Dirk-Jan C. Binnema’s mode-line blog post inspired me to post about my own Emacs mode line configuration. I found the default mode line to be too busy for my tastes. I removed most of it and added to the features I care about most. Here’s what it currently looks like:
I use a proportional font for most of the mode line, along with extra padding to make the mode line taller than other lines. From left to right:
Line and column position. I use a monospace font for this portion because it’s changing all the time, and I don’t want the rest of the mode line to move around.
I also highlight the column number if I go over 80 columns, using code similar to modeline-posn.el:
Buffer status. If the buffer is modified, I use a bright white and red block:
If it’s read-only, I use a blue indicator:
Directory and buffer name. I found that the current directory matters to me so I decided to put it into the mode line, in addition to alternatives like Uniquify. Some directory names are too long so I only show the trailing portion.
Mode indicators. I want to see the major mode. I’m less sure about the rest: VC mode (not all VC packages use this), narrowing (I almost never use this), recursive edit (I should use this but I don’t), minor modes (I almost never look at this part of the mode-line), process status.
And what would a mode line be without Nyan mode? It only turns on if I use
I removed things I don’t care about: character encoding, mule, end of line conversion, tooltips, menus, file size, overwrite mode, frame information, portion of buffer being displayed, and the dashes.
Duncan MacGregor suggests splitting up the mode line into smaller pieces. However, I haven’t done that yet. Instead, I expanded everything into one big list.
;; Mode line setup (setq-default mode-line-format '(; Position, including warning for 80 columns (:propertize "%4l:" face mode-line-position-face) (:eval (propertize "%3c" 'face (if (>= (current-column) 80) 'mode-line-80col-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) (make-face 'mode-line-80col-face) (set-face-attribute 'mode-line nil :foreground "gray60" :background "gray20" :inverse-video nil :box '(:line-width 6 :color "gray20" :style nil)) (set-face-attribute 'mode-line-inactive nil :foreground "gray80" :background "gray40" :inverse-video nil :box '(:line-width 6 :color "gray40" :style nil)) (set-face-attribute 'mode-line-read-only-face nil :inherit 'mode-line-face :foreground "#4271ae" :box '(:line-width 2 :color "#4271ae")) (set-face-attribute 'mode-line-modified-face nil :inherit 'mode-line-face :foreground "#c82829" :background "#ffffff" :box '(:line-width 2 :color "#c82829")) (set-face-attribute 'mode-line-folder-face nil :inherit 'mode-line-face :foreground "gray60") (set-face-attribute 'mode-line-filename-face nil :inherit 'mode-line-face :foreground "#eab700" :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 "gray80") (set-face-attribute 'mode-line-minor-mode-face nil :inherit 'mode-line-mode-face :foreground "gray40" :height 110) (set-face-attribute 'mode-line-process-face nil :inherit 'mode-line-face :foreground "#718c00") (set-face-attribute 'mode-line-80col-face nil :inherit 'mode-line-position-face :foreground "black" :background "#eab700")
Update: [2016-12-22] If I were doing this again, I'd probably start with the spaceline package.
Update: [2017-01-08] I did switch to spaceline.