ui/doom-modeline: minor refactor

This commit is contained in:
Henrik Lissner 2018-01-31 05:03:28 -05:00
parent 6b453962d7
commit d01deb5545
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -42,6 +42,10 @@
(add-hook 'doom-escape-hook #'anzu--reset-status t) (add-hook 'doom-escape-hook #'anzu--reset-status t)
(add-hook 'iedit-mode-end-hook #'anzu--reset-status)) (add-hook 'iedit-mode-end-hook #'anzu--reset-status))
;; fish-style modeline
(def-package! shrink-path
:commands (shrink-path-prompt shrink-path-file-mixed))
;; Keep `+doom-modeline-current-window' up-to-date ;; Keep `+doom-modeline-current-window' up-to-date
(defvar +doom-modeline-current-window (frame-selected-window)) (defvar +doom-modeline-current-window (frame-selected-window))
@ -56,10 +60,6 @@
(advice-add #'handle-switch-frame :after #'+doom-modeline|set-selected-window) (advice-add #'handle-switch-frame :after #'+doom-modeline|set-selected-window)
(advice-add #'select-window :after #'+doom-modeline|set-selected-window) (advice-add #'select-window :after #'+doom-modeline|set-selected-window)
;; fish-style modeline
(def-package! shrink-path
:commands (shrink-path-prompt shrink-path-file-mixed))
;; ;;
;; Variables ;; Variables
@ -288,7 +288,7 @@ Example:
;; ;;
;; Segments ;; buffer information
;; ;;
(def-modeline-segment! buffer-default-directory (def-modeline-segment! buffer-default-directory
@ -304,7 +304,6 @@ buffer where knowing the current project directory is important."
(propertize (concat " " (abbreviate-file-name default-directory)) (propertize (concat " " (abbreviate-file-name default-directory))
'face face)))) 'face face))))
;;
(def-modeline-segment! buffer-info (def-modeline-segment! buffer-info
"Combined information about the current buffer, including the current working "Combined information about the current buffer, including the current working
directory, the file name, and its state (modified, read-only or non-existent)." directory, the file name, and its state (modified, read-only or non-existent)."
@ -337,7 +336,6 @@ directory, the file name, and its state (modified, read-only or non-existent)."
(+doom-modeline-buffer-file-name) (+doom-modeline-buffer-file-name)
"%b"))) "%b")))
;;
(def-modeline-segment! buffer-info-simple (def-modeline-segment! buffer-info-simple
"Display only the current buffer's name, but with fontification." "Display only the current buffer's name, but with fontification."
(propertize (propertize
@ -346,7 +344,6 @@ directory, the file name, and its state (modified, read-only or non-existent)."
'doom-modeline-buffer-modified) 'doom-modeline-buffer-modified)
((active) 'doom-modeline-buffer-file)))) ((active) 'doom-modeline-buffer-file))))
;;
(def-modeline-segment! buffer-encoding (def-modeline-segment! buffer-encoding
"Displays the encoding and eol style of the buffer the same way Atom does." "Displays the encoding and eol style of the buffer the same way Atom does."
(concat (pcase (coding-system-eol-type buffer-file-coding-system) (concat (pcase (coding-system-eol-type buffer-file-coding-system)
@ -359,7 +356,11 @@ directory, the file name, and its state (modified, read-only or non-existent)."
(t (upcase (symbol-name (plist-get sys :name)))))) (t (upcase (symbol-name (plist-get sys :name))))))
" ")) " "))
;; ;;
;; major-mode
;;
(def-modeline-segment! major-mode (def-modeline-segment! major-mode
"The major mode, including process, environment and text-scale info." "The major mode, including process, environment and text-scale info."
(propertize (propertize
@ -371,7 +372,11 @@ directory, the file name, and its state (modified, read-only or non-existent)."
(format " (%+d)" text-scale-mode-amount))) (format " (%+d)" text-scale-mode-amount)))
'face (if (active) 'doom-modeline-buffer-major-mode))) 'face (if (active) 'doom-modeline-buffer-major-mode)))
;; ;;
;; vcs
;;
(def-modeline-segment! vcs (def-modeline-segment! vcs
"Displays the current branch, colored based on its state." "Displays the current branch, colored based on its state."
(when (and vc-mode buffer-file-name) (when (and vc-mode buffer-file-name)
@ -407,7 +412,11 @@ directory, the file name, and its state (modified, read-only or non-existent)."
'face (if active face)) 'face (if active face))
" "))))) " ")))))
;; ;;
;; flycheck
;;
(defun +doom-ml-icon (icon &optional text face voffset) (defun +doom-ml-icon (icon &optional text face voffset)
"Displays an octicon ICON with FACE, followed by TEXT. Uses "Displays an octicon ICON with FACE, followed by TEXT. Uses
`all-the-icons-octicon' to fetch the icon." `all-the-icons-octicon' to fetch the icon."
@ -416,8 +425,7 @@ directory, the file name, and its state (modified, read-only or non-existent)."
(concat (concat
(all-the-icons-material icon :face face :height 1.1 :v-adjust (or voffset -0.2)) (all-the-icons-material icon :face face :height 1.1 :v-adjust (or voffset -0.2))
(if text +doom-modeline-vspc))) (if text +doom-modeline-vspc)))
(when text (if text (propertize text 'face face))
(propertize text 'face face))
(if vc-mode " " " "))) (if vc-mode " " " ")))
(defvar-local +doom-modeline--flycheck nil) (defvar-local +doom-modeline--flycheck nil)
@ -443,7 +451,11 @@ directory, the file name, and its state (modified, read-only or non-existent)."
icons." icons."
+doom-modeline--flycheck) +doom-modeline--flycheck)
;; ;;
;; selection-info
;;
(defsubst doom-column (pos) (defsubst doom-column (pos)
(save-excursion (goto-char pos) (save-excursion (goto-char pos)
(current-column))) (current-column)))
@ -480,6 +492,9 @@ lines are selected, or the NxM dimensions of a block selection."
;; ;;
;; matches (anzu, evil-substitute, iedit, macro)
;;
(defun +doom-modeline--macro-recording () (defun +doom-modeline--macro-recording ()
"Display current Emacs or evil macro being recorded." "Display current Emacs or evil macro being recorded."
(when (and (active) (or defining-kbd-macro executing-kbd-macro)) (when (and (active) (or defining-kbd-macro executing-kbd-macro))
@ -561,14 +576,24 @@ with `evil-ex-substitute', and/or 4. The number of active `iedit' regions."
(or (and (not (equal meta "")) meta) (or (and (not (equal meta "")) meta)
(if buffer-file-name " %I ")))) (if buffer-file-name " %I "))))
;; TODO Include other information
;;
;; media-info
;;
(def-modeline-segment! media-info (def-modeline-segment! media-info
"Metadata regarding the current file, such as dimensions for images." "Metadata regarding the current file, such as dimensions for images."
;; TODO Include other information
(cond ((eq major-mode 'image-mode) (cond ((eq major-mode 'image-mode)
(cl-destructuring-bind (width . height) (cl-destructuring-bind (width . height)
(image-size (image-get-display-property) :pixels) (image-size (image-get-display-property) :pixels)
(format " %dx%d " width height))))) (format " %dx%d " width height)))))
;;
;; bar
;;
(defvar +doom-modeline--bar-active nil) (defvar +doom-modeline--bar-active nil)
(defvar +doom-modeline--bar-inactive nil) (defvar +doom-modeline--bar-inactive nil)
(def-modeline-segment! bar (def-modeline-segment! bar
@ -612,7 +637,7 @@ Returns \"\" to not break --no-window-system."
(defun +doom-modeline|init () (defun +doom-modeline|init ()
;; Create bars ;; Create bars
(setq +doom-modeline--bar-active (+doom-modeline--make-xpm 'doom-modeline-bar) (setq +doom-modeline--bar-active (+doom-modeline--make-xpm 'doom-modeline-bar)
+doom-modeline--bar-inactive (+doom-modeline--make-xpm 'doom-modeline-inactive-bar)) +doom-modeline--bar-inactive (+doom-modeline--make-xpm 'doom-modeline-inactive-bar))
;; These buffers are already created and don't get modelines. For the love of ;; These buffers are already created and don't get modelines. For the love of
@ -641,5 +666,5 @@ Returns \"\" to not break --no-window-system."
(add-hook 'doom-scratch-buffer-hook #'+doom-modeline|set-special-modeline) (add-hook 'doom-scratch-buffer-hook #'+doom-modeline|set-special-modeline)
(add-hook '+doom-dashboard-mode-hook #'+doom-modeline|set-project-modeline) (add-hook '+doom-dashboard-mode-hook #'+doom-modeline|set-project-modeline)
(add-hook 'image-mode-hook #'+doom-modeline|set-media-modeline) (add-hook 'image-mode-hook #'+doom-modeline|set-media-modeline)
(add-hook 'circe-mode-hook #'+doom-modeline|set-special-modeline) (add-hook 'circe-mode-hook #'+doom-modeline|set-special-modeline)