mirror of
https://github.com/correl/doom-modeline.git
synced 2024-11-23 19:19:50 +00:00
Merge new codes and fix warnings.
This commit is contained in:
parent
2d9ce25bcc
commit
0234007b08
1 changed files with 64 additions and 50 deletions
114
doom-modeline.el
114
doom-modeline.el
|
@ -308,10 +308,19 @@ If STRICT-P, return nil if no project was found, otherwise return
|
||||||
(force-mode-line-update))
|
(force-mode-line-update))
|
||||||
|
|
||||||
(add-hook 'window-configuration-change-hook #'doom-modeline-set-selected-window)
|
(add-hook 'window-configuration-change-hook #'doom-modeline-set-selected-window)
|
||||||
(add-hook 'focus-in-hook #'doom-modeline-set-selected-window)
|
|
||||||
(add-hook 'focus-out-hook #'doom-modeline-unset-selected-window)
|
|
||||||
(add-hook 'doom-after-switch-window-hook #'doom-modeline-set-selected-window)
|
(add-hook 'doom-after-switch-window-hook #'doom-modeline-set-selected-window)
|
||||||
(add-hook 'doom-after-switch-frame-hook #'doom-modeline-set-selected-window)
|
(with-no-warnings
|
||||||
|
(if (not (boundp 'after-focus-change-function))
|
||||||
|
(progn
|
||||||
|
(add-hook 'focus-in-hook #'doom-modeline-set-selected-window)
|
||||||
|
(add-hook 'focus-out-hook #'doom-modeline-unset-selected-window))
|
||||||
|
(defun doom-modeline-refresh-frame ()
|
||||||
|
(setq +doom-modeline-current-window nil)
|
||||||
|
(cl-loop for frame in (frame-list)
|
||||||
|
if (eq (frame-focus-state frame) t)
|
||||||
|
return (setq +doom-modeline-current-window (frame-selected-window frame)))
|
||||||
|
(force-mode-line-update))
|
||||||
|
(add-function :after after-focus-change-function #'doom-modeline-refresh-frame)))
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;; Variables
|
;; Variables
|
||||||
|
@ -413,32 +422,25 @@ active."
|
||||||
"The face used for eyebrowse."
|
"The face used for eyebrowse."
|
||||||
:group 'doom-modeline)
|
:group 'doom-modeline)
|
||||||
|
|
||||||
;;
|
|
||||||
;; 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)
|
|
||||||
(doom-modeline-add-hook! '(focus-in-hook find-file-hook) #'doom-modeline-update-env)
|
|
||||||
(defun doom-modeline-update-env ()
|
|
||||||
(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
|
|
||||||
(doom-modeline-add-hook! 'python-mode-hook (setq doom-modeline-env-command "python --version 2>&1 | cut -d' ' -f2"))
|
|
||||||
(doom-modeline-add-hook! 'ruby-mode-hook (setq doom-modeline-env-command "ruby --version 2>&1 | cut -d' ' -f2"))
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;; Modeline helpers
|
;; Modeline helpers
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
(defun doom-modeline-maybe-icon-octicon (&rest args)
|
||||||
|
"Display octicon via `ARGS'."
|
||||||
|
(when (and (featurep 'all-the-icons) (display-graphic-p) (not (eq system-type 'windows-nt)))
|
||||||
|
(apply 'all-the-icons-octicon args)))
|
||||||
|
|
||||||
|
(defun doom-modeline-maybe-icon-faicon (&rest args)
|
||||||
|
"Display font awesome icon via `ARGS'."
|
||||||
|
(when (and (featurep 'all-the-icons) (display-graphic-p) (not (eq system-type 'windows-nt)))
|
||||||
|
(apply 'all-the-icons-faicon args)))
|
||||||
|
|
||||||
|
(defun doom-modeline-maybe-icon-material (&rest args)
|
||||||
|
"Display material icon via `ARGS'."
|
||||||
|
(when (and (featurep 'all-the-icons) (display-graphic-p) (not (eq system-type 'windows-nt)))
|
||||||
|
(apply 'all-the-icons-material args)))
|
||||||
|
|
||||||
(defsubst doom-modeline--active ()
|
(defsubst doom-modeline--active ()
|
||||||
(eq (selected-window) doom-modeline-current-window))
|
(eq (selected-window) doom-modeline-current-window))
|
||||||
|
|
||||||
|
@ -447,9 +449,7 @@ active."
|
||||||
(propertize
|
(propertize
|
||||||
" " 'display
|
" " 'display
|
||||||
(let ((data (make-list height (make-list width 1)))
|
(let ((data (make-list height (make-list width 1)))
|
||||||
(color (or (when face
|
(color (or (face-background face nil t) "None")))
|
||||||
(face-background face nil t))
|
|
||||||
"None")))
|
|
||||||
(ignore-errors
|
(ignore-errors
|
||||||
(create-image
|
(create-image
|
||||||
(concat
|
(concat
|
||||||
|
@ -472,7 +472,7 @@ active."
|
||||||
'xpm t :ascent 'center)))))
|
'xpm t :ascent 'center)))))
|
||||||
|
|
||||||
(defun doom-modeline-buffer-file-name ()
|
(defun doom-modeline-buffer-file-name ()
|
||||||
"Propertized `buffer-file-name' based on `doom-modeline-buffer-file-name-style'."
|
"Propertized variable `buffer-file-name' based on `+doom-modeline-buffer-file-name-style'."
|
||||||
(let ((buffer-file-name (or buffer-file-name ""))
|
(let ((buffer-file-name (or buffer-file-name ""))
|
||||||
(buffer-file-truename (or buffer-file-truename "")))
|
(buffer-file-truename (or buffer-file-truename "")))
|
||||||
(propertize
|
(propertize
|
||||||
|
@ -495,14 +495,14 @@ active."
|
||||||
"Propertized `buffer-file-name' that truncates every dir along path.
|
"Propertized `buffer-file-name' that truncates every dir along path.
|
||||||
If TRUNCATE-TAIL is t also truncate the parent directory of the file."
|
If TRUNCATE-TAIL is t also truncate the parent directory of the file."
|
||||||
(let ((dirs (shrink-path-prompt (file-name-directory buffer-file-truename)))
|
(let ((dirs (shrink-path-prompt (file-name-directory buffer-file-truename)))
|
||||||
(doom-modeline--active (doom-modeline--active)))
|
(active (doom-modeline--active)))
|
||||||
(if (null dirs)
|
(if (null dirs)
|
||||||
(propertize "%b" 'face (if doom-modeline--active 'doom-modeline-buffer-file))
|
(propertize "%b" 'face (if active 'doom-modeline-buffer-file))
|
||||||
(let ((modified-faces (if (buffer-modified-p) 'doom-modeline-buffer-modified)))
|
(let ((modified-faces (if (buffer-modified-p) 'doom-modeline-buffer-modified)))
|
||||||
(let ((dirname (car dirs))
|
(let ((dirname (car dirs))
|
||||||
(basename (cdr dirs))
|
(basename (cdr dirs))
|
||||||
(dir-faces (or modified-faces (if doom-modeline--active 'doom-modeline-project-root-dir)))
|
(dir-faces (or modified-faces (if active 'doom-modeline-project-root-dir)))
|
||||||
(file-faces (or modified-faces (if doom-modeline--active 'doom-modeline-buffer-file))))
|
(file-faces (or modified-faces (if active 'doom-modeline-buffer-file))))
|
||||||
(concat (propertize (concat dirname
|
(concat (propertize (concat dirname
|
||||||
(if truncate-tail (substring basename 0 1) basename)
|
(if truncate-tail (substring basename 0 1) basename)
|
||||||
"/")
|
"/")
|
||||||
|
@ -510,18 +510,6 @@ If TRUNCATE-TAIL is t also truncate the parent directory of the file."
|
||||||
(propertize (file-name-nondirectory buffer-file-name)
|
(propertize (file-name-nondirectory buffer-file-name)
|
||||||
'face (if file-faces `(:inherit ,file-faces)))))))))
|
'face (if file-faces `(:inherit ,file-faces)))))))))
|
||||||
|
|
||||||
(defun doom-modeline-maybe-icon-octicon (&rest args)
|
|
||||||
(when (and (featurep 'all-the-icons) (display-graphic-p) (not (eq system-type 'windows-nt)))
|
|
||||||
(apply 'all-the-icons-octicon args)))
|
|
||||||
|
|
||||||
(defun doom-modeline-maybe-icon-faicon (&rest args)
|
|
||||||
(when (and (featurep 'all-the-icons) (display-graphic-p) (not (eq system-type 'windows-nt)))
|
|
||||||
(apply 'all-the-icons-faicon args)))
|
|
||||||
|
|
||||||
(defun doom-modeline-maybe-icon-material (&rest args)
|
|
||||||
(when (and (featurep 'all-the-icons) (display-graphic-p) (not (eq system-type 'windows-nt)))
|
|
||||||
(apply 'all-the-icons-material args)))
|
|
||||||
|
|
||||||
(defun doom-modeline--buffer-file-name-relative (&optional include-project)
|
(defun doom-modeline--buffer-file-name-relative (&optional include-project)
|
||||||
"Propertized `buffer-file-name' showing directories relative to project's root only."
|
"Propertized `buffer-file-name' showing directories relative to project's root only."
|
||||||
(let ((root (doom-modeline-project-root))
|
(let ((root (doom-modeline-project-root))
|
||||||
|
@ -667,6 +655,7 @@ directory, the file name, and its state (modified, read-only or non-existent)."
|
||||||
|
|
||||||
(defvar-local doom-modeline--vcs nil)
|
(defvar-local doom-modeline--vcs nil)
|
||||||
(defun doom-modeline--update-vcs ()
|
(defun doom-modeline--update-vcs ()
|
||||||
|
"Update vsc status in mode-line."
|
||||||
(setq doom-modeline--vcs
|
(setq doom-modeline--vcs
|
||||||
(when (and vc-mode buffer-file-name)
|
(when (and vc-mode buffer-file-name)
|
||||||
(let* ((backend (vc-backend buffer-file-name))
|
(let* ((backend (vc-backend buffer-file-name))
|
||||||
|
@ -713,12 +702,12 @@ directory, the file name, and its state (modified, read-only or non-existent)."
|
||||||
;;
|
;;
|
||||||
|
|
||||||
(defvar doom-modeline-vspc
|
(defvar doom-modeline-vspc
|
||||||
(propertize " " 'face 'variable-pitch)
|
"Text style with icons in mode-line."
|
||||||
"TODO")
|
(propertize " " 'face 'variable-pitch))
|
||||||
|
|
||||||
(defun doom-modeline-icon (icon &optional text face voffset)
|
(defun doom-modeline-icon (icon &optional text face voffset)
|
||||||
"Displays an ICON with FACE, followed by TEXT. Uses
|
"Displays an ICON with FACE, followed by TEXT.
|
||||||
`all-the-icons-material' to fetch the icon."
|
Uses `all-the-icons-material' to fetch the icon."
|
||||||
(concat (if vc-mode " " " ")
|
(concat (if vc-mode " " " ")
|
||||||
(when icon
|
(when icon
|
||||||
(concat
|
(concat
|
||||||
|
@ -895,7 +884,7 @@ with `evil-ex-substitute', and/or 4. The number of active `iedit' regions."
|
||||||
(doom-modeline-def-segment! bar
|
(doom-modeline-def-segment! bar
|
||||||
"The bar regulates the height of the mode-line in GUI Emacs.
|
"The bar regulates the height of the mode-line in GUI Emacs.
|
||||||
Returns \"\" to not break --no-window-system."
|
Returns \"\" to not break --no-window-system."
|
||||||
(if window-system
|
(if (display-graphic-p)
|
||||||
(if (doom-modeline--active)
|
(if (doom-modeline--active)
|
||||||
doom-modeline--bar-active
|
doom-modeline--bar-active
|
||||||
doom-modeline--bar-inactive)
|
doom-modeline--bar-inactive)
|
||||||
|
@ -977,6 +966,7 @@ enabled."
|
||||||
;;
|
;;
|
||||||
|
|
||||||
(defun doom-modeline-refresh-bars (&optional width height)
|
(defun doom-modeline-refresh-bars (&optional width height)
|
||||||
|
"Refreash mode-line bars with `WIDTH' and `HEIGHT'."
|
||||||
(setq doom-modeline--bar-active
|
(setq doom-modeline--bar-active
|
||||||
(doom-modeline--make-xpm 'doom-modeline-bar
|
(doom-modeline--make-xpm 'doom-modeline-bar
|
||||||
(or width doom-modeline-bar-width)
|
(or width doom-modeline-bar-width)
|
||||||
|
@ -988,6 +978,7 @@ enabled."
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom-modeline-init ()
|
(defun doom-modeline-init ()
|
||||||
|
"Initialize doom mode-line."
|
||||||
;; Create bars
|
;; Create bars
|
||||||
(doom-modeline-refresh-bars)
|
(doom-modeline-refresh-bars)
|
||||||
(unless after-init-time
|
(unless after-init-time
|
||||||
|
@ -998,12 +989,15 @@ enabled."
|
||||||
(doom-modeline-set 'main)))))
|
(doom-modeline-set 'main)))))
|
||||||
|
|
||||||
(defun doom-modeline-set-special-modeline ()
|
(defun doom-modeline-set-special-modeline ()
|
||||||
|
"Set sepcial mode-line."
|
||||||
(doom-modeline-set 'special))
|
(doom-modeline-set 'special))
|
||||||
|
|
||||||
(defun doom-modeline-set-media-modeline ()
|
(defun doom-modeline-set-media-modeline ()
|
||||||
|
"Set media mode-line."
|
||||||
(doom-modeline-set 'media))
|
(doom-modeline-set 'media))
|
||||||
|
|
||||||
(defun doom-modeline-set-project-modeline ()
|
(defun doom-modeline-set-project-modeline ()
|
||||||
|
"Set project mode-line."
|
||||||
(doom-modeline-set 'project))
|
(doom-modeline-set 'project))
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
@ -1019,13 +1013,33 @@ enabled."
|
||||||
(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)
|
||||||
|
|
||||||
|
;; 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)
|
||||||
|
(doom-modeline-add-hook! '(focus-in-hook find-file-hook) #'doom-modeline-update-env)
|
||||||
|
(defun doom-modeline-update-env ()
|
||||||
|
(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
|
||||||
|
(doom-modeline-add-hook! 'python-mode-hook (setq doom-modeline-env-command "python --version 2>&1 | cut -d' ' -f2"))
|
||||||
|
(doom-modeline-add-hook! 'ruby-mode-hook (setq doom-modeline-env-command "ruby --version 2>&1 | cut -d' ' -f2"))
|
||||||
|
|
||||||
;; Ensure modeline is inactive when Emacs is unfocused (and active otherwise)
|
;; Ensure modeline is inactive when Emacs is unfocused (and active otherwise)
|
||||||
(defvar doom-modeline-remap-face-cookie nil)
|
(defvar doom-modeline-remap-face-cookie nil)
|
||||||
(defun doom-modeline-focus ()
|
(defun doom-modeline-focus ()
|
||||||
|
"Focus mode-line."
|
||||||
(when doom-modeline-remap-face-cookie
|
(when doom-modeline-remap-face-cookie
|
||||||
(require 'face-remap)
|
(require 'face-remap)
|
||||||
(face-remap-remove-relative doom-modeline-remap-face-cookie)))
|
(face-remap-remove-relative doom-modeline-remap-face-cookie)))
|
||||||
(defun doom-modeline-unfocus ()
|
(defun doom-modeline-unfocus ()
|
||||||
|
"Unfocus mode-line."
|
||||||
(setq doom-modeline-remap-face-cookie (face-remap-add-relative 'mode-line 'mode-line-inactive)))
|
(setq doom-modeline-remap-face-cookie (face-remap-add-relative 'mode-line 'mode-line-inactive)))
|
||||||
|
|
||||||
(add-hook 'focus-in-hook #'doom-modeline-focus)
|
(add-hook 'focus-in-hook #'doom-modeline-focus)
|
||||||
|
|
Loading…
Reference in a new issue