Emacs のモードラインを Powerline 風にカスタマイズ

Emacs のモードラインを Vim の powerline のようにカスタマイズする設定が各所で紹介されている。Emacs のこうした細かい設定の妙は、このエディタに興味がない人にはまったく理解されないだろうが、こうした設定に凝ってしまう人は共通してある種病的に楽しんでいるのだと思う。もちろん私も含めて。

EmacsWiki: Power Line や紹介記事のコードをもとに試してみた。

;; Powerline
(defun arrow-right-xpm (color1 color2)
  "Return an XPM right arrow string representing."
  (format "/* XPM */
static char * arrow_right[] = {
"12 18 2 1",
". c %s",
"  c %s",
".           ",
"..          ",
"...         ",
"....        ",
".....       ",
"......      ",
".......     ",
"........    ",
".........   ",
".........   ",
"........    ",
".......     ",
"......      ",
".....       ",
"....        ",
"...         ",
"..          ",
".           "};"  color1 color2))

(defun arrow-left-xpm (color1 color2)
  "Return an XPM right arrow string representing."
  (format "/* XPM */
static char * arrow_right[] = {
"12 18 2 1",
". c %s",
"  c %s",
"           .",
"          ..",
"         ...",
"        ....",
"       .....",
"      ......",
"     .......",
"    ........",
"   .........",
"   .........",
"    ........",
"     .......",
"      ......",
"       .....",
"        ....",
"         ...",
"          ..",
"           ."};"  color2 color1))

(defconst color1 "#666666") ; gray40
(defconst color2 "#999999") ; gray60

(defvar arrow-right-0 (create-image (arrow-right-xpm "None" color1) 'xpm t :ascent 'center))
(defvar arrow-right-1 (create-image (arrow-right-xpm color1 color2) 'xpm t :ascent 'center))
(defvar arrow-right-2 (create-image (arrow-right-xpm color2 "None") 'xpm t :ascent 'center))
(defvar arrow-left-1  (create-image (arrow-left-xpm color2 color1) 'xpm t :ascent 'center))
(defvar arrow-left-2  (create-image (arrow-left-xpm "None" color2) 'xpm t :ascent 'center))

(display-time)

(setq-default mode-line-format
              (list
               '("-"
                 mode-line-mule-info
                 mode-line-modified
                 minor-mode-alist)
               '(:eval (concat (propertize " " 'display arrow-right-0)))
               '(:eval (concat (propertize " %m " 'face 'mode-line-color-1)
                               (propertize " " 'display arrow-right-1)))
               '(:eval (concat (propertize " %b " 'face 'mode-line-color-2)
                               (propertize " " 'display arrow-right-2)))
               ;; Justify right by filling with spaces to right fringe - 16
               ;; (16 should be computed rahter than hardcoded)
               '(:eval (propertize " " 'display '((space :align-to (- right-fringe 17)))))
               '(:eval (concat (propertize " " 'display arrow-left-2)
                               (propertize " %p " 'face 'mode-line-color-2)))
               '(:eval (concat (propertize " " 'display arrow-left-1)
                               (propertize "%4l:%2c  " 'face 'mode-line-color-1)))
                 ))


(make-face 'mode-line-color-1)
(set-face-attribute 'mode-line-color-1 nil
                    :foreground "#fffacd"
                    :bold t
                    :background color1)

(make-face 'mode-line-color-2)
(set-face-attribute 'mode-line-color-2 nil
                    :foreground "#fffacd"
                    :bold t
                    :background color2)

(set-face-attribute 'mode-line nil
                    :foreground "#fffacd"
                    :background "#171717"
                    :box nil)
(set-face-attribute 'mode-line-inactive nil
                    :foreground "#fffacd"
                    :background "#171717")

Emacs の mode-line に関するレファレンスは、

あたりを参照した。

表示は次のようになる。

https://skalldan.files.wordpress.com/2012/05/wpid-powerline_emacs.png

色の設定で印象が随分変わる。いろいろ遊んでみると楽しい。設定色は M-x list-colors-display で確認できる。

(defconst color1 "#4682b4")
(defconst color2 "#ff6347")

https://skalldan.files.wordpress.com/2012/05/wpid-emacs_color_powerline_01.png

(defconst color1 "#6b8e23")
(defconst color2 "#eedd82")

(set-face-attribute 'mode-line-color-2 nil
                    :foreground "#171717"
                    :bold t
                    :background color2)

https://skalldan.files.wordpress.com/2012/05/wpid-emacs_color_powerline_02.png

さすがにこれはやりすぎすですが…

(defconst color1 "#00cd00")
(defconst color2 "#1e90ff")
(defconst color3 "#ff3030")

;; (中略)

(set-face-attribute 'mode-line nil
                    :foreground "#171717"
                    :background "#ffb90f"
                    :bold t
                    :box nil)

https://skalldan.files.wordpress.com/2012/05/wpid-emacs_color_powerline_03.png

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s