[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/git-commit 29f5be3576 2/2: Backport menu functions for Ema
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/git-commit 29f5be3576 2/2: Backport menu functions for Emacs < 28 |
Date: |
Sat, 26 Mar 2022 18:58:16 -0400 (EDT) |
branch: elpa/git-commit
commit 29f5be3576ce031f90eb9637dd3bd8ec627d53f4
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Jonas Bernoulli <jonas@bernoul.li>
Backport menu functions for Emacs < 28
---
lisp/magit-section.el | 30 ++++++++++++++++++++++++++++--
1 file changed, 28 insertions(+), 2 deletions(-)
diff --git a/lisp/magit-section.el b/lisp/magit-section.el
index 923bcee329..80416be5f0 100644
--- a/lisp/magit-section.el
+++ b/lisp/magit-section.el
@@ -355,7 +355,9 @@ if any.")
`( menu-item "" ,(make-sparse-keymap)
:filter ,(lambda (_)
(let ((menu (make-sparse-keymap)))
- (context-menu-local menu last-input-event)
+ (if (fboundp 'context-menu-local)
+ (context-menu-local menu last-input-event)
+ (magit--context-menu-local menu last-input-event))
(magit-section-context-menu menu last-input-event)
menu)))))
(define-key map [left-fringe mouse-1] 'magit-mouse-toggle-section)
@@ -578,7 +580,9 @@ The return value has the form (TYPE...)."
(when (consp binding)
(define-key-after menu (vector key)
(copy-sequence binding))))
- (menu-bar-keymap map))))
+ (if (fboundp 'menu-bar-keymap)
+ (menu-bar-keymap map)
+ (magit--menu-bar-keymap map)))))
menu)
(defun magit-menu-set (keymap key def desc &optional props after)
@@ -694,6 +698,28 @@ The following %-specs are allowed:
(?M . ,(or multiple value))
(?x . ,(format "%s" magit-menu-common-value))))))
+(defun magit--menu-bar-keymap (keymap)
+ "Backport of `menu-bar-keymap' for Emacs < 28.
+Slight trimmed down."
+ (let ((menu-bar nil))
+ (map-keymap (lambda (key binding)
+ (push (cons key binding) menu-bar))
+ keymap)
+ (cons 'keymap (nreverse menu-bar))))
+
+(defun magit--context-menu-local (menu _click)
+ "Backport of `context-menu-local' for Emacs < 28."
+ (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
+ (define-key-after menu [separator-local] menu-bar-separator)
+ (let ((keymap (local-key-binding [menu-bar])))
+ (when keymap
+ (map-keymap (lambda (key binding)
+ (when (consp binding)
+ (define-key-after menu (vector key)
+ (copy-sequence binding))))
+ (magit--menu-bar-keymap keymap))))
+ menu)
+
(advice-add 'context-menu-region :around
(lambda (fn menu click)
"Disable in `magit-section-mode' buffers."