fnwiya's quine

自分自身を出力するブログ

Emacsのフラットデザインっぽくする(FlatUI)

Emacsのテーマは今までsolarizedを使ってきましたが、

定番すぎたのでもうちょい自分らしく変えようと思い、

フラットデザインをとりいててみました。

f:id:fnwiya:20150823162104p:plain

テーマ

john2x/flatui-theme.el · GitHub

M-x list-packegesでは入ります。

以下をinit.elに記述(自分はファイル分割してます)

;;;カラースキーム
(color-theme-initialize)
(load-theme 'flatui t)

モードライン

気分屋なのでたまにテーマを変更します。

その際いちいち設定しなおすのが面倒なので

face-attributeを使ってテーマと連動する形で変わるようになってます。

↓をベースに、なるべく編集状況によってずれが生じないようにしてます。

Amit's Thoughts: Emacs: custom mode line

その他マイナーモードで表示しないものを簡単に指定できるようにしてます。

f:id:fnwiya:20150823163851p:plain

;; power-line
(require 'powerline)

;; Mode line setup
(setq-default
 mode-line-format
 '(; Position
   ; 総行数
   (:eval (format "%04d" (count-lines (point-max) (point-min))))
   ; 現在の行数,列数(4桁・3桁で固定)
   (:propertize "(%04l" face mode-line-position-face)
   ":"
   (:propertize "%03c)"  face mode-line-position-face)
                                        ; emacsclient [default -- keep?]
   mode-line-client
   "  "
                                        ; read-only or modified status
   (:eval
    (cond (buffer-read-only
           (propertize " RO " 'face 'mode-line-read-only-face))
          ((buffer-modified-p)
           (propertize " ** " 'face 'mode-line-modified-face))
          (t" -- ")))
   "  "
                                        ; directory and buffer/file name
   (:propertize (:eval (shorten-directory default-directory 30))
                face mode-line-folder-face)
   (:propertize "%b"
                face mode-line-filename-face)
                                        ; narrow [default -- keep?]
   "%n"
                                        ; mode indicators: vc, recursive edit, major mode, minor modes, process, global
   (vc-mode vc-mode)
   " %["
   (:propertize mode-name
                face mode-line-mode-face)
   "%] "
   (:eval (propertize (format-mode-line minor-mode-alist)
                      'face 'mode-line-minor-mode-face))
   (:propertize mode-line-process
                face mode-line-process-face)
   (global-mode-string global-mode-string)
   "  "
                                        ; nyan-mode uses nyan cat as an alternative to %p
   (:eval (when nyan-mode (list (nyan-create))))
   ))

;; Helper function
(defun shorten-directory (dir max-length)
  "Show up to `max-length' characters of a directory name `dir'."
  (let ((path (reverse (split-string (abbreviate-file-name dir) "/")))
        (output ""))
    (when (and path (equal "" (car path)))
      (setq path (cdr path)))
    (while (and path (< (length output) (- max-length 4)))
      (setq output (concat (car path) "/" output))
      (setq path (cdr path)))
    (when path
      (setq output (concat ".../" output)))
    output))

;; Extra mode line faces
(make-face 'mode-line-read-only-face)
(make-face 'mode-line-modified-face)
(make-face 'mode-line-folder-face)
(make-face 'mode-line-filename-face)
(make-face 'mode-line-position-face)
(make-face 'mode-line-mode-face)
(make-face 'mode-line-minor-mode-face)
(make-face 'mode-line-process-face)


;;色の設定
(set-face-attribute 'mode-line nil
  :foreground (face-attribute 'default :background)
  :background (face-attribute 'default :foreground)
  :inverse-video nil
  :height 125
  :box nil)
(set-face-attribute 'mode-line-inactive nil
  :foreground (face-attribute 'default :background)
  :background (face-attribute 'default :foreground)
  :inverse-video nil
  :box nil)
(set-face-attribute 'mode-line-read-only-face nil
  :inherit 'mode-line-face
  :foreground (face-attribute 'link :foreground)
  :background (face-attribute 'mode-line :background)
  :weight 'bold
  :box nil)
(set-face-attribute 'mode-line-modified-face nil
  :inherit 'mode-line-face
  :foreground (face-attribute 'warning :foreground)
  :background (face-attribute 'mode-line :background)
  :weight 'bold
  :box nil)
(set-face-attribute 'mode-line-folder-face nil
  :inherit 'mode-line-face
  :foreground (face-attribute 'default :background))
(set-face-attribute 'mode-line-filename-face nil
  :inherit 'mode-line-face
  :foreground "#c0392b"
  :weight 'bold)
(set-face-attribute 'mode-line-position-face nil
  :inherit 'mode-line-face
  :family "Menlo" :height 100)
(set-face-attribute 'mode-line-mode-face nil
  :inherit 'mode-line-face
  :foreground (face-attribute 'default :background))
(set-face-attribute 'mode-line-minor-mode-face nil
  :inherit 'mode-line-mode-face
  :foreground (face-attribute 'default :background)
  :height 110)
(set-face-attribute 'mode-line-process-face nil
  :inherit 'mode-line-face
  :foreground (face-attribute 'default :background))


;;http://www.bookshelf.jp/soft/meadow_16.html
(add-hook 'lisp-interaction-mode-hook
          '(lambda ()
             (setq mode-name "Lisp-Int")))
(add-hook 'emacs-lisp-mode-hook
          '(lambda ()
             (setq mode-name "Elisp")))

;マイナーモードで表示しないものを指定
(setq my/hidden-minor-modes
      '(undo-tree-mode
        auto-complete-mode
        helm-mode
        volatile-highlights-mode
        smartparens-mode))

(mapc (lambda (mode)
        (setq minor-mode-alist
              (cons (list mode "") (assq-delete-all mode minor-mode-alist))))
      my/hidden-minor-modes)

タブ

自分はタブが欲しい派なのでtabbar.elを使っています。

こちらはモードラインの色(つまりさらにたどってテーマの色)と連動します。

ポイントはinitの際、モードラインより後に読み込みするようにすることです。

(同様にモードラインはテーマより後に読み込みます)

(require 'tabbar)
(tabbar-mode 1)
;; タブ上でマウスホイール操作無効
(tabbar-mwheel-mode -1)
;; グループ化しない
(setq tabbar-buffer-groups-function nil)
;; 画像を使わないことで軽量化する
(setq tabbar-use-images nil)
;; 左に表示されるボタンを無効化
(dolist (btn '(tabbar-buffer-home-button
               tabbar-scroll-left-button
               tabbar-scroll-right-button))
  (set btn (cons (cons "" nil)
                 (cons "" nil))))
;; タブに表示させるバッファの設定
(defvar my-tabbar-displayed-buffers
  '("*scratch*" "*Messages*" "*Backtrace*" "*Colors*" "*Faces*" "*vc-")
  "*Regexps matches buffer names always included tabs.")
(defun my-tabbar-buffer-list ()
  "Return the list of buffers to show in tabs.
Exclude buffers whose name starts with a space or an asterisk.
The current buffer and buffers matches `my-tabbar-displayed-buffers'
are always included."
  (let* ((hides (list ?\  ?\*))
         (re (regexp-opt my-tabbar-displayed-buffers))
         (cur-buf (current-buffer))
         (tabs (delq nil
                     (mapcar (lambda (buf)
                               (let ((name (buffer-name buf)))
                                 (when (or (string-match re name)
                                           (not (memq (aref name 0) hides)))
                                   buf)))
                             (buffer-list)))))
    ;; Always include the current buffer.
    (if (memq cur-buf tabs)
        tabs
      (cons cur-buf tabs))))
(setq tabbar-buffer-list-function 'my-tabbar-buffer-list)

;; 見た目(mode-lineに合わせる)
(setq tabbar-separator '(1.0))
(set-face-attribute 'tabbar-default nil
  :family (face-attribute 'mode-line-position-face :family)
  :background (face-attribute 'mode-line-inactive :background)
  :foreground (face-attribute 'mode-line-inactive :foreground)
  :height (face-attribute 'mode-line-minor-mode-face :height)
  :box nil)
(set-face-attribute 'tabbar-unselected nil
  :background (face-attribute 'mode-line-inactive :background)
  :foreground (face-attribute 'mode-line-inactive :foreground)
  :box nil)
(set-face-attribute 'tabbar-selected nil
  :background (face-attribute 'mode-line-filename-face :foreground)
  :foreground (face-attribute 'mode-line :foreground)
  :box nil)
(set-face-attribute 'tabbar-modified nil
  :background (face-attribute 'mode-line-modified-face :foreground)
  :foreground (face-attribute 'mode-line :foreground)
  :box nil)
(set-face-attribute 'tabbar-separator nil
  :background (face-attribute 'mode-line-inactive :background)
  :foreground (face-attribute 'mode-line-inactive :background)
  :height 1.0)

;; key bindings
(global-set-key [(C-tab)]   'tabbar-forward-tab)
(global-set-key [(C-S-tab)] 'tabbar-backward-tab)
(global-set-key "\M-}"      'tabbar-forward-tab)
(global-set-key "\M-{"      'tabbar-backward-tab)

うん、結構気に入ってます。

しかしやっぱり暗い背景がすきなので現在のテーマをベースに自作テーマ作成中です←

その他の設定は

fnwiya (fnwiya) · GitHub

をご確認ください。

それでは自分らしいEmacsライフを