branch: elpa/git-commit commit 70b34f08ab5dc8bb7a0fb71bbf5d8cab7f8a47c4 Author: Jonas Bernoulli <jo...@bernoul.li> Commit: Jonas Bernoulli <jo...@bernoul.li>
Increase use of section type, keymap and binding inheritance --- lisp/magit-base.el | 21 ++++++++++++++++----- lisp/magit-diff.el | 15 +++++++++------ lisp/magit-log.el | 16 ++++++++++++---- lisp/magit-merge.el | 2 +- lisp/magit-refs.el | 4 ++-- lisp/magit-stash.el | 4 ++-- lisp/magit-status.el | 2 +- 7 files changed, 43 insertions(+), 21 deletions(-) diff --git a/lisp/magit-base.el b/lisp/magit-base.el index 78c7ac8030..3ec5afd461 100644 --- a/lisp/magit-base.el +++ b/lisp/magit-base.el @@ -439,10 +439,13 @@ and delay of your graphical environment or operating system." ;;; Section Classes -(defclass magit-commit-section (magit-section) - ()) +(defclass magit-commit-section (magit-section) ()) -(defclass magit-file-section (magit-section) +(setf (alist-get 'commit magit--section-type-alist) 'magit-commit-section) + +(defclass magit-diff-section (magit-section) () :abstract t) + +(defclass magit-file-section (magit-diff-section) ((keymap :initform 'magit-file-section-map) (source :initform nil) (header :initform nil))) @@ -451,7 +454,7 @@ and delay of your graphical environment or operating system." ((keymap :initform 'magit-module-section-map) (range :initform nil))) -(defclass magit-hunk-section (magit-section) +(defclass magit-hunk-section (magit-diff-section) ((keymap :initform 'magit-hunk-section-map) (refined :initform nil) (combined :initform nil) @@ -460,11 +463,19 @@ and delay of your graphical environment or operating system." (to-range :initform nil) (about :initform nil))) -(setf (alist-get 'commit magit--section-type-alist) 'magit-commit-section) (setf (alist-get 'file magit--section-type-alist) 'magit-file-section) (setf (alist-get 'module magit--section-type-alist) 'magit-module-section) (setf (alist-get 'hunk magit--section-type-alist) 'magit-hunk-section) +(defclass magit-log-section (magit-section) () :abstract t) +(defclass magit-unpulled-section (magit-log-section) ()) +(defclass magit-unpushed-section (magit-log-section) ()) +(defclass magit-unmerged-section (magit-log-section) ()) + +(setf (alist-get 'unpulled magit--section-type-alist) 'magit-unpulled-section) +(setf (alist-get 'unpushed magit--section-type-alist) 'magit-unpushed-section) +(setf (alist-get 'unmerged magit--section-type-alist) 'magit-unmerged-section) + ;;; User Input (defvar helm-completion-in-region-default-sort-fn) diff --git a/lisp/magit-diff.el b/lisp/magit-diff.el index dd384e870c..7c78424bff 100644 --- a/lisp/magit-diff.el +++ b/lisp/magit-diff.el @@ -1942,7 +1942,9 @@ Staging and applying changes is documented in info node (list 'unstaged magit-buffer-typearg))) (and magit-buffer-diff-files (cons "--" magit-buffer-diff-files)))) -(defvar magit-diff-section-base-map +(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))) (define-key map (kbd "C-j") 'magit-diff-visit-worktree-file) (define-key map (kbd "C-<return>") 'magit-diff-visit-worktree-file) @@ -1961,7 +1963,10 @@ Staging and applying changes is documented in info node (define-key map (kbd "C-c C-t") 'magit-diff-trace-definition) (define-key map (kbd "C-c C-e") 'magit-diff-edit-hunk-commit) map) - "Parent of `magit-{hunk,file}-section-map'.") + "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.") (defvar magit-file-section-map (let ((map (make-sparse-keymap))) @@ -2814,9 +2819,8 @@ 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) - (define-key map "s" 'magit-stage) - (define-key map "u" 'magit-unstage) map) "Keymap for the `unstaged' section.") @@ -2833,10 +2837,9 @@ 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) - (define-key map "s" 'magit-stage) - (define-key map "u" 'magit-unstage) map) "Keymap for the `staged' section.") diff --git a/lisp/magit-log.el b/lisp/magit-log.el index 32b8e38d92..0558b681a4 100644 --- a/lisp/magit-log.el +++ b/lisp/magit-log.el @@ -1142,13 +1142,12 @@ Do not add this to a hook variable." (defvar magit-commit-section-map (let ((map (make-sparse-keymap))) (define-key map [remap magit-visit-thing] 'magit-show-commit) - (define-key map "a" 'magit-cherry-apply) map) "Keymap for `commit' sections.") (defvar magit-module-commit-section-map (let ((map (make-sparse-keymap))) - (define-key map [remap magit-visit-thing] 'magit-show-commit) + (set-keymap-parent map magit-commit-section-map) map) "Keymap for `module-commit' sections.") @@ -1746,10 +1745,19 @@ Type \\[magit-cherry-pick] to apply the commit at point. ;;; Log Sections ;;;; Standard Log Sections -(defvar magit-unpulled-section-map +(defvar magit-log-section-map (let ((map (make-sparse-keymap))) (define-key map [remap magit-visit-thing] 'magit-diff-dwim) map) + "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.") + +(defvar magit-unpulled-section-map + (let ((map (make-sparse-keymap))) + (set-keymap-parent map magit-log-section-map) + map) "Keymap for `unpulled' sections.") (magit-define-section-jumper magit-jump-to-unpulled-from-upstream @@ -1784,7 +1792,7 @@ Type \\[magit-cherry-pick] to apply the commit at point. (defvar magit-unpushed-section-map (let ((map (make-sparse-keymap))) - (define-key map [remap magit-visit-thing] 'magit-diff-dwim) + (set-keymap-parent map magit-log-section-map) map) "Keymap for `unpushed' sections.") diff --git a/lisp/magit-merge.el b/lisp/magit-merge.el index d153c2755a..7deaa1b015 100644 --- a/lisp/magit-merge.el +++ b/lisp/magit-merge.el @@ -294,7 +294,7 @@ then also remove the respective remote branch." (defvar magit-unmerged-section-map (let ((map (make-sparse-keymap))) - (define-key map [remap magit-visit-thing] 'magit-diff-dwim) + (set-keymap-parent map magit-log-section-map) map) "Keymap for `unmerged' sections.") diff --git a/lisp/magit-refs.el b/lisp/magit-refs.el index 2665097138..1264564688 100644 --- a/lisp/magit-refs.el +++ b/lisp/magit-refs.el @@ -477,7 +477,7 @@ 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 "R" 'magit-remote-rename) + (define-key map [remap magit-file-rename] 'magit-remote-rename) map) "Keymap for `remote' sections.") @@ -485,7 +485,7 @@ Branch %s already exists. (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 "R" 'magit-branch-rename) + (define-key map [remap magit-file-rename] 'magit-branch-rename) map) "Keymap for `branch' sections.") diff --git a/lisp/magit-stash.el b/lisp/magit-stash.el index c0650f3c0b..5de5ffce95 100644 --- a/lisp/magit-stash.el +++ b/lisp/magit-stash.el @@ -386,8 +386,8 @@ current branch or `HEAD' as the start-point." (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 "a" 'magit-stash-apply) - (define-key map "A" 'magit-stash-pop) + (define-key map [remap magit-cherry-apply] 'magit-stash-apply) + (define-key map [remap magit-cherry-pick] 'magit-stash-pop) map) "Keymap for `stash' sections.") diff --git a/lisp/magit-status.el b/lisp/magit-status.el index 2bd428d8e5..6b950ee564 100644 --- a/lisp/magit-status.el +++ b/lisp/magit-status.el @@ -715,8 +715,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) - (define-key map "s" 'magit-stage) map) "Keymap for the `untracked' section.")