all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jim Porter <jporterbugs@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 52286@debbugs.gnu.org
Subject: bug#52286: 28.0.90; [PATCH] Be consistent in naming of separators in context menu
Date: Sat, 11 Dec 2021 12:52:16 -0800	[thread overview]
Message-ID: <6faca77f-d732-d13e-2689-76e1e0943368@gmail.com> (raw)
In-Reply-To: <8335n53nai.fsf@gnu.org>

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

On 12/6/2021 4:55 AM, Eli Zaretskii wrote:
> I think the most natural place is where we describe how to construct
> menus.

Thanks.

>> We can detect whether an item is a separator pretty easily without this
>> change. However, context menu functions use specific separators to
>> determine where exactly it should put new menu items. For example,
>> `elisp-context-menu' adds menu items after `middle-separator':
>>
>>       (define-key-after menu [elisp-separator] menu-bar-separator
>>         'middle-separator)
>>
>> (Later in the function, it adds the actual menu items after the
>> newly-added `elisp-separator'.)
> 
> If this is a private convention of elisp-mode, we don't have to codify
> it.

It's not just for `elisp-mode'; any mode (or other third-party code) may 
want to insert context menu items in a certain spot. `middle-separator' 
follows the naming convention I recommend, but a hypothetical mode might 
want to insert a new item just after the separator for the Undo section. 
However, that's currently named `separator-undo' on master, so it can be 
confusing to remember the difference in naming between these two cases:

   (define-key-after menu [my-separator] menu-bar-separator
     'middle-separator)

   (define-key-after menu [my-separator] menu-bar-separator
     'separator-undo)

> So maybe instead of conventions we should have recommendations, with
> explanation why following that could be useful in some situation.
> Then let Lisp programmers decide what they want.

Ok, I've tried to provide a brief explanation of the recommendation and 
the reasoning for it without *over*-explaining it. I also added a small 
explanation about how to use `menu-bar-separator', since I didn't see 
documentation on that in the manual, and it helped segue into an 
explanation about the naming recommendation.

[-- Attachment #2: 0001-Rename-context-menu-separators-to-FOO-separator-for-.patch --]
[-- Type: text/plain, Size: 5135 bytes --]

From 7b646daeb0a8c9838d92eb9c093ac203bd9e1f03 Mon Sep 17 00:00:00 2001
From: Jim Porter <jporterbugs@gmail.com>
Date: Sat, 11 Dec 2021 12:44:12 -0800
Subject: [PATCH] Rename context menu separators to 'FOO-separator' for
 consistency

* lisp/mouse.el (context-menu-toolbar, context-menu-global)
(context-menu-local, context-menu-minor, context-menu-buffers)
(context-menu-vc, context-menu-undo, context-menu-region): Rename
separators to 'FOO-separator'.
* doc/lispref/keymaps.texi (Menu Separators): Add documentation
explaining 'menu-bar-separator' and naming convention of separators.
---
 doc/lispref/keymaps.texi | 15 ++++++++++++++-
 lisp/mouse.el            | 16 ++++++++--------
 2 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/doc/lispref/keymaps.texi b/doc/lispref/keymaps.texi
index edf1d6e83f..4fb66cecde 100644
--- a/doc/lispref/keymaps.texi
+++ b/doc/lispref/keymaps.texi
@@ -2460,7 +2460,20 @@ Menu Separators
 
   A menu separator is a kind of menu item that doesn't display any
 text---instead, it divides the menu into subparts with a horizontal line.
-A separator looks like this in the menu keymap:
+To create a basic separator, you can use @code{menu-bar-separator} when
+defining the item:
+
+@example
+(define-key map [@var{foo-separator}] menu-bar-separator)
+@end example
+
+@noindent
+When possible, it's recommended to name the key for the separator with
+the form @var{foo-separator} so that it's clear the underlying object
+is a separator.  For example, @code{region-separator} is preferred
+over @code{separator-region}.
+
+  A separator looks like this in the menu keymap:
 
 @example
 (menu-item @var{separator-type})
diff --git a/lisp/mouse.el b/lisp/mouse.el
index 11fdd3f639..96205fa346 100644
--- a/lisp/mouse.el
+++ b/lisp/mouse.el
@@ -358,7 +358,7 @@ context-menu-middle-separator
 (defun context-menu-toolbar (menu _click)
   "Populate MENU with submenus from the tool bar."
   (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
-  (define-key-after menu [separator-toolbar] menu-bar-separator)
+  (define-key-after menu [toolbar-separator] menu-bar-separator)
   (map-keymap (lambda (key binding)
                 (when (consp binding)
                   (define-key-after menu (vector key)
@@ -369,7 +369,7 @@ context-menu-toolbar
 (defun context-menu-global (menu _click)
   "Populate MENU with submenus from the global menu."
   (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
-  (define-key-after menu [separator-global] menu-bar-separator)
+  (define-key-after menu [global-separator] menu-bar-separator)
   (map-keymap (lambda (key binding)
                 (when (consp binding)
                   (define-key-after menu (vector key)
@@ -380,7 +380,7 @@ context-menu-global
 (defun context-menu-local (menu _click)
   "Populate MENU with submenus provided by major mode."
   (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
-  (define-key-after menu [separator-local] menu-bar-separator)
+  (define-key-after menu [local-separator] menu-bar-separator)
   (let ((keymap (local-key-binding [menu-bar])))
     (when keymap
       (map-keymap (lambda (key binding)
@@ -393,7 +393,7 @@ context-menu-local
 (defun context-menu-minor (menu _click)
   "Populate MENU with submenus provided by minor modes."
   (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
-  (define-key-after menu [separator-minor] menu-bar-separator)
+  (define-key-after menu [minor-separator] menu-bar-separator)
   (dolist (mode (reverse (minor-mode-key-binding [menu-bar])))
     (when (and (consp mode) (symbol-value (car mode)))
       (map-keymap (lambda (key binding)
@@ -406,7 +406,7 @@ context-menu-minor
 (defun context-menu-buffers (menu _click)
   "Populate MENU with the buffer submenus to buffer switching."
   (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
-  (define-key-after menu [separator-buffers] menu-bar-separator)
+  (define-key-after menu [buffers-separator] menu-bar-separator)
   (map-keymap (lambda (key binding)
                 (when (consp binding)
                   (define-key-after menu (vector key)
@@ -416,13 +416,13 @@ context-menu-buffers
 
 (defun context-menu-vc (menu _click)
   "Populate MENU with Version Control commands."
-  (define-key-after menu [separator-vc] menu-bar-separator)
+  (define-key-after menu [vc-separator] menu-bar-separator)
   (define-key-after menu [vc-menu] vc-menu-entry)
   menu)
 
 (defun context-menu-undo (menu _click)
   "Populate MENU with undo commands."
-  (define-key-after menu [separator-undo] menu-bar-separator)
+  (define-key-after menu [undo-separator] menu-bar-separator)
   (when (and (not buffer-read-only)
              (not (eq t buffer-undo-list))
              (if (eq last-command 'undo)
@@ -440,7 +440,7 @@ context-menu-undo
 
 (defun context-menu-region (menu click)
   "Populate MENU with region commands."
-  (define-key-after menu [separator-region] menu-bar-separator)
+  (define-key-after menu [region-separator] menu-bar-separator)
   (when (and mark-active (not buffer-read-only))
     (define-key-after menu [cut]
       '(menu-item "Cut" kill-region
-- 
2.25.1


  reply	other threads:[~2021-12-11 20:52 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-04 21:57 bug#52286: 28.0.90; [PATCH] Be consistent in naming of separators in context menu Jim Porter
2021-12-05  6:45 ` Eli Zaretskii
2021-12-05  7:44   ` Jim Porter
2021-12-05 10:39     ` Eli Zaretskii
2021-12-06  2:09       ` Jim Porter
2021-12-06 12:55         ` Eli Zaretskii
2021-12-11 20:52           ` Jim Porter [this message]
2022-01-15 18:57             ` Juri Linkov
2022-01-15 19:13               ` Eli Zaretskii
2022-01-15 19:19                 ` Juri Linkov
2022-01-15 19:23                   ` Eli Zaretskii
2022-01-15 19:25                     ` Juri Linkov
2021-12-05  9:37   ` Juri Linkov
2021-12-05 17:52 ` Juri Linkov

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

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

  git send-email \
    --in-reply-to=6faca77f-d732-d13e-2689-76e1e0943368@gmail.com \
    --to=jporterbugs@gmail.com \
    --cc=52286@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.