branch: elpa/git-commit
commit deb10e984e16201182b0569f7df7d30ec3b8afa9
Author: Jonas Bernoulli <jo...@bernoul.li>
Commit: Jonas Bernoulli <jo...@bernoul.li>

    Use defvar-keymap for keymaps containing context menus
---
 lisp/magit-diff.el      | 141 ++++++++++++++++++++++++------------------------
 lisp/magit-log.el       |  34 +++++-------
 lisp/magit-refs.el      |  43 +++++++--------
 lisp/magit-section.el   |  76 ++++++++++----------------
 lisp/magit-stash.el     |  32 +++++------
 lisp/magit-status.el    |  22 ++++----
 lisp/magit-submodule.el |  42 +++++++--------
 lisp/magit-worktree.el  |  16 +++---
 8 files changed, 188 insertions(+), 218 deletions(-)

diff --git a/lisp/magit-diff.el b/lisp/magit-diff.el
index bc04868c30..1f0b8844b2 100644
--- a/lisp/magit-diff.el
+++ b/lisp/magit-diff.el
@@ -1962,62 +1962,61 @@ Staging and applying changes is documented in info node
 
 (define-obsolete-variable-alias 'magit-diff-section-base-map
   'magit-diff-section-map "Magit-Section 4.0.0")
-(defvar magit-diff-section-map
-  (let ((map (make-sparse-keymap)))
-    (magit-menu-set map [magit-cherry-apply]
-      #'magit-apply "Apply %x"
-      '(:enable (not (memq (magit-diff-type) '(unstaged staged)))))
-    (magit-menu-set map [magit-stage-file]
-      #'magit-stage "Stage %x"
-      '(:enable (eq (magit-diff-type) 'unstaged)))
-    (magit-menu-set map [magit-unstage-file]
-      #'magit-unstage "Unstage %x"
-      '(:enable (eq (magit-diff-type) 'staged)))
-    (magit-menu-set map [magit-delete-thing]
-      #'magit-discard "Discard %x"
-      '(:enable (not (memq (magit-diff-type) '(committed undefined)))))
-    (magit-menu-set map [magit-revert-no-commit]
-      #'magit-reverse "Reverse %x"
-      '(:enable (not (memq (magit-diff-type) '(untracked unstaged)))))
-    (magit-menu-set map [magit-visit-thing]
-      #'magit-diff-visit-file "Visit file")
-    (magit-menu-set map [magit-file-untrack]
-      #'magit-file-untrack "Untrack %x"
-      '(:enable (memq (magit-diff-scope) '(file files))))
-    (magit-menu-set map [magit-file-rename]
-      #'magit-file-rename "Rename file"
-      '(:enable (eq (magit-diff-scope) 'file)))
-    (keymap-set map "C-j"            #'magit-diff-visit-worktree-file)
-    (keymap-set map "C-<return>"     #'magit-diff-visit-worktree-file)
-    (keymap-set map "C-x 4 <return>" #'magit-diff-visit-file-other-window)
-    (keymap-set map "C-x 5 <return>" #'magit-diff-visit-file-other-frame)
-    (keymap-set map "&"       #'magit-do-async-shell-command)
-    (keymap-set map "C"       #'magit-commit-add-log)
-    (keymap-set map "C-x a"   #'magit-add-change-log-entry)
-    (keymap-set map "C-x 4 a" #'magit-add-change-log-entry-other-window)
-    (keymap-set map "C-c C-t" #'magit-diff-trace-definition)
-    (keymap-set map "C-c C-e" #'magit-diff-edit-hunk-commit)
-    map)
-  "Keymap for diff sections.
+
+
+(defvar-keymap magit-diff-section-map
+  :doc "Keymap for diff sections.
 The classes `magit-file-section' and `magit-hunk-section' derive
 from the abstract `magit-diff-section' class.  Accordingly this
-keymap is the parent of their keymaps.")
+keymap is the parent of their keymaps."
+  "C-j"            #'magit-diff-visit-worktree-file
+  "C-<return>"     #'magit-diff-visit-worktree-file
+  "C-x 4 <return>" #'magit-diff-visit-file-other-window
+  "C-x 5 <return>" #'magit-diff-visit-file-other-frame
+  "&"              #'magit-do-async-shell-command
+  "C"              #'magit-commit-add-log
+  "C-x a"          #'magit-add-change-log-entry
+  "C-x 4 a"        #'magit-add-change-log-entry-other-window
+  "C-c C-t"        #'magit-diff-trace-definition
+  "C-c C-e"        #'magit-diff-edit-hunk-commit
+  "<remap> <magit-file-rename>"      #'magit-file-rename
+  "<remap> <magit-file-untrack>"     #'magit-file-untrack
+  "<remap> <magit-visit-thing>"      #'magit-diff-visit-file
+  "<remap> <magit-revert-no-commit>" #'magit-reverse
+  "<remap> <magit-delete-thing>"     #'magit-discard
+  "<remap> <magit-unstage-file>"     #'magit-unstage
+  "<remap> <magit-stage-file>"       #'magit-stage
+  "<remap> <magit-cherry-apply>"     #'magit-apply
+  "<8>" (magit-menu-item "Rename file" #'magit-file-rename
+                         '(:enable (eq (magit-diff-scope) 'file)))
+  "<7>" (magit-menu-item "Untrack %x" #'magit-file-untrack)
+  "<6>" (magit-menu-item "Visit file" #'magit-diff-visit-file
+                         '(:enable (memq (magit-diff-scope) '(file files))))
+  "<5>" (magit-menu-item "Reverse %x" #'magit-reverse
+                         '(:enable (not (memq (magit-diff-type)
+                                              '(untracked unstaged)))))
+  "<4>" (magit-menu-item "Discard %x" #'magit-discard
+                         '(:enable (not (memq (magit-diff-type)
+                                              '(committed undefined)))))
+  "<3>" (magit-menu-item "Unstage %x" #'magit-unstage
+                         '(:enable (eq (magit-diff-type) 'staged)))
+  "<2>" (magit-menu-item "Stage %x"   #'magit-stage
+                         '(:enable (eq (magit-diff-type) 'unstaged)))
+  "<1>" (magit-menu-item "Apply %x" #'magit-apply
+                         '(:enable (not (memq (magit-diff-type)
+                                              '(unstaged staged))))))
 
 (defvar-keymap magit-file-section-map
   :doc "Keymap for `file' sections."
   :parent magit-diff-section-base-map)
 
-(defvar magit-hunk-section-map
-  (let ((map (make-sparse-keymap)))
-    (set-keymap-parent map magit-diff-section-base-map)
-    (let ((m (make-sparse-keymap)))
-      (keymap-set m "RET" #'magit-smerge-keep-current)
-      (keymap-set m "u"   #'magit-smerge-keep-upper)
-      (keymap-set m "b"   #'magit-smerge-keep-base)
-      (keymap-set m "l"   #'magit-smerge-keep-lower)
-      (define-key map smerge-command-prefix m))
-    map)
-  "Keymap for `hunk' sections.")
+(defvar-keymap magit-hunk-section-map
+  :doc "Keymap for `hunk' sections."
+  :parent magit-diff-section-base-map
+  "C-c ^ RET" #'magit-smerge-keep-current
+  "C-c ^ u"   #'magit-smerge-keep-upper
+  "C-c ^ b"   #'magit-smerge-keep-base
+  "C-c ^ l"   #'magit-smerge-keep-lower)
 
 (defconst magit-diff-conflict-headline-re
   (concat "^" (regexp-opt
@@ -2575,12 +2574,11 @@ or a ref which is not a branch, then it inserts 
nothing."
         (goto-char (point-max)))
       (insert ?\n))))
 
-(defvar magit-commit-message-section-map
-  (let ((map (make-sparse-keymap)))
-    (magit-menu-set map [magit-visit-thing] #'magit-show-commit "Visit %t"
-      '(:enable (magit-thing-at-point 'git-revision t)))
-    map)
-  "Keymap for `commit-message' sections.")
+(defvar-keymap magit-commit-message-section-map
+  :doc "Keymap for `commit-message' sections."
+  "<remap> <magit-visit-thing>"  #'magit-show-commit
+  "<1>" (magit-menu-item "Visit %t" #'magit-show-commit
+                         '(:enable (magit-thing-at-point 'git-revision t))))
 
 (defun magit-insert-revision-message ()
   "Insert the commit message into a revision buffer."
@@ -2899,13 +2897,14 @@ It the SECTION has a different type, then do nothing."
 
 ;;; Diff Sections
 
-(defvar magit-unstaged-section-map
-  (let ((map (make-sparse-keymap)))
-    (magit-menu-set map [magit-visit-thing]  #'magit-diff-unstaged "Visit 
diff")
-    (magit-menu-set map [magit-stage-file]   #'magit-stage         "Stage all")
-    (magit-menu-set map [magit-delete-thing] #'magit-discard       "Discard 
all")
-    map)
-  "Keymap for the `unstaged' section.")
+(defvar-keymap magit-unstaged-section-map
+  :doc "Keymap for the `unstaged' section."
+  "<remap> <magit-visit-thing>"  #'magit-diff-unstaged
+  "<remap> <magit-stage-file>"   #'magit-stage
+  "<remap> <magit-delete-thing>" #'magit-discard
+  "<3>" (magit-menu-item "Discard all" #'magit-discard)
+  "<2>" (magit-menu-item "Stage all"   #'magit-stage)
+  "<1>" (magit-menu-item "Visit diff"  #'magit-diff-unstaged))
 
 (magit-define-section-jumper magit-jump-to-unstaged "Unstaged changes" 
unstaged)
 
@@ -2917,14 +2916,16 @@ It the SECTION has a different type, then do nothing."
       "diff" magit-buffer-diff-args "--no-prefix"
       "--" magit-buffer-diff-files)))
 
-(defvar magit-staged-section-map
-  (let ((map (make-sparse-keymap)))
-    (magit-menu-set map [magit-visit-thing]  #'magit-diff-staged "Visit diff")
-    (magit-menu-set map [magit-unstage-file]     #'magit-unstage "Unstage all")
-    (magit-menu-set map [magit-delete-thing]     #'magit-discard "Discard all")
-    (magit-menu-set map [magit-revert-no-commit] #'magit-reverse "Reverse all")
-    map)
-  "Keymap for the `staged' section.")
+(defvar-keymap magit-staged-section-map
+  :doc "Keymap for the `staged' section."
+  "<remap> <magit-revert-no-commit>" #'magit-reverse
+  "<remap> <magit-delete-thing>"     #'magit-discard
+  "<remap> <magit-unstage-file>"     #'magit-unstage
+  "<remap> <magit-visit-thing>"      #'magit-diff-staged
+  "<4>" (magit-menu-item "Reverse all" #'magit-reverse)
+  "<3>" (magit-menu-item "Discard all" #'magit-discard)
+  "<2>" (magit-menu-item "Unstage all" #'magit-unstage)
+  "<1>" (magit-menu-item "Visit diff"  #'magit-diff-staged))
 
 (magit-define-section-jumper magit-jump-to-staged "Staged changes" staged)
 
diff --git a/lisp/magit-log.el b/lisp/magit-log.el
index c0d75ebc18..901a299e0c 100644
--- a/lisp/magit-log.el
+++ b/lisp/magit-log.el
@@ -1150,20 +1150,15 @@ Do not add this to a hook variable."
   (or (magit-diff--region-range)
       (oref (magit-current-section) value)))
 
-(defvar magit-commit-section-map
-  (let ((map (make-sparse-keymap)))
-    ;; The second remapping overrides the first but we still get two menu
-    ;; items, though only one of them will be available at any given time.
-    (magit-menu-set map [magit-visit-thing]
-      #'magit-diff-range   "Diff %x"
-      '(:visible (region-active-p)))
-    (magit-menu-set map [magit-visit-thing]
-      #'magit-show-commit  "Show commit %x"
-      '(:visible (not (region-active-p))))
-    (magit-menu-set map [magit-cherry-apply]
-      #'magit-cherry-apply "Apply %x")
-    map)
-  "Keymap for `commit' sections.")
+
+(defvar-keymap magit-commit-section-map
+  :doc "Keymap for `commit' sections."
+  "<remap> <magit-visit-thing>" #'magit-show-commit
+  "<3>" (magit-menu-item "Apply %x" #'magit-cherry-apply)
+  "<2>" (magit-menu-item "Show commit %x" #'magit-show-commit
+                         '(:visible (not (region-active-p))))
+  "<1>" (magit-menu-item "Diff %x" #'magit-diff-range
+                         '(:visible (region-active-p))))
 
 (defvar-keymap magit-module-commit-section-map
   :doc "Keymap for `module-commit' sections."
@@ -1762,14 +1757,13 @@ Type \\[magit-cherry-pick] to apply the commit at point.
 ;;; Log Sections
 ;;;; Standard Log Sections
 
-(defvar magit-log-section-map
-  (let ((map (make-sparse-keymap)))
-    (magit-menu-set map [magit-visit-thing] #'magit-diff-dwim "Visit diff")
-    map)
-  "Keymap for log sections.
+(defvar-keymap magit-log-section-map
+  :doc "Keymap for log sections.
 The classes `magit-{unpulled,unpushed,unmerged}-section' derive
 from the abstract `magit-log-section' class.  Accordingly this
-keymap is the parent of their keymaps.")
+keymap is the parent of their keymaps."
+  "<remap> <magit-visit-thing>" #'magit-diff-dwim
+  "<1>" (magit-menu-item "Visit diff" #'magit-diff-dwim))
 
 (defvar-keymap magit-unpulled-section-map
   :doc "Keymap for `unpulled' sections."
diff --git a/lisp/magit-refs.el b/lisp/magit-refs.el
index cddc05d40d..e02317db96 100644
--- a/lisp/magit-refs.el
+++ b/lisp/magit-refs.el
@@ -471,27 +471,28 @@ Branch %s already exists.
 
 ;;; Sections
 
-(defvar magit-remote-section-map
-  (let ((map (make-sparse-keymap)))
-    (magit-menu-set map [magit-delete-thing] #'magit-remote-remove "Remove %m")
-    (magit-menu-set map [magit-file-rename]  #'magit-remote-rename "Rename %s")
-    map)
-  "Keymap for `remote' sections.")
-
-(defvar magit-branch-section-map
-  (let ((map (make-sparse-keymap)))
-    (magit-menu-set map [magit-visit-thing]  #'magit-visit-ref     "Visit 
commit")
-    (magit-menu-set map [magit-delete-thing] #'magit-branch-delete "Delete %m")
-    (magit-menu-set map [magit-file-rename]  #'magit-branch-rename "Rename %s")
-    map)
-  "Keymap for `branch' sections.")
-
-(defvar magit-tag-section-map
-  (let ((map (make-sparse-keymap)))
-    (magit-menu-set map [magit-visit-thing]  #'magit-visit-ref  "Visit %s")
-    (magit-menu-set map [magit-delete-thing] #'magit-tag-delete "Delete %m")
-    map)
-  "Keymap for `tag' sections.")
+(defvar-keymap magit-remote-section-map
+  :doc "Keymap for `remote' sections."
+  "<remap> <magit-file-rename>"  #'magit-remote-rename
+  "<remap> <magit-delete-thing>" #'magit-remote-remove
+  "<2>" (magit-menu-item "Rename %s" #'magit-remote-rename)
+  "<1>" (magit-menu-item "Remove %m" #'magit-remote-remove))
+
+(defvar-keymap magit-branch-section-map
+  :doc "Keymap for `branch' sections."
+  "<remap> <magit-file-rename>"  #'magit-branch-rename
+  "<remap> <magit-delete-thing>" #'magit-branch-delete
+  "<remap> <magit-visit-thing>"  #'magit-visit-ref
+  "<3>" (magit-menu-item "Rename %s"    #'magit-branch-rename)
+  "<2>" (magit-menu-item "Delete %m"    #'magit-branch-delete)
+  "<1>" (magit-menu-item "Visit commit" #'magit-visit-ref))
+
+(defvar-keymap magit-tag-section-map
+  :doc "Keymap for `tag' sections."
+  "<remap> <magit-delete-thing>" #'magit-tag-delete
+  "<remap> <magit-visit-thing>"  #'magit-visit-ref
+  "<2>" (magit-menu-item "Delete %m" #'magit-tag-delete)
+  "<1>" (magit-menu-item "Visit %s"  #'magit-visit-ref))
 
 (defun magit--painted-branch-as-menu-section (section)
   (and-let* ((branch (and (magit-section-match 'commit)
diff --git a/lisp/magit-section.el b/lisp/magit-section.el
index 073ed6d7f5..a6789d992b 100644
--- a/lisp/magit-section.el
+++ b/lisp/magit-section.el
@@ -599,55 +599,33 @@ The return value has the form (TYPE...)."
                     (magit--menu-bar-keymap map)))))
   menu)
 
-(defun magit-menu-set (keymap key def desc &optional props after)
-  "In KEYMAP, define KEY and a menu entry for DEF.
-
-Add the menu item (menu-item DESC DEF . PROPS) at the end of
-KEYMAP, or if optional AFTER is non-nil, then after that.
-
-Because it is so common, and would otherwise result in overlong
-lines or else unsightly line wrapping, a definition [remap CMD]
-can be written as just [CMD].  As a result KEY might have to be
-a string when otherwise a vector would have worked.
-
-If DESC is a string that contains a supported %-spec, substitute
-the expression (magit-menu-format-desc DESC) for that.  See
-`magit-menu-format-desc'."
-  (declare (indent defun))
-  (when (vectorp key)
-    ;; Expand the short-hand.
-    (unless (eq (aref key 0) 'remap)
-      (setq key (vconcat [remap] key)))
-    ;; The default binding is RET, but in my configuration it
-    ;; is <return>.  In that case the displayed binding would
-    ;; be <CMD> instead of <return>, for unknown reasons. The
-    ;; same does not happen for similar events, such as <tab>.
-    (when (and (equal key [remap magit-visit-thing])
-               (boundp 'magit-mode-map)
-               (ignore-errors (eq (lookup-key magit-mode-map [return])
-                                  'magit-visit-thing)))
-      (setq key [return]))
-    ;; `define-key-after' cannot deal with [remap CMD],
-    ;; so we have to add the key binding separately.
-    (define-key keymap key def)
-    (unless (symbolp def)
-      (error "When KEY is a remapping, then DEF must be a symbol: %s" def))
-    (setq key (vector def)))
-  (when (and (stringp desc) (string-match-p "%[tTvsmMx]" desc))
-    (setq desc (list 'magit-menu-format-desc desc)))
-  (define-key-after keymap key
-    `( menu-item ,desc ,def ,@props
-       ;; Without this, the keys for point would be shown instead
-       ;; of the relevant ones from where the click occurred.
-       ,@(and (not (region-active-p))
-              (list :keys
-                    (lambda ()
-                      (or (ignore-errors
-                            (save-excursion
-                              (goto-char (magit-menu-position))
-                              (key-description (where-is-internal def nil t))))
-                          "")))))
-    after))
+(defun magit-menu-item (desc def &optional props)
+  "Return a menu item named DESC binding DEF and using PROPS.
+
+If DESC contains a supported %-spec, substitute the
+expression (magit-menu-format-desc DESC) for that.
+See `magit-menu-format-desc'."
+  `(menu-item
+    ,(if (and (stringp desc) (string-match-p "%[tTvsmMx]" desc))
+         (list 'magit-menu-format-desc desc)
+       desc)
+    ,def
+    ;; Without this, the keys for point would be shown instead
+    ;; of the relevant ones from where the click occurred.
+    :keys ,(apply-partially #'magit--menu-position-keys def)
+    ,@props))
+
+(defun magit--menu-position-keys (def)
+  (or (ignore-errors
+        (save-excursion
+          (goto-char (magit-menu-position))
+          (and-let* ((key (cl-find-if-not
+                           (lambda (key)
+                             (string-match-p "\\`<[0-9]+>\\'"
+                                             (key-description key)))
+                           (where-is-internal def))))
+            (key-description key))))
+      ""))
 
 (defun magit-menu-position ()
   "Return the position where the context-menu was invoked.
diff --git a/lisp/magit-stash.el b/lisp/magit-stash.el
index abb4bd0248..b6b3ab3937 100644
--- a/lisp/magit-stash.el
+++ b/lisp/magit-stash.el
@@ -373,21 +373,23 @@ current branch or `HEAD' as the start-point."
 
 ;;; Sections
 
-(defvar magit-stashes-section-map
-  (let ((map (make-sparse-keymap)))
-    (magit-menu-set map [magit-visit-thing]  #'magit-stash-list  "List %t")
-    (magit-menu-set map [magit-delete-thing] #'magit-stash-clear "Clear %t")
-    map)
-  "Keymap for `stashes' section.")
-
-(defvar magit-stash-section-map
-  (let ((map (make-sparse-keymap)))
-    (magit-menu-set map [magit-visit-thing]  #'magit-stash-show  "Visit %v")
-    (magit-menu-set map [magit-delete-thing] #'magit-stash-drop  "Delete %M")
-    (magit-menu-set map [magit-cherry-apply] #'magit-stash-apply "Apply %M")
-    (magit-menu-set map [magit-cherry-pick]  #'magit-stash-pop   "Pop %M")
-    map)
-  "Keymap for `stash' sections.")
+(defvar-keymap magit-stashes-section-map
+  :doc "Keymap for `stashes' section."
+  "<remap> <magit-delete-thing>" #'magit-stash-clear
+  "<remap> <magit-visit-thing>"  #'magit-stash-list
+  "<2>" (magit-menu-item "Clear %t" #'magit-stash-clear)
+  "<1>" (magit-menu-item "List %t"  #'magit-stash-list))
+
+(defvar-keymap magit-stash-section-map
+  :doc "Keymap for `stash' sections."
+  "<remap> <magit-cherry-pick>"  #'magit-stash-pop
+  "<remap> <magit-cherry-apply>" #'magit-stash-apply
+  "<remap> <magit-delete-thing>" #'magit-stash-drop
+  "<remap> <magit-visit-thing>"  #'magit-stash-show
+  "<4>" (magit-menu-item "Pop %M"    #'magit-stash-pop)
+  "<3>" (magit-menu-item "Apply %M"  #'magit-stash-apply)
+  "<2>" (magit-menu-item "Delete %M" #'magit-stash-drop)
+  "<1>" (magit-menu-item "Visit %v"  #'magit-stash-show))
 
 (magit-define-section-jumper magit-jump-to-stashes
   "Stashes" stashes "refs/stash")
diff --git a/lisp/magit-status.el b/lisp/magit-status.el
index ee8e2d6fd1..8b6a6bd837 100644
--- a/lisp/magit-status.el
+++ b/lisp/magit-status.el
@@ -496,12 +496,10 @@ The sections are inserted by running the functions on the 
hook
       (magit-insert-headers 'magit-status-headers-hook)
     (insert "In the beginning there was darkness\n\n")))
 
-(defvar magit-error-section-map
-  (let ((map (make-sparse-keymap)))
-    (magit-menu-set map [magit-visit-thing]
-      #'magit-process-buffer "Visit process output")
-    map)
-  "Keymap for `error' sections.")
+(defvar-keymap magit-error-section-map
+  :doc "Keymap for `error' sections."
+  "<remap> <magit-visit-thing>" #'magit-process-buffer
+  "<1>" (magit-menu-item "Visit process output" #'magit-process-buffer))
 
 (defun magit-insert-error-header ()
   "Insert the message about the Git error that just occurred.
@@ -699,12 +697,12 @@ remote in alphabetic order."
 
 ;;;; File Sections
 
-(defvar magit-untracked-section-map
-  (let ((map (make-sparse-keymap)))
-    (magit-menu-set map [magit-stage-file]   #'magit-stage   "Stage files")
-    (magit-menu-set map [magit-delete-thing] #'magit-discard "Discard files")
-    map)
-  "Keymap for the `untracked' section.")
+(defvar-keymap magit-untracked-section-map
+  :doc "Keymap for the `untracked' section."
+  "<remap> <magit-delete-thing>" #'magit-discard
+  "<remap> <magit-stage-file>"   #'magit-stage
+  "<2>" (magit-menu-item "Discard files" #'magit-discard)
+  "<1>" (magit-menu-item "Stage files"   #'magit-stage))
 
 (magit-define-section-jumper magit-jump-to-untracked "Untracked files" 
untracked)
 
diff --git a/lisp/magit-submodule.el b/lisp/magit-submodule.el
index 8f7ccd41c1..08facb568d 100644
--- a/lisp/magit-submodule.el
+++ b/lisp/magit-submodule.el
@@ -507,29 +507,25 @@ or, failing that, the abbreviated HEAD commit hash."
             (insert ?\n))))))
   (insert ?\n))
 
-(defvar magit-modules-section-map
-  (let ((map (make-sparse-keymap)))
-    (magit-menu-set map [magit-visit-thing]
-      #'magit-list-submodules "List %t")
-    map)
-  "Keymap for `modules' sections.")
-
-(defvar magit-module-section-map
-  (let ((map (make-sparse-keymap)))
-    (keymap-set map "C-j" #'magit-submodule-visit)
-    (keymap-set map "C-<return>" #'magit-submodule-visit)
-    (magit-menu-set map [magit-visit-thing]
-      #'magit-submodule-visit "Visit %s")
-    (magit-menu-set map [magit-stage-file]
-      #'magit-stage "Stage %T"
-      '(:visible (eq (magit-diff-type) 'unstaged)))
-    (magit-menu-set map [magit-unstage-file]
-      #'magit-unstage "Unstage %T"
-      '(:visible (eq (magit-diff-type) 'staged)))
-    (define-key-after map [separator-magit-submodule] menu-bar-separator)
-    (magit-menu-set map [magit-submodule] #'magit-submodule "Module 
commands...")
-    map)
-  "Keymap for `module' sections.")
+(defvar-keymap magit-modules-section-map
+  :doc "Keymap for `modules' sections."
+  "<remap> <magit-visit-thing>" #'magit-list-submodules
+  "<1>" (magit-menu-item "List %t" #'magit-list-submodules))
+
+(defvar-keymap magit-module-section-map
+  :doc "Keymap for `module' sections."
+  "C-j"        #'magit-submodule-visit
+  "C-<return>" #'magit-submodule-visit
+  "<remap> <magit-unstage-file>" #'magit-unstage
+  "<remap> <magit-stage-file>"   #'magit-stage
+  "<remap> <magit-visit-thing>"  #'magit-submodule-visit
+  "<5>" (magit-menu-item "Module commands..." #'magit-submodule)
+  "<4>" '(menu-item "--")
+  "<3>" (magit-menu-item "Unstage %T" #'magit-unstage
+                         '(:visible (eq (magit-diff-type) 'staged)))
+  "<2>" (magit-menu-item "Stage %T" #'magit-stage
+                         '(:visible (eq (magit-diff-type) 'unstaged)))
+  "<1>" (magit-menu-item "Visit %s" #'magit-submodule-visit))
 
 (defun magit-submodule-visit (module &optional other-window)
   "Visit MODULE by calling `magit-status' on it.
diff --git a/lisp/magit-worktree.el b/lisp/magit-worktree.el
index b955e07681..135e821580 100644
--- a/lisp/magit-worktree.el
+++ b/lisp/magit-worktree.el
@@ -145,14 +145,14 @@ then show it in Dired instead."
 
 ;;; Sections
 
-(defvar magit-worktree-section-map
-  (let ((map (make-sparse-keymap)))
-    (magit-menu-set map [magit-visit-thing]  #'magit-worktree-status "Visit 
%s")
-    (magit-menu-set map [magit-delete-thing] #'magit-worktree-delete "Delete 
%m")
-    (define-key-after map [separator-magit-worktree] menu-bar-separator)
-    (magit-menu-set map [magit-worktree] #'magit-worktree "Worktree 
commands...")
-    map)
-  "Keymap for `worktree' sections.")
+(defvar-keymap magit-worktree-section-map
+  :doc "Keymap for `worktree' sections."
+  "<remap> <magit-delete-thing>" #'magit-worktree-delete
+  "<remap> <magit-visit-thing>"  #'magit-worktree-status
+  "<4>" (magit-menu-item "Worktree commands..." #'magit-worktree)
+  "<3>" '(menu-item "--")
+  "<2>" (magit-menu-item "Delete %m" #'magit-worktree-delete)
+  "<1>" (magit-menu-item "Visit %s" #'magit-worktree-status))
 
 (defun magit-insert-worktrees ()
   "Insert sections for all worktrees.

Reply via email to