Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
amitp's modeline summer 2019
;; You'll need to have the s and powerline packages installed for this modeline to work
(require 's)
(require 'powerline)
(defvar my/mode-line-border 8)
(defvar my/modeline-height 22)
(set-face-attribute 'mode-line nil :family "M+ 1m" :height 120
:background "gray20" :foreground "white"
:weight 'normal
:box `(:line-width ,my/mode-line-border :color "gray20" :style nil))
(set-face-attribute 'mode-line-inactive nil :inherit 'mode-line
:background "gray20" :foreground "gray50"
:box `(:line-width ,my/mode-line-border :color "gray20" :style nil))
;; remove things I don't use
(setq-default mode-line-front-space '(:eval (format-time-string "W%y%V")))
(setq-default mode-line-mule-info "")
(setq-default mode-line-remote "")
(setq-default mode-line-frame-identification "")
(setq-default mode-line-position "") ;; I use line-number-mode instead
(setq-default mode-line-modes '("%[" mode-name mode-line-process "%n" "%]"))
(setq-default mode-line-end-spaces "")
;; show the buffer status with brighter colors
(make-face 'mode-line-read-only-face)
(set-face-attribute 'mode-line-read-only-face nil :inherit 'mode-line
:foreground "#b3d5e6"
:box '(:line-width -5 :color "#3f95bf"))
(make-face 'mode-line-modified-face)
(set-face-attribute 'mode-line-modified-face nil :inherit 'mode-line
:foreground "#c82829" :background "GoldenRod2"
:box '(:line-width -5 :color "#c82829"))
(setq-default mode-line-modified
(cond (buffer-read-only
(propertize " RO " 'face 'mode-line-read-only-face))
(propertize " ** " 'face 'mode-line-modified-face))
(t " "))))
;; show both directory and buffer name
(set-face-attribute 'mode-line-buffer-id nil :inherit 'mode-line :foreground "green")
(make-face 'mode-line-folder-face)
(set-face-attribute 'mode-line-folder-face nil :inherit 'mode-line
:family "Fira Sans Condensed" :height 150)
(make-face 'mode-line-filename-face)
(set-face-attribute 'mode-line-filename-face nil :inherit 'mode-line
:family "Fira Sans Condensed" :height 150
:foreground "white" :background "#3f95bf")
(defun my/modeline-project-root ()
"Ask project.el for the directory for the current project"
(or (cdr (project-current)) default-directory))
(defun my/modeline-buffer-id ()
(cond (buffer-file-name
(s-chop-prefix (my/modeline-project-root) buffer-file-name))
(t "%b")))
(defun my/shorten-directory (dir max-length)
"Show directory name DIR with 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)))
(setq-default mode-line-buffer-identification
(- (window-width) (length (my/modeline-buffer-id)) 60)))
face mode-line-folder-face)
(:propertize " "
face mode-line-filename-face
display ,(powerline-wave-right 'mode-line-folder-face nil my/modeline-height))
(:eval (my/modeline-buffer-id))
face mode-line-filename-face)
(:propertize " "
face mode-line-filename-face
display ,(powerline-wave-left nil 'mode-line-folder-face my/modeline-height))
(provide 'my-modeline)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment