unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Eli Zaretskii <eliz@gnu.org>
Cc: dmitry@gutov.dev, 63469@debbugs.gnu.org, sbaugh@janestreet.com
Subject: bug#63469: 29.0.90; project.el doesn't add menu-bar entries
Date: Mon, 22 May 2023 20:48:08 +0300	[thread overview]
Message-ID: <86o7mccl5z.fsf@mail.linkov.net> (raw)
In-Reply-To: <835y8otbub.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 19 May 2023 21:28:28 +0300")

[-- Attachment #1: Type: text/plain, Size: 1261 bytes --]

>> >> +(define-minor-mode project-mode
>> >> +  "Toggle display of project menu in the project-aware buffers."
>> >> +  :lighter " Pro"
>> >> +  :keymap (define-keymap "<menu-bar>" project-mode-menu))
>> >
>> > If this mode is only for showing the menu, then at least the mode's
>> > name should reflect that.
>>
>> It can be used for anything.  For example, to display the project name
>> on the mode-line.  (Then better to cache the project name in a new
>> buffer-local variable.)
>
> I don't see anything but the menu in the patch you suggested.  I
> understand that in principle we could do many things there, but if you
> are proposing a real patch, not just an initial idea, please show all
> of the code you want to include in this mode.

Actually I miss this feature very much.  There is already the mode-line
indication with the VC system name and the VC branch name, but
no indication with a project name, so similar files
in different projects all are showing the same "Git-master".

Now here is the implementation of 'project-mode' based on 'vc-mode',
and 'project-menu-entry' based on 'vc-menu-entry' that shows
a project name alongside of vc info, and the mouse click opens
the project menu using 'menu-bar-project-menu' implemented by Spencer.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: project-mode-line.patch --]
[-- Type: text/x-diff, Size: 2343 bytes --]

diff --git a/lisp/bindings.el b/lisp/bindings.el
index c77b64c05da..ba9f44b920c 100644
--- a/lisp/bindings.el
+++ b/lisp/bindings.el
@@ -616,6 +616,7 @@ mode-line-end-spaces
 	     "   "
 	     'mode-line-position
 	     '(vc-mode vc-mode)
+	     '(project-mode project-name)
 	     "  "
 	     'mode-line-modes
 	     'mode-line-misc-info
diff --git a/lisp/desktop.el b/lisp/desktop.el
index 6aacb85c12c..6198441d788 100644
--- a/lisp/desktop.el
+++ b/lisp/desktop.el
@@ -547,6 +547,7 @@ desktop-minor-mode-table
   '((defining-kbd-macro nil)
     (isearch-mode nil)
     (vc-mode nil)
+    (project-mode nil)
     (vc-dir-mode nil)
     (erc-track-minor-mode nil)
     (savehist-mode nil))
diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index 7c51778d5d4..06bd0d09b8e 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -1883,5 +1908,47 @@ project-switch-project
     (let ((project-current-directory-override dir))
       (call-interactively command))))
 
+;;; Project mode
+
+;; Tell Emacs about this new kind of minor mode
+(add-to-list 'minor-mode-alist '(project-mode project-name))
+
+(defvar project-name nil
+  "The project name of the current buffer when it belongs to a project.")
+
+;;;###autoload
+(put 'project-name 'risky-local-variable t)
+(put 'project-name 'permanent-local t)
+
+(defvar project-menu-entry
+  `(menu-item ,(purecopy "Project") ,menu-bar-project-menu))
+
+(defconst project-mode-line-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map [mode-line down-mouse-1] project-menu-entry)
+    map))
+
+;;;###autoload
+(define-minor-mode project-mode
+  "Toggle display of project menu in the project-aware buffers."
+  (if project-mode
+      (setq-local project-name (concat
+	                        " "
+	                        (propertize
+	                         (project-name (project-current))
+	                         'mouse-face 'mode-line-highlight
+	                         'local-map project-mode-line-map)))))
+
+(defun project-mode--turn-on ()
+  "Turn on `project-mode' in all pertinent buffers."
+  (when (project-current)
+    (project-mode 1)))
+
+;;;###autoload
+(define-globalized-minor-mode global-project-mode
+  project-mode project-mode--turn-on
+  :group 'project
+  :version "30.1")
+
 (provide 'project)
 ;;; project.el ends here

  reply	other threads:[~2023-05-22 17:48 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-12 17:48 bug#63469: 29.0.90; project.el doesn't add menu-bar entries Spencer Baugh
2023-05-12 19:09 ` Eli Zaretskii
2023-05-12 19:25   ` Dmitry Gutov
2023-05-15 16:49 ` Juri Linkov
2023-05-15 18:15   ` Spencer Baugh
2023-05-15 18:19   ` Eli Zaretskii
2023-05-15 18:11 ` Spencer Baugh
2023-05-15 18:37   ` Eli Zaretskii
2023-05-15 18:46     ` Spencer Baugh
2023-05-16 16:09       ` Eli Zaretskii
2023-05-16 17:09         ` Spencer Baugh
2023-05-17 11:30           ` Eli Zaretskii
2023-05-17 14:50             ` Spencer Baugh
2023-05-18  6:53             ` Dmitry Gutov
2023-05-18  7:01               ` Eli Zaretskii
2023-05-18  9:49                 ` Dmitry Gutov
2023-05-18 10:23                   ` Eli Zaretskii
2023-05-18 14:30                     ` Spencer Baugh
2023-05-18 15:15                       ` Eli Zaretskii
2023-05-18 15:57                         ` Juri Linkov
2023-05-18 16:06                           ` Eli Zaretskii
2023-05-18 19:34                           ` Dmitry Gutov
2023-05-19  6:56                             ` Juri Linkov
2023-05-19 10:44                               ` Eli Zaretskii
2023-05-19 17:46                                 ` Juri Linkov
2023-05-19 18:28                                   ` Eli Zaretskii
2023-05-22 17:48                                     ` Juri Linkov [this message]
2023-05-22 18:20                                       ` Eli Zaretskii
2023-05-22 19:49                                         ` Spencer Baugh
2023-05-22 19:54                                           ` Dmitry Gutov
2023-05-22 21:20                                             ` Spencer Baugh
2023-05-22 21:30                                               ` Dmitry Gutov
2023-05-23 13:57                                                 ` Michael Albinus
2023-05-24  1:07                                                   ` Dmitry Gutov
2023-05-24  8:38                                                     ` Michael Albinus
2023-05-23  6:52                                           ` Juri Linkov
2023-05-23 11:17                                             ` Eli Zaretskii
2023-05-23 18:08                                               ` Juri Linkov
2023-05-24  1:10                                             ` Dmitry Gutov
2023-05-24  6:25                                               ` Juri Linkov
2023-05-25  1:15                                                 ` Dmitry Gutov
2023-05-25  6:35                                                   ` Juri Linkov
2023-05-25 16:17                                                     ` Dmitry Gutov
2023-05-23  6:49                                         ` Juri Linkov
2023-05-22 19:59                                       ` Dmitry Gutov
2023-05-23  6:46                                         ` Juri Linkov
2023-05-23 18:11                                           ` Juri Linkov
2023-05-24  1:03                                             ` Dmitry Gutov
2023-05-24  6:29                                               ` Juri Linkov
2023-05-25  1:14                                                 ` Dmitry Gutov
2023-05-25  6:29                                                   ` Juri Linkov
2023-05-25 16:14                                                     ` Dmitry Gutov
2023-05-25 18:41                                                       ` Juri Linkov
2023-05-25 22:19                                                         ` Dmitry Gutov
2023-05-30 17:51                                                           ` Juri Linkov
2023-06-02  2:11                                                             ` Dmitry Gutov
2023-06-02  6:37                                                               ` Juri Linkov
2023-06-03  1:36                                                                 ` Dmitry Gutov
2023-05-24  1:00                                           ` Dmitry Gutov
2023-05-19 14:42                           ` Spencer Baugh
2023-05-19 17:41                             ` Juri Linkov
2023-06-28  0:54 ` Spencer Baugh
2023-06-28  6:52   ` Juri Linkov
2023-06-29 15:30     ` Spencer Baugh
2023-06-29 17:31       ` Juri Linkov
2023-06-29 18:03       ` Eli Zaretskii
2023-06-29 19:22         ` Spencer Baugh
2023-06-30  5:32           ` Eli Zaretskii
2023-06-30 15:55             ` Spencer Baugh
2023-07-01  9:44               ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86o7mccl5z.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=63469@debbugs.gnu.org \
    --cc=dmitry@gutov.dev \
    --cc=eliz@gnu.org \
    --cc=sbaugh@janestreet.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).