mirror of
https://github.com/correl/doom-modeline.git
synced 2024-11-23 19:19:50 +00:00
Refactor.
This commit is contained in:
parent
63c5cde9a3
commit
d3a2928efa
1 changed files with 91 additions and 95 deletions
|
@ -90,16 +90,16 @@
|
|||
else
|
||||
collect (list (intern (format "doom-modeline-segment--%s" (symbol-name seg))))))
|
||||
|
||||
(defmacro doom-modeline-def (name lhs &optional rhs)
|
||||
(defmacro doom-modeline-def-modeline (name lhs &optional rhs)
|
||||
"Define a modeline format and byte-compiles it.
|
||||
NAME is a symbol to identify it (used by `doom-modeline' for retrieval).
|
||||
LHS and RHS are lists of symbols of modeline segments defined
|
||||
with `doom-modeline-def-segment'.
|
||||
Example:
|
||||
(doom-modeline-def minimal
|
||||
(doom-modeline-def-modeline minimal
|
||||
(bar matches \" \" buffer-info)
|
||||
(media-info major-mode))
|
||||
(doom-modeline-set 'minimal t)"
|
||||
(doom-modeline-set-modeline 'minimal t)"
|
||||
(let ((sym (intern (format "doom-modeline-format--%s" name)))
|
||||
(lhs-forms (doom-modeline--prepare-segments lhs))
|
||||
(rhs-forms (doom-modeline--prepare-segments rhs)))
|
||||
|
@ -125,7 +125,7 @@ Throws an error if it doesn't exist."
|
|||
(when (functionp fn)
|
||||
`(:eval (,fn)))))
|
||||
|
||||
(defun doom-modeline-set (key &optional default)
|
||||
(defun doom-modeline-set-modeline (key &optional default)
|
||||
"Set the modeline format. Does nothing if the modeline KEY doesn't exist.
|
||||
If DEFAULT is non-nil, set the default mode-line for all buffers."
|
||||
(-when-let* ((modeline (doom-modeline key)))
|
||||
|
@ -313,24 +313,6 @@ active."
|
|||
(advice-add #'select-window :after #'doom-modeline-set-selected-window)
|
||||
|
||||
|
||||
;;
|
||||
;; Bootstrap
|
||||
;;
|
||||
|
||||
;; Show version string for multi-version managers like rvm, rbenv, pyenv, etc.
|
||||
(defvar-local doom-modeline-env-version nil)
|
||||
(defvar-local doom-modeline-env-command nil)
|
||||
(add-hook 'focus-in-hook #'doom-modeline-update-env)
|
||||
(add-hook 'find-file-hook #'doom-modeline-update-env)
|
||||
(defun doom-modeline-update-env ()
|
||||
"Update environment for mode-line."
|
||||
(when doom-modeline-env-command
|
||||
(let* ((default-directory (doom-modeline-project-root))
|
||||
(s (shell-command-to-string doom-modeline-env-command)))
|
||||
(setq doom-modeline-env-version (if (string-match "[ \t\n\r]+\\'" s)
|
||||
(replace-match "" t t s)
|
||||
s)))))
|
||||
|
||||
;; Only support python and ruby for now
|
||||
|
||||
;; TODO torgeir
|
||||
|
@ -834,23 +816,23 @@ enabled."
|
|||
;; Mode lines
|
||||
;;
|
||||
|
||||
(doom-modeline-def main
|
||||
(doom-modeline-def-modeline main
|
||||
(workspace-number bar matches " " buffer-info " %l:%c %p " selection-info)
|
||||
(buffer-encoding major-mode vcs flycheck))
|
||||
|
||||
(doom-modeline-def minimal
|
||||
(doom-modeline-def-modeline minimal
|
||||
(bar matches " " buffer-info)
|
||||
(media-info major-mode))
|
||||
|
||||
(doom-modeline-def special
|
||||
(doom-modeline-def-modeline special
|
||||
(bar matches " " buffer-info-simple " %l:%c %p " selection-info)
|
||||
(buffer-encoding major-mode flycheck))
|
||||
|
||||
(doom-modeline-def project
|
||||
(doom-modeline-def-modeline project
|
||||
(bar buffer-default-directory)
|
||||
(major-mode))
|
||||
|
||||
(doom-modeline-def media
|
||||
(doom-modeline-def-modeline media
|
||||
(bar " %b ")
|
||||
(media-info major-mode))
|
||||
|
||||
|
@ -861,27 +843,41 @@ enabled."
|
|||
;;;###autoload
|
||||
(defun doom-modeline-init ()
|
||||
"Set the default modeline."
|
||||
(doom-modeline-set 'main t)
|
||||
(doom-modeline-set-modeline 'main t)
|
||||
|
||||
;; This scratch and messages buffer is already created and doesn't get a
|
||||
;; modeline.
|
||||
(with-current-buffer "*Messages*"
|
||||
(doom-modeline-set 'main))
|
||||
(doom-modeline-set-modeline 'main))
|
||||
(with-current-buffer "*scratch*"
|
||||
(doom-modeline-set 'main)))
|
||||
(doom-modeline-set-modeline 'main)))
|
||||
|
||||
(defun doom-modeline-set-special-modeline ()
|
||||
"Set the special modeline."
|
||||
(doom-modeline-set 'special))
|
||||
(doom-modeline-set-modeline 'special))
|
||||
|
||||
(defun doom-modeline-set-media-modeline ()
|
||||
"Set the media modeline."
|
||||
(doom-modeline-set 'media))
|
||||
(doom-modeline-set-modeline 'media))
|
||||
|
||||
(add-hook 'image-mode-hook #'doom-modeline-set-media-modeline)
|
||||
(add-hook 'org-src-mode-hook #'doom-modeline-set-special-modeline)
|
||||
(add-hook 'circe-mode-hook #'doom-modeline-set-special-modeline)
|
||||
|
||||
;; Show version string for multi-version managers like rvm, rbenv, pyenv, etc.
|
||||
(defvar-local doom-modeline-env-version nil)
|
||||
(defvar-local doom-modeline-env-command nil)
|
||||
(add-hook 'focus-in-hook #'doom-modeline-update-env)
|
||||
(add-hook 'find-file-hook #'doom-modeline-update-env)
|
||||
(defun doom-modeline-update-env ()
|
||||
"Update environment for mode-line."
|
||||
(when doom-modeline-env-command
|
||||
(let* ((default-directory (doom-modeline-project-root))
|
||||
(s (shell-command-to-string doom-modeline-env-command)))
|
||||
(setq doom-modeline-env-version (if (string-match "[ \t\n\r]+\\'" s)
|
||||
(replace-match "" t t s)
|
||||
s)))))
|
||||
|
||||
(provide 'doom-modeline)
|
||||
|
||||
;;; doom-modeline.el ends here
|
||||
|
|
Loading…
Reference in a new issue