From e168bb73865f64cc67f80f8b2599c826cbf9e957 Mon Sep 17 00:00:00 2001 From: Robert Pluim Date: Thu, 31 Oct 2019 10:52:20 +0100 Subject: [PATCH] Rework vc stash bindings This adds create/snapshot bindings to the stash button even when there are no stashes, and extends the stash menu bindings. * etc/NEWS: Announce the bindings. * lisp/vc/vc-git.el (vc-git-stash-shared-map): New keymap. Holds shared bindings between stash button and stash list. (vc-git-stash-map): Inherit from vc-git-stash-shared-map. (vc-git-stash-button-map): New keymap. Holds button bindings, inherit from vc-git-stash-shared-map. (vc-git-stash-shared-help, vc-git-stash-list-help): New defconsts. Abstract out list/button help texts. (vc-git--make-button-text): Set keymap property to vc-git-stash-button-map. (vc-git-make-stash-button): Use vc-git-stash-shared-help. (vc-git-stash-menu-map): Add items for vc-git-stash and vc-git-stash-snapshot. (vc-git-dir-extra-headers): Use vc-git-stash-list-help and vc-git-stash-shared-help. Add vc-git-stash and vc-git-stash-snapshot bindings to text shown when there are no stashes. --- etc/NEWS | 4 ++++ lisp/vc/vc-git.el | 57 +++++++++++++++++++++++++++++++++-------------- 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index cd1e46bb872..ee73d2414bd 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -879,6 +879,10 @@ When no files are marked, all modified files are stashed, as before. *** 'vc-git-stash' has now been bound to the 'C' keystroke in the stash headers. +*** Some stash keybindings are now available in the stash button. +'vc-git-stash' and 'vc-git-stash-snapshot' can now be run using 'C' +and 'S' respectively, including when there are no stashes. + *** The new hook 'vc-retrieve-tag-hook' runs after retrieving a tag. --- diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index e0b3b094626..3960f725cf9 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -636,8 +636,15 @@ or an empty string if none." :files files :update-function update-function))) +(defvar vc-git-stash-shared-map + (let ((map (make-sparse-keymap))) + (define-key map "S" 'vc-git-stash-snapshot) + (define-key map "C" 'vc-git-stash) + map)) + (defvar vc-git-stash-map (let ((map (make-sparse-keymap))) + (set-keymap-parent map vc-git-stash-shared-map) ;; Turn off vc-dir marking (define-key map [mouse-2] 'ignore) @@ -647,16 +654,29 @@ or an empty string if none." (define-key map "\C-m" 'vc-git-stash-show-at-point) (define-key map "A" 'vc-git-stash-apply-at-point) (define-key map "P" 'vc-git-stash-pop-at-point) - (define-key map "S" 'vc-git-stash-snapshot) - (define-key map "C" 'vc-git-stash) map)) +(defvar vc-git-stash-button-map + (let ((map (make-sparse-keymap))) + (set-keymap-parent map vc-git-stash-shared-map) + (define-key map [mouse-2] 'push-button) + (define-key map "\C-m" 'push-button) + map)) + +(defconst vc-git-stash-shared-help + "\\\\[vc-git-stash]: Create named stash\n\\[vc-git-stash-snapshot]: Snapshot stash") + +(defconst vc-git-stash-list-help (concat "\\mouse-3: Show stash menu\n\\[vc-git-stash-show-at-point], =: Show stash\n\\[vc-git-stash-apply-at-point]: Apply stash\n\\[vc-git-stash-pop-at-point]: Apply and remove stash (pop)\n\\[vc-git-stash-delete-at-point]: Delete stash\n" + vc-git-stash-shared-help)) + (defun vc-git--make-button-text (show count1 count2) - (if show - (format "Show all stashes (%s)" count2) - (if (= count1 count2) - (format "Hide all stashes (%s)" count2) - (format "Show %s stash%s (of %s)" count1 (if (= count1 1) "" "es") count2)))) + (propertize + (if show + (format "Show all stashes (%s)" count2) + (if (= count1 count2) + (format "Hide all stashes (%s)" count2) + (format "Show %s stash%s (of %s)" count1 (if (= count1 1) "" "es") count2))) + 'keymap vc-git-stash-button-map)) (defun vc-git-make-stash-button (show count1 count2) (let ((orig-text (vc-git--make-button-text show count1 count2))) @@ -678,10 +698,16 @@ or an empty string if none." (insert (vc-git-make-stash-button (not state) (car counts) (cdr counts)))))) 'button-data (cons count1 count2) - 'help-echo "mouse-2, RET: Show/hide stashes"))) + 'help-echo (concat "mouse-2, RET: Show/hide stashes\n" vc-git-stash-shared-help)))) (defvar vc-git-stash-menu-map (let ((map (make-sparse-keymap "Git Stash"))) + (define-key map [sn] + '(menu-item "Snapshot Stash" vc-git-stash-snapshot + :help "Snapshot stash")) + (define-key map [cr] + '(menu-item "Create Samed Stash" vc-git-stash + :help "Create named stash")) (define-key map [de] '(menu-item "Delete Stash" vc-git-stash-delete-at-point :help "Delete the current stash")) @@ -701,8 +727,6 @@ or an empty string if none." (with-current-buffer standard-output (vc-git--out-ok "symbolic-ref" "HEAD")))) (stash-list (vc-git-stash-list)) - (stash-help-echo "Use M-x vc-git-stash to create stashes.") - (stash-list-help-echo "mouse-3: Show stash menu\nRET: Show stash\nA: Apply stash\nP: Apply and remove stash (pop)\nC-k: Delete stash") branch remote remote-url stash-button stash-string) (if (string-match "^\\(refs/heads/\\)?\\(.+\\)$" str) @@ -749,7 +773,7 @@ or an empty string if none." 'face 'font-lock-variable-name-face 'mouse-face 'highlight 'vc-git-hideable all-hideable - 'help-echo stash-list-help-echo + 'help-echo vc-git-stash-list-help 'keymap vc-git-stash-map)) shown-stashes (propertize "\n" @@ -766,7 +790,7 @@ or an empty string if none." 'mouse-face 'highlight 'invisible t 'vc-git-hideable t - 'help-echo stash-list-help-echo + 'help-echo vc-git-stash-list-help 'keymap vc-git-stash-map)) hidden-stashes (propertize "\n" @@ -790,15 +814,14 @@ or an empty string if none." (propertize "\nRebase : in progress" 'face 'font-lock-warning-face)) (if stash-list (concat - (propertize "\nStash : " 'face 'font-lock-type-face - 'help-echo stash-help-echo) + (propertize "\nStash : " 'face 'font-lock-type-face) stash-button stash-string) (concat - (propertize "\nStash : " 'face 'font-lock-type-face - 'help-echo stash-help-echo) + (propertize "\nStash : " 'face 'font-lock-type-face) (propertize "Nothing stashed" - 'help-echo stash-help-echo + 'help-echo vc-git-stash-shared-help + 'keymap vc-git-stash-shared-map 'face 'font-lock-variable-name-face)))))) (defun vc-git-branches () -- 2.39.5