[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 238292d6571 2/2: New option 'project-mode-line' to show project n
From: |
Juri Linkov |
Subject: |
master 238292d6571 2/2: New option 'project-mode-line' to show project name on mode line (bug#66317) |
Date: |
Mon, 9 Oct 2023 14:11:31 -0400 (EDT) |
branch: master
commit 238292d6571402e93d4f7886baac9853011b36f6
Author: Juri Linkov <juri@linkov.net>
Commit: Juri Linkov <juri@linkov.net>
New option 'project-mode-line' to show project name on mode line (bug#66317)
* lisp/bindings.el (standard-mode-line-format):
Add '(project-mode-line project-mode-line-format)'.
* lisp/progmodes/project.el (project-mode-line): New user option.
(project-menu-entry, project-mode-line-map): New variables.
(project-mode-line-format): New variable.
(project-mode-line-format): New function.
---
etc/NEWS | 4 ++++
lisp/bindings.el | 1 +
lisp/progmodes/project.el | 33 +++++++++++++++++++++++++++++++++
3 files changed, 38 insertions(+)
diff --git a/etc/NEWS b/etc/NEWS
index 8e05c668439..934521ec1b0 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -889,6 +889,10 @@ showcases all their customization options.
** Project
+*** New user option 'project-mode-line'.
+When non-nil, display the name of the current project on
+the mode line. Clicking mouse-1 pops up the project menu.
+
*** New user option 'project-file-history-behavior'.
Customizing it to 'relativize' makes commands like 'project-find-file'
and 'project-find-dir' display previous history entries relative to
diff --git a/lisp/bindings.el b/lisp/bindings.el
index 207adb3a2a4..70e4087e131 100644
--- a/lisp/bindings.el
+++ b/lisp/bindings.el
@@ -682,6 +682,7 @@ By default, this shows the information specified by
`global-mode-string'.")
'mode-line-buffer-identification
" "
'mode-line-position
+ '(project-mode-line project-mode-line-format)
'(vc-mode vc-mode)
" "
'mode-line-modes
diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 68d5edc482c..9997833ceb1 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -2010,5 +2010,38 @@ would otherwise have the same name."
(file-relative-name dirname root))))
dirname))
+;;; Project mode-line
+
+;;;###autoload
+(defcustom project-mode-line nil
+ "Show the current project name with the menu on the mode line.
+This feature requires the presence of the following item in
+`mode-line-format': `(project-mode-line project-mode-line-format)'."
+ :type 'boolean
+ :group 'project
+ :version "30.1")
+
+(defvar project-menu-entry
+ `(menu-item "Project" ,menu-bar-project-menu))
+
+(defvar project-mode-line-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map [mode-line down-mouse-1] project-menu-entry)
+ map))
+
+(defvar project-mode-line-format '(:eval (project-mode-line-format)))
+(put 'project-mode-line-format 'risky-local-variable t)
+
+(defun project-mode-line-format ()
+ "Compose the project mode-line."
+ (when-let ((project (project-current)))
+ (concat
+ " "
+ (propertize
+ (project-name project)
+ 'mouse-face 'mode-line-highlight
+ 'help-echo "mouse-1: Project menu"
+ 'local-map project-mode-line-map))))
+
(provide 'project)
;;; project.el ends here