aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Pluim2019-10-31 10:52:20 +0100
committerRobert Pluim2019-10-31 10:53:05 +0100
commite168bb73865f64cc67f80f8b2599c826cbf9e957 (patch)
tree04001f4f952cff9fc150877584f388c95521b2c6
parente65be8cc5b623385ebe31aa0a1089e0de2b075b5 (diff)
downloademacs-e168bb73865f64cc67f80f8b2599c826cbf9e957.tar.gz
emacs-e168bb73865f64cc67f80f8b2599c826cbf9e957.zip
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.
-rw-r--r--etc/NEWS4
-rw-r--r--lisp/vc/vc-git.el57
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.
879*** 'vc-git-stash' has now been bound to the 'C' keystroke in the 879*** 'vc-git-stash' has now been bound to the 'C' keystroke in the
880stash headers. 880stash headers.
881 881
882*** Some stash keybindings are now available in the stash button.
883'vc-git-stash' and 'vc-git-stash-snapshot' can now be run using 'C'
884and 'S' respectively, including when there are no stashes.
885
882*** The new hook 'vc-retrieve-tag-hook' runs after retrieving a tag. 886*** The new hook 'vc-retrieve-tag-hook' runs after retrieving a tag.
883 887
884--- 888---
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."
636 :files files 636 :files files
637 :update-function update-function))) 637 :update-function update-function)))
638 638
639(defvar vc-git-stash-shared-map
640 (let ((map (make-sparse-keymap)))
641 (define-key map "S" 'vc-git-stash-snapshot)
642 (define-key map "C" 'vc-git-stash)
643 map))
644
639(defvar vc-git-stash-map 645(defvar vc-git-stash-map
640 (let ((map (make-sparse-keymap))) 646 (let ((map (make-sparse-keymap)))
647 (set-keymap-parent map vc-git-stash-shared-map)
641 ;; Turn off vc-dir marking 648 ;; Turn off vc-dir marking
642 (define-key map [mouse-2] 'ignore) 649 (define-key map [mouse-2] 'ignore)
643 650
@@ -647,16 +654,29 @@ or an empty string if none."
647 (define-key map "\C-m" 'vc-git-stash-show-at-point) 654 (define-key map "\C-m" 'vc-git-stash-show-at-point)
648 (define-key map "A" 'vc-git-stash-apply-at-point) 655 (define-key map "A" 'vc-git-stash-apply-at-point)
649 (define-key map "P" 'vc-git-stash-pop-at-point) 656 (define-key map "P" 'vc-git-stash-pop-at-point)
650 (define-key map "S" 'vc-git-stash-snapshot)
651 (define-key map "C" 'vc-git-stash)
652 map)) 657 map))
653 658
659(defvar vc-git-stash-button-map
660 (let ((map (make-sparse-keymap)))
661 (set-keymap-parent map vc-git-stash-shared-map)
662 (define-key map [mouse-2] 'push-button)
663 (define-key map "\C-m" 'push-button)
664 map))
665
666(defconst vc-git-stash-shared-help
667 "\\<vc-git-stash-shared-map>\\[vc-git-stash]: Create named stash\n\\[vc-git-stash-snapshot]: Snapshot stash")
668
669(defconst vc-git-stash-list-help (concat "\\<vc-git-stash-map>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"
670 vc-git-stash-shared-help))
671
654(defun vc-git--make-button-text (show count1 count2) 672(defun vc-git--make-button-text (show count1 count2)
655 (if show 673 (propertize
656 (format "Show all stashes (%s)" count2) 674 (if show
657 (if (= count1 count2) 675 (format "Show all stashes (%s)" count2)
658 (format "Hide all stashes (%s)" count2) 676 (if (= count1 count2)
659 (format "Show %s stash%s (of %s)" count1 (if (= count1 1) "" "es") count2)))) 677 (format "Hide all stashes (%s)" count2)
678 (format "Show %s stash%s (of %s)" count1 (if (= count1 1) "" "es") count2)))
679 'keymap vc-git-stash-button-map))
660 680
661(defun vc-git-make-stash-button (show count1 count2) 681(defun vc-git-make-stash-button (show count1 count2)
662 (let ((orig-text (vc-git--make-button-text show count1 count2))) 682 (let ((orig-text (vc-git--make-button-text show count1 count2)))
@@ -678,10 +698,16 @@ or an empty string if none."
678 (insert (vc-git-make-stash-button 698 (insert (vc-git-make-stash-button
679 (not state) (car counts) (cdr counts)))))) 699 (not state) (car counts) (cdr counts))))))
680 'button-data (cons count1 count2) 700 'button-data (cons count1 count2)
681 'help-echo "mouse-2, RET: Show/hide stashes"))) 701 'help-echo (concat "mouse-2, RET: Show/hide stashes\n" vc-git-stash-shared-help))))
682 702
683(defvar vc-git-stash-menu-map 703(defvar vc-git-stash-menu-map
684 (let ((map (make-sparse-keymap "Git Stash"))) 704 (let ((map (make-sparse-keymap "Git Stash")))
705 (define-key map [sn]
706 '(menu-item "Snapshot Stash" vc-git-stash-snapshot
707 :help "Snapshot stash"))
708 (define-key map [cr]
709 '(menu-item "Create Samed Stash" vc-git-stash
710 :help "Create named stash"))
685 (define-key map [de] 711 (define-key map [de]
686 '(menu-item "Delete Stash" vc-git-stash-delete-at-point 712 '(menu-item "Delete Stash" vc-git-stash-delete-at-point
687 :help "Delete the current stash")) 713 :help "Delete the current stash"))
@@ -701,8 +727,6 @@ or an empty string if none."
701 (with-current-buffer standard-output 727 (with-current-buffer standard-output
702 (vc-git--out-ok "symbolic-ref" "HEAD")))) 728 (vc-git--out-ok "symbolic-ref" "HEAD"))))
703 (stash-list (vc-git-stash-list)) 729 (stash-list (vc-git-stash-list))
704 (stash-help-echo "Use M-x vc-git-stash to create stashes.")
705 (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")
706 730
707 branch remote remote-url stash-button stash-string) 731 branch remote remote-url stash-button stash-string)
708 (if (string-match "^\\(refs/heads/\\)?\\(.+\\)$" str) 732 (if (string-match "^\\(refs/heads/\\)?\\(.+\\)$" str)
@@ -749,7 +773,7 @@ or an empty string if none."
749 'face 'font-lock-variable-name-face 773 'face 'font-lock-variable-name-face
750 'mouse-face 'highlight 774 'mouse-face 'highlight
751 'vc-git-hideable all-hideable 775 'vc-git-hideable all-hideable
752 'help-echo stash-list-help-echo 776 'help-echo vc-git-stash-list-help
753 'keymap vc-git-stash-map)) 777 'keymap vc-git-stash-map))
754 shown-stashes 778 shown-stashes
755 (propertize "\n" 779 (propertize "\n"
@@ -766,7 +790,7 @@ or an empty string if none."
766 'mouse-face 'highlight 790 'mouse-face 'highlight
767 'invisible t 791 'invisible t
768 'vc-git-hideable t 792 'vc-git-hideable t
769 'help-echo stash-list-help-echo 793 'help-echo vc-git-stash-list-help
770 'keymap vc-git-stash-map)) 794 'keymap vc-git-stash-map))
771 hidden-stashes 795 hidden-stashes
772 (propertize "\n" 796 (propertize "\n"
@@ -790,15 +814,14 @@ or an empty string if none."
790 (propertize "\nRebase : in progress" 'face 'font-lock-warning-face)) 814 (propertize "\nRebase : in progress" 'face 'font-lock-warning-face))
791 (if stash-list 815 (if stash-list
792 (concat 816 (concat
793 (propertize "\nStash : " 'face 'font-lock-type-face 817 (propertize "\nStash : " 'face 'font-lock-type-face)
794 'help-echo stash-help-echo)
795 stash-button 818 stash-button
796 stash-string) 819 stash-string)
797 (concat 820 (concat
798 (propertize "\nStash : " 'face 'font-lock-type-face 821 (propertize "\nStash : " 'face 'font-lock-type-face)
799 'help-echo stash-help-echo)
800 (propertize "Nothing stashed" 822 (propertize "Nothing stashed"
801 'help-echo stash-help-echo 823 'help-echo vc-git-stash-shared-help
824 'keymap vc-git-stash-shared-map
802 'face 'font-lock-variable-name-face)))))) 825 'face 'font-lock-variable-name-face))))))
803 826
804(defun vc-git-branches () 827(defun vc-git-branches ()