[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 4a303c4 2/3: Remove separators at the beginning and end of the co
From: |
Lars Ingebrigtsen |
Subject: |
master 4a303c4 2/3: Remove separators at the beginning and end of the context menu |
Date: |
Fri, 3 Dec 2021 11:23:06 -0500 (EST) |
branch: master
commit 4a303c4dcac590c65c5a4826682c68a4023085b1
Author: Jim Porter <jporterbugs@gmail.com>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
Remove separators at the beginning and end of the context menu
* lisp/mouse.el (context-menu-map): Remove beginning/end
seperators (bug#52237).
---
lisp/mouse.el | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/lisp/mouse.el b/lisp/mouse.el
index ec43aec..b5ca80a 100644
--- a/lisp/mouse.el
+++ b/lisp/mouse.el
@@ -327,12 +327,21 @@ the function `context-menu-filter-function'."
(setq menu (funcall fun menu click))
nil)))
- ;; Remove duplicate separators
- (let ((l menu))
- (while (consp l)
- (if (and (equal (cdr-safe (car l)) menu-bar-separator)
- (equal (cdr-safe (cadr l)) menu-bar-separator))
+ ;; Remove duplicate separators as well as ones at the beginning or
+ ;; end of the menu.
+ (let ((l menu) saw-first-item)
+ (while (consp (cdr l))
+ ;; If the next item is a separator, remove it if 1) we haven't
+ ;; seen any other items yet, or 2) it's followed by either
+ ;; another separator or the end of the list.
+ (if (and (equal (cdr-safe (cadr l)) menu-bar-separator)
+ (or (not saw-first-item)
+ (null (caddr l))
+ (equal (cdr-safe (caddr l)) menu-bar-separator)))
(setcdr l (cddr l))
+ ;; The "first item" is any cons cell; this excludes the
+ ;; `keymap' symbol and the menu name.
+ (when (consp (cadr l)) (setq saw-first-item t))
(setq l (cdr l)))))
(when (functionp context-menu-filter-function)