emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/git-commit 38cb9372dc 17/18: Add section-specific context-


From: ELPA Syncer
Subject: [nongnu] elpa/git-commit 38cb9372dc 17/18: Add section-specific context-menus
Date: Fri, 25 Mar 2022 13:58:20 -0400 (EDT)

branch: elpa/git-commit
commit 38cb9372dc51df4767b30181db93f51f7ac856ab
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Jonas Bernoulli <jonas@bernoul.li>

    Add section-specific context-menus
---
 lisp/magit-diff.el      | 59 ++++++++++++++++++++++++++++++++++++-------------
 lisp/magit-log.el       | 18 +++++++++++++--
 lisp/magit-refs.el      | 20 +++++++++--------
 lisp/magit-stash.el     | 12 +++++-----
 lisp/magit-status.el    |  7 +++---
 lisp/magit-submodule.el | 18 ++++++++++-----
 lisp/magit-worktree.el  |  6 +++--
 7 files changed, 97 insertions(+), 43 deletions(-)

diff --git a/lisp/magit-diff.el b/lisp/magit-diff.el
index 793a760527..71532cafd8 100644
--- a/lisp/magit-diff.el
+++ b/lisp/magit-diff.el
@@ -64,6 +64,14 @@
 (declare-function forge--pullreq-ref "forge-pullreq" (pullreq))
 ;; For `magit-diff-wash-diff'
 (declare-function ansi-color-apply-on-region "ansi-color")
+;; For keymaps and menus
+(declare-function magit-apply "magit-apply" (&rest args))
+(declare-function magit-stage "magit-apply" (&optional indent))
+(declare-function magit-unstage "magit-apply" ())
+(declare-function magit-discard "magit-apply" ())
+(declare-function magit-reverse "magit-apply" (&rest args))
+(declare-function magit-file-rename "magit-files" (file newname))
+(declare-function magit-file-untrack "magit-files" (files &optional force))
 
 (eval-when-compile
   (cl-pushnew 'orig-rev eieio--known-slot-names)
@@ -1947,21 +1955,41 @@ Staging and applying changes is documented in info node
                 (list 'unstaged magit-buffer-typearg)))
          (and magit-buffer-diff-files (cons "--" magit-buffer-diff-files))))
 
+(cl-defmethod magit-menu-common-value ((_section magit-diff-section))
+  (magit-diff-scope))
+
 (define-obsolete-variable-alias 'magit-diff-section-base-map
   'magit-diff-section-map "Magit-Section 3.4.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)))
     (define-key map (kbd "C-j")            'magit-diff-visit-worktree-file)
     (define-key map (kbd "C-<return>")     'magit-diff-visit-worktree-file)
     (define-key map (kbd "C-x 4 <return>") 'magit-diff-visit-file-other-window)
     (define-key map (kbd "C-x 5 <return>") 'magit-diff-visit-file-other-frame)
-    (define-key map [remap magit-visit-thing]      'magit-diff-visit-file)
-    (define-key map [remap magit-delete-thing]     'magit-discard)
-    (define-key map [remap magit-revert-no-commit] 'magit-reverse)
-    (define-key map "a" 'magit-apply)
-    (define-key map "s" 'magit-stage)
-    (define-key map "u" 'magit-unstage)
-    (define-key map "&" 'magit-do-async-shell-command)
+    (define-key map "&"             'magit-do-async-shell-command)
     (define-key map "C"             'magit-commit-add-log)
     (define-key map (kbd "C-x a")   'magit-add-change-log-entry)
     (define-key map (kbd "C-x 4 a") 'magit-add-change-log-entry-other-window)
@@ -2519,7 +2547,8 @@ or a ref which is not a branch, then it inserts nothing."
 
 (defvar magit-commit-message-section-map
   (let ((map (make-sparse-keymap)))
-    (define-key map [remap magit-visit-thing] 'magit-show-commit)
+    (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.")
 
@@ -2823,9 +2852,9 @@ It the SECTION has a different type, then do nothing."
 
 (defvar magit-unstaged-section-map
   (let ((map (make-sparse-keymap)))
-    (define-key map [remap magit-visit-thing]  'magit-diff-unstaged)
-    (define-key map [remap magit-stage-file]   'magit-stage)
-    (define-key map [remap magit-delete-thing] 'magit-discard)
+    (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.")
 
@@ -2841,10 +2870,10 @@ It the SECTION has a different type, then do nothing."
 
 (defvar magit-staged-section-map
   (let ((map (make-sparse-keymap)))
-    (define-key map [remap magit-visit-thing]      'magit-diff-staged)
-    (define-key map [remap magit-unstage-file]     'magit-unstage)
-    (define-key map [remap magit-delete-thing]     'magit-discard)
-    (define-key map [remap magit-revert-no-commit] 'magit-reverse)
+    (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.")
 
diff --git a/lisp/magit-log.el b/lisp/magit-log.el
index a3fb5c28bb..e161d38515 100644
--- a/lisp/magit-log.el
+++ b/lisp/magit-log.el
@@ -35,6 +35,7 @@
 (require 'magit-diff)
 
 (declare-function magit-blob-visit "magit-files" (blob-or-file))
+(declare-function magit-cherry-apply "magit-sequence" (commit &optional args))
 (declare-function magit-insert-head-branch-header "magit-status"
                   (&optional branch))
 (declare-function magit-insert-upstream-branch-header "magit-status"
@@ -1139,9 +1140,22 @@ Do not add this to a hook variable."
         args)
       "--use-mailmap" "--no-prefix" revs "--" files)))
 
+(cl-defmethod magit-menu-common-value ((_section magit-commit-section))
+  (or (magit-diff--region-range)
+      (oref (magit-current-section) value)))
+
 (defvar magit-commit-section-map
   (let ((map (make-sparse-keymap)))
-    (define-key map [remap magit-visit-thing] 'magit-show-commit)
+    ;; 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.")
 
@@ -1747,7 +1761,7 @@ Type \\[magit-cherry-pick] to apply the commit at point.
 
 (defvar magit-log-section-map
   (let ((map (make-sparse-keymap)))
-    (define-key map [remap magit-visit-thing] 'magit-diff-dwim)
+    (magit-menu-set map [magit-visit-thing] #'magit-diff-dwim "Visit diff")
     map)
   "Keymap for log sections.
 The classes `magit-{unpulled,unpushed,unmerged}-section' derive
diff --git a/lisp/magit-refs.el b/lisp/magit-refs.el
index 1264564688..f7abc98809 100644
--- a/lisp/magit-refs.el
+++ b/lisp/magit-refs.el
@@ -429,10 +429,12 @@ This command behaves just like `magit-show-commit', 
except if
 point is on a reference in a `magit-refs-mode' buffer (a buffer
 listing branches and tags), in which case the behavior may be
 different, but only if you have customized the option
-`magit-visit-ref-behavior' (which see)."
+`magit-visit-ref-behavior' (which see).  When invoked from a
+menu this command always behaves like `magit-show-commit'."
   (interactive)
   (if (and (derived-mode-p 'magit-refs-mode)
-           (magit-section-match '(branch tag)))
+           (magit-section-match '(branch tag))
+           (magit-menu-position))
       (let ((ref (oref (magit-current-section) value)))
         (cond (current-prefix-arg
                (cond ((memq 'focus-on-ref magit-visit-ref-behavior)
@@ -476,23 +478,23 @@ Branch %s already exists.
 
 (defvar magit-remote-section-map
   (let ((map (make-sparse-keymap)))
-    (define-key map [remap magit-delete-thing] 'magit-remote-remove)
-    (define-key map [remap magit-file-rename]  'magit-remote-rename)
+    (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)))
-    (define-key map [remap magit-visit-thing]  'magit-visit-ref)
-    (define-key map [remap magit-delete-thing] 'magit-branch-delete)
-    (define-key map [remap magit-file-rename]  'magit-branch-rename)
+    (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)))
-    (define-key map [remap magit-visit-thing]  'magit-visit-ref)
-    (define-key map [remap magit-delete-thing] 'magit-tag-delete)
+    (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.")
 
diff --git a/lisp/magit-stash.el b/lisp/magit-stash.el
index 5de5ffce95..09b25865d2 100644
--- a/lisp/magit-stash.el
+++ b/lisp/magit-stash.el
@@ -377,17 +377,17 @@ current branch or `HEAD' as the start-point."
 
 (defvar magit-stashes-section-map
   (let ((map (make-sparse-keymap)))
-    (define-key map [remap magit-visit-thing]  'magit-stash-list)
-    (define-key map [remap magit-delete-thing] 'magit-stash-clear)
+    (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)))
-    (define-key map [remap magit-visit-thing]  'magit-stash-show)
-    (define-key map [remap magit-delete-thing] 'magit-stash-drop)
-    (define-key map [remap magit-cherry-apply] 'magit-stash-apply)
-    (define-key map [remap magit-cherry-pick]  'magit-stash-pop)
+    (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.")
 
diff --git a/lisp/magit-status.el b/lisp/magit-status.el
index 6b950ee564..c9a0850a20 100644
--- a/lisp/magit-status.el
+++ b/lisp/magit-status.el
@@ -512,7 +512,8 @@ The sections are inserted by running the functions on the 
hook
 
 (defvar magit-error-section-map
   (let ((map (make-sparse-keymap)))
-    (define-key map [remap magit-visit-thing] 'magit-process-buffer)
+    (magit-menu-set map [magit-visit-thing]
+      #'magit-process-buffer "Visit process output")
     map)
   "Keymap for `error' sections.")
 
@@ -715,8 +716,8 @@ remote in alphabetic order."
 
 (defvar magit-untracked-section-map
   (let ((map (make-sparse-keymap)))
-    (define-key map [remap magit-stage-file]   'magit-stage)
-    (define-key map [remap magit-delete-thing] 'magit-discard)
+    (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.")
 
diff --git a/lisp/magit-submodule.el b/lisp/magit-submodule.el
index 5dbe15685c..fed35475ea 100644
--- a/lisp/magit-submodule.el
+++ b/lisp/magit-submodule.el
@@ -510,19 +510,25 @@ or, failing that, the abbreviated HEAD commit hash."
 
 (defvar magit-modules-section-map
   (let ((map (make-sparse-keymap)))
-    (define-key map [remap magit-visit-thing] 'magit-list-submodules)
+    (magit-menu-set map [remap magit-visit-thing]
+      #'magit-list-submodules "List %t")
     map)
   "Keymap for `modules' sections.")
 
 (defvar magit-module-section-map
   (let ((map (make-sparse-keymap)))
-    (set-keymap-parent map magit-file-section-map)
     (define-key map (kbd "C-j") 'magit-submodule-visit)
     (define-key map [C-return]  'magit-submodule-visit)
-    (define-key map [remap magit-visit-thing]  'magit-submodule-visit)
-    (define-key map [remap magit-delete-thing] 'magit-submodule-unpopulate)
-    (define-key map "K" 'magit-file-untrack)
-    (define-key map "R" 'magit-file-rename)
+    (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.")
 
diff --git a/lisp/magit-worktree.el b/lisp/magit-worktree.el
index 3e176e35e5..e42e16921b 100644
--- a/lisp/magit-worktree.el
+++ b/lisp/magit-worktree.el
@@ -150,8 +150,10 @@ then show it in Dired instead."
 
 (defvar magit-worktree-section-map
   (let ((map (make-sparse-keymap)))
-    (define-key map [remap magit-visit-thing]  'magit-worktree-status)
-    (define-key map [remap magit-delete-thing] 'magit-worktree-delete)
+    (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.")
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]