Skip to content

Instantly share code, notes, and snippets.

@pkkm
Created March 28, 2013 16:53
Show Gist options
  • Save pkkm/5264886 to your computer and use it in GitHub Desktop.
Save pkkm/5264886 to your computer and use it in GitHub Desktop.
My modeline config.
; Modeline with left, center and right aligned parts (using powerline).
(package-ensure-installed 'powerline)
(setq-default mode-line-format
'((:eval
(let*
;;; Modeline sections.
((my-dir-and-name
(concat
(if buffer-file-name ; If the buffer is visiting a file...
(propertize (shorten-directory default-directory 20)
'face 'my-mode-line-directory)
"")
(propertize "%b"
'face 'my-mode-line-filename)))
(my-modified-ro
(cond (buffer-read-only
(propertize "RO"
'face 'my-mode-line-read-only))
((buffer-modified-p)
(propertize "+"
'face 'my-mode-line-modified))
(t
"")))
(my-is-narrowed
(if (not (string= (format-mode-line "%n") ""))
(propertize "Narrow"
'face 'my-mode-line-narrowed)
""))
(my-recursive-edit-open-braces
(propertize "%["
'face 'my-mode-line-recursive-edit-braces))
(my-recursive-edit-close-braces
(propertize "%]"
'face 'my-mode-line-recursive-edit-braces))
(my-major-mode
(propertize mode-name
'face 'my-mode-line-major-mode))
(my-minor-modes
(if (not (string= (format-mode-line minor-mode-alist) ""))
(propertize
(concat
"("
(substring (format-mode-line minor-mode-alist) 1)
")")
'face 'my-mode-line-minor-modes)
""))
(my-process
(propertize (format-mode-line mode-line-process)
'face 'my-mode-line-process))
(my-global-mode-string
(propertize (format-mode-line global-mode-string)
'face 'my-mode-line-global-mode-string))
(my-coding
(propertize (symbol-name buffer-file-coding-system)
'face 'my-mode-line-coding))
(my-position
(propertize "%p"
'face 'my-mode-line-position))
(my-line-column
(concat
(propertize "%l" 'face 'my-mode-line-line)
(propertize ":%c" 'face 'my-mode-line-column)))
;;; Left, center and right parts of the modeline.
(left (list
" " ; Spacing from the window edge.
(mapconcat
'identity
(delq ""
(list my-dir-and-name
my-modified-ro
my-is-narrowed))
" ")))
(center (list
(mapconcat
'identity
(delq ""
(list my-recursive-edit-open-braces
my-major-mode
my-minor-modes
my-process
my-global-mode-string
my-recursive-edit-close-braces))
" ")))
(right (list
(mapconcat
'identity
(delq ""
(list my-coding
my-position
my-line-column))
" ")
" "))) ; Spacing from the window edge.
;;; Rendering the modeline.
(concat
(powerline-render left)
(powerline-fill-center nil (/ (powerline-width center) 2.0))
(powerline-render center)
(powerline-fill nil (powerline-width right))
(powerline-render right))))))
(defface my-mode-line-directory '((t (:inherit 'mode-line-inactive)))
"Face for the folder name in the modeline."
:group 'modeline)
(defface my-mode-line-filename '((t ()))
"Face for the file name in the modeline."
:group 'modeline)
(defface my-mode-line-modified '((t (:inherit 'warning)))
"Face for the indicator of file being modified in the modeline."
:group 'modeline)
(defface my-mode-line-read-only '((t (:weight bold)))
"Face for the indicator of file being read only in the modeline."
:group 'modeline)
(defface my-mode-line-narrowed '((t (:box t)))
"Face for the indicator of buffer being narrowed in the modeline."
:group 'modeline)
(defface my-mode-line-recursive-edit-braces '((t (:inherit 'mode-line-inactive)))
"Face for the recursive edit braces in the modeline."
:group 'modeline)
(defface my-mode-line-major-mode '((t (:weight bold)))
"Face for the major mode in the modeline."
:group 'modeline)
(defface my-mode-line-minor-modes '((t ()))
"Face for minor modes in the modeline."
:group 'modeline)
(defface my-mode-line-process '((t ()))
"Face for the process status in the modeline."
:group 'modeline)
(defface my-mode-line-global-mode-string '((t ()))
"Face for the global mode string (see help for global-mode-string) in the modeline."
:group 'modeline)
(defface my-mode-line-coding '((t ()))
"Face for the coding system name in the modeline."
:group 'modeline)
(defface my-mode-line-position '((t (:inherit 'mode-line-inactive)))
"Face for the buffer position in the modeline."
:group 'modeline)
(defface my-mode-line-line '((t ()))
"Face for the current line in the modeline."
:group 'modeline)
(defface my-mode-line-column '((t (:inherit 'mode-line-inactive)))
"Face for the current column in the modeline."
:group 'modeline)
(defun shorten-directory (dir max-length)
"Shorten directory name DIR to up to MAX-LENGTH characters."
(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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment