Skip to content

Commit

Permalink
feat: Add support for Emacs 30 project-mode-line option
Browse files Browse the repository at this point in the history
Closes #750.

new option: doom-modeline-project-name
new faces: doom-modeline-project-name, doom-modeline-workspace-name
  • Loading branch information
seagle0128 committed Dec 1, 2024
1 parent e6ae2ec commit ba6afb2
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 7 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ Run `M-x customize-group RET doom-modeline RET` or set the variables.
;; The maximum number displayed for notifications.
(setq doom-modeline-number-limit 99)
;; Whether display the project name. Non-nil to display in the mode-line.
(setq doom-modeline-project-name t)
;; Whether display the workspace name. Non-nil to display in the mode-line.
(setq doom-modeline-workspace-name t)
Expand Down
17 changes: 17 additions & 0 deletions doom-modeline-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,13 @@ It respects option `doom-modeline-icon'."
:type 'integer
:group 'doom-modeline)

(defcustom doom-modeline-project-name (bound-and-true-p project-mode-line)
"Whether display the project name.
Non-nil to display in the mode-line."
:type 'boolean
:group 'doom-modeline)

(defcustom doom-modeline-workspace-name t
"Whether display the workspace name.
Expand Down Expand Up @@ -947,6 +954,16 @@ Also see the face `doom-modeline-unread-number'."
"Face for the keypad state in meow-edit indicator."
:group 'doom-modeline-faces)

(defface doom-modeline-project-name
'((t (:inherit (doom-modeline font-lock-comment-face italic))))
"Face for the project name."
:group 'doom-modeline-faces)

(defface doom-modeline-workspace-name
'((t (:inherit (doom-modeline-emphasis bold))))
"Face for the workspace name."
:group 'doom-modeline-faces)

(defface doom-modeline-persp-name
'((t (:inherit (doom-modeline font-lock-comment-face italic))))
"Face for the persp name."
Expand Down
65 changes: 59 additions & 6 deletions doom-modeline-segments.el
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
(defvar phi-search--overlays)
(defvar phi-search--selection)
(defvar phi-search-mode-line-format)
(defvar projectile-mode-map)
(defvar rcirc-activity)
(defvar symbol-overlay-keywords-alist)
(defvar symbol-overlay-temp-symbol)
Expand Down Expand Up @@ -222,6 +223,8 @@
(declare-function poke-line-create "ext:poke-line")
(declare-function popup-create "ext:popup")
(declare-function popup-delete "ext:popup")
(declare-function project-name "project")
(declare-function projectile-project-name "ext:projectile")
(declare-function rcirc-next-active-buffer "rcirc")
(declare-function rcirc-short-buffer-name "rcirc")
(declare-function rcirc-switch-to-server-buffer "rcirc")
Expand Down Expand Up @@ -1516,6 +1519,58 @@ one. The ignored buffers are excluded unless `aw-ignore-on' is nil."
(propertize (format " %s " num)
'face (doom-modeline-face 'doom-modeline-buffer-major-mode)))))

;;
;; Project
;;

(defvar doom-modeline-project-map
(cond
((and (memq doom-modeline-project-detection '(auto projectile))
(bound-and-true-p projectile-mode))
projectile-mode-map)
((and (memq doom-modeline-project-detection '(auto project))
(fboundp 'project-current))
(let ((map (make-sparse-keymap)))
(define-key map [mode-line down-mouse-1]
(bound-and-true-p menu-bar-project-item))
map))))

(defvar-local doom-modeline--project-name nil)
(defun doom-modeline-project-name ()
"Get the project name."
(or doom-modeline--project-name
(setq doom-modeline--project-name
(let ((name (cond
((and (memq doom-modeline-project-detection '(auto projectile))
(bound-and-true-p projectile-mode))
(projectile-project-name))
((and (memq doom-modeline-project-detection '(auto project))
(fboundp 'project-current))
(when-let* ((project (project-current)))
(project-name project)))
(t ""))))
(unless (string-empty-p name)
(format " [%s] " name))))))

(doom-modeline-add-variable-watcher
'doom-modeline-project-detection
(lambda (_sym val op _where)
(when (eq op 'set)
(setq doom-modeline-project-detection val)
(dolist (buf (buffer-list))
(with-current-buffer buf
(setq doom-modeline--project-name nil)
(and buffer-file-name (revert-buffer t t)))))))

(doom-modeline-def-segment project-name
"The current perspective name."
(when (doom-modeline--segment-visible 'project-name)
(propertize (doom-modeline-project-name)
'face (doom-modeline-face 'doom-modeline-project-name)
'mouse-face 'mode-line-highlight
'help-echo "mouse-1: Project menu"
'local-map doom-modeline-project-map)))


;;
;; Workspace
Expand All @@ -1542,8 +1597,9 @@ Requires `eyebrowse-mode' to be enabled or `tab-bar-mode' tabs to be created."
(explicit-name (alist-get 'explicit-name current-tab))
(tab-name (alist-get 'name current-tab)))
(if explicit-name tab-name (+ 1 tab-index)))))))
(propertize (format " %s " name)
'face (doom-modeline-face 'doom-modeline-buffer-major-mode)))))
(unless (string-empty-p name)
(propertize (format " %s " name)
'face (doom-modeline-face 'doom-modeline-workspace-name))))))


;;
Expand Down Expand Up @@ -1571,10 +1627,7 @@ Requires `eyebrowse-mode' to be enabled or `tab-bar-mode' tabs to be created."
(not (string-equal persp-nil-name name)))
(concat " "
(propertize (concat (and doom-modeline-persp-icon
(concat icon
(propertize
" "
'display '((space :relative-width 0.5)))))
(concat icon (doom-modeline-vspc)))
(propertize name 'face face))
'help-echo "mouse-1: Switch perspective
mouse-2: Show help for minor mode"
Expand Down
2 changes: 1 addition & 1 deletion doom-modeline.el
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@

(doom-modeline-def-modeline 'main
'(eldoc bar workspace-name window-number modals matches follow buffer-info remote-host buffer-position word-count parrot selection-info)
'(compilation objed-state misc-info persp-name battery grip irc mu4e gnus github debug repl lsp minor-modes input-method indent-info buffer-encoding major-mode process vcs check time))
'(compilation objed-state misc-info project-name persp-name battery grip irc mu4e gnus github debug repl lsp minor-modes input-method indent-info buffer-encoding major-mode process vcs check time))

(doom-modeline-def-modeline 'minimal
'(bar window-number modals matches buffer-info-simple)
Expand Down

0 comments on commit ba6afb2

Please sign in to comment.