aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Pluim2019-10-17 15:55:06 +0200
committerRobert Pluim2019-10-21 11:32:12 +0200
commita5ca89d35c9762b1ff850235e0df5fdb4e77079d (patch)
treebb65c1028ae15d6eaf484ab006a8596465caa51e
parent435eb82e7b7e8926a3675bac74713e7c6081f7db (diff)
downloademacs-a5ca89d35c9762b1ff850235e0df5fdb4e77079d.tar.gz
emacs-a5ca89d35c9762b1ff850235e0df5fdb4e77079d.zip
Add button to vc-dir to toggle visibility of stash list
* lisp/vc/vc-git.el: Move cl-lib require outside 'eval-when-compile'. * lisp/vc/vc-git.el (vc-git-show-stash):New user option. (vc-git-make-stash-button): Create button that allows hiding the stash list. (vc-git-dir-extra-headers): Split stash list into hideable and non-hideable parts depending on value of vc-git-show-stash. Add button to toggle visibility of hideable part. * etc/NEWS: Announce it.
-rw-r--r--etc/NEWS5
-rw-r--r--lisp/vc/vc-git.el102
2 files changed, 89 insertions, 18 deletions
diff --git a/etc/NEWS b/etc/NEWS
index cf6b066b442..50213227fb3 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -815,6 +815,11 @@ The default value is 'find-dired-sort-by-filename'.
815*** New command 'log-edit-generate-changelog-from-diff', bound to 'C-c C-w'. 815*** New command 'log-edit-generate-changelog-from-diff', bound to 'C-c C-w'.
816This generates ChangeLog entries from the VC fileset diff. 816This generates ChangeLog entries from the VC fileset diff.
817 817
818*** 'vc-dir' now shows a button allowing you to hide the stash list.
819Controlled by user option 'vc-git-show-stash'. Default t means show
820the entire list as before. An integer value limits the list length
821(but still allows you to show the entire list via the button).
822
818*** Recording ChangeLog entries doesn't require an actual file. 823*** Recording ChangeLog entries doesn't require an actual file.
819If a ChangeLog file doesn't exist, and if the new user option 824If a ChangeLog file doesn't exist, and if the new user option
820'add-log-dont-create-changelog-file' is non-nil (which is the 825'add-log-dont-create-changelog-file' is non-nil (which is the
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 9715aea1fdc..70f53990733 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -102,8 +102,8 @@
102 102
103;;; Code: 103;;; Code:
104 104
105(require 'cl-lib)
105(eval-when-compile 106(eval-when-compile
106 (require 'cl-lib)
107 (require 'subr-x) ; for string-trim-right 107 (require 'subr-x) ; for string-trim-right
108 (require 'vc) 108 (require 'vc)
109 (require 'vc-dir)) 109 (require 'vc-dir))
@@ -192,6 +192,21 @@ The following place holders should be present in the string:
192 :type 'string 192 :type 'string
193 :version "27.1") 193 :version "27.1")
194 194
195(defcustom vc-git-show-stash t
196 "How much of the git stash list to show by default.
197Default t means all, otherwise an integer specifying the maximum
198number to show. A text button is always shown allowing you to
199toggle display of the entire list."
200 :type '(choice (const :tag "All" t)
201 (integer :tag "Limit"
202 :validate
203 (lambda (widget)
204 (unless (>= (widget-value widget) 0)
205 (widget-put widget :error
206 "Invalid value: must be a non-negative integer")
207 widget))))
208 :version "27.1")
209
195;; History of Git commands. 210;; History of Git commands.
196(defvar vc-git-history nil) 211(defvar vc-git-history nil)
197 212
@@ -635,6 +650,18 @@ or an empty string if none."
635 (define-key map "S" 'vc-git-stash-snapshot) 650 (define-key map "S" 'vc-git-stash-snapshot)
636 map)) 651 map))
637 652
653(defun vc-git-make-stash-button ()
654 (make-text-button "Show/hide stashes" nil
655 'action
656 (lambda (&rest _ignore)
657 (let* ((inhibit-read-only t)
658 (start (next-single-property-change (point-min) 'vc-git-hideable))
659 (end (next-single-property-change start 'vc-git-hideable)))
660 (add-text-properties
661 start end
662 `(invisible ,(not (get-text-property start 'invisible))))))
663 'help-echo "mouse-2, RET: Show/hide stashes"))
664
638(defvar vc-git-stash-menu-map 665(defvar vc-git-stash-menu-map
639 (let ((map (make-sparse-keymap "Git Stash"))) 666 (let ((map (make-sparse-keymap "Git Stash")))
640 (define-key map [de] 667 (define-key map [de]
@@ -655,9 +682,11 @@ or an empty string if none."
655 (let ((str (with-output-to-string 682 (let ((str (with-output-to-string
656 (with-current-buffer standard-output 683 (with-current-buffer standard-output
657 (vc-git--out-ok "symbolic-ref" "HEAD")))) 684 (vc-git--out-ok "symbolic-ref" "HEAD"))))
658 (stash (vc-git-stash-list)) 685 (stash-list (vc-git-stash-list))
659 (stash-help-echo "Use M-x vc-git-stash to create stashes.") 686 (stash-help-echo "Use M-x vc-git-stash to create stashes.")
660 branch remote remote-url) 687 (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")
688
689 branch remote remote-url stash-button stash-string)
661 (if (string-match "^\\(refs/heads/\\)?\\(.+\\)$" str) 690 (if (string-match "^\\(refs/heads/\\)?\\(.+\\)$" str)
662 (progn 691 (progn
663 (setq branch (match-string 2 str)) 692 (setq branch (match-string 2 str))
@@ -677,6 +706,50 @@ or an empty string if none."
677 (when (string-match "\\([^\n]+\\)" remote-url) 706 (when (string-match "\\([^\n]+\\)" remote-url)
678 (setq remote-url (match-string 1 remote-url)))) 707 (setq remote-url (match-string 1 remote-url))))
679 (setq branch "not (detached HEAD)")) 708 (setq branch "not (detached HEAD)"))
709 (when stash-list
710 (let* ((limit
711 (if (integerp vc-git-show-stash)
712 (min vc-git-show-stash (length stash-list))
713 (length stash-list)))
714 (shown-stashes (cl-subseq stash-list 0 limit))
715 (hidden-stashes (cl-subseq stash-list limit))
716 (all-hideable (eq vc-git-show-stash t)))
717 (setq stash-button (vc-git-make-stash-button)
718 stash-string
719 (concat
720 (when shown-stashes
721 (concat
722 (propertize "\n"
723 'vc-git-hideable all-hideable)
724 (mapconcat
725 (lambda (x)
726 (propertize x
727 'face 'font-lock-variable-name-face
728 'mouse-face 'highlight
729 'vc-git-hideable all-hideable
730 'help-echo stash-list-help-echo
731 'keymap vc-git-stash-map))
732 shown-stashes
733 (propertize "\n"
734 'vc-git-hideable all-hideable))))
735 (when hidden-stashes
736 (concat
737 (propertize "\n"
738 'invisible t
739 'vc-git-hideable t)
740 (mapconcat
741 (lambda (x)
742 (propertize x
743 'face 'font-lock-variable-name-face
744 'mouse-face 'highlight
745 'invisible t
746 'vc-git-hideable t
747 'help-echo stash-list-help-echo
748 'keymap vc-git-stash-map))
749 hidden-stashes
750 (propertize "\n"
751 'invisible t
752 'vc-git-hideable t))))))))
680 ;; FIXME: maybe use a different face when nothing is stashed. 753 ;; FIXME: maybe use a different face when nothing is stashed.
681 (concat 754 (concat
682 (propertize "Branch : " 'face 'font-lock-type-face) 755 (propertize "Branch : " 'face 'font-lock-type-face)
@@ -688,26 +761,19 @@ or an empty string if none."
688 (propertize "Remote : " 'face 'font-lock-type-face) 761 (propertize "Remote : " 'face 'font-lock-type-face)
689 (propertize remote-url 762 (propertize remote-url
690 'face 'font-lock-variable-name-face))) 763 'face 'font-lock-variable-name-face)))
691 "\n"
692 ;; For now just a heading, key bindings can be added later for various bisect actions 764 ;; For now just a heading, key bindings can be added later for various bisect actions
693 (when (file-exists-p (expand-file-name ".git/BISECT_START" (vc-git-root dir))) 765 (when (file-exists-p (expand-file-name ".git/BISECT_START" (vc-git-root dir)))
694 (propertize "Bisect : in progress\n" 'face 'font-lock-warning-face)) 766 (propertize "\nBisect : in progress" 'face 'font-lock-warning-face))
695 (when (file-exists-p (expand-file-name ".git/rebase-apply" (vc-git-root dir))) 767 (when (file-exists-p (expand-file-name ".git/rebase-apply" (vc-git-root dir)))
696 (propertize "Rebase : in progress\n" 'face 'font-lock-warning-face)) 768 (propertize "\nRebase : in progress" 'face 'font-lock-warning-face))
697 (if stash 769 (if stash-list
698 (concat 770 (concat
699 (propertize "Stash :\n" 'face 'font-lock-type-face 771 (propertize "\nStash : " 'face 'font-lock-type-face
700 'help-echo stash-help-echo) 772 'help-echo stash-help-echo)
701 (mapconcat 773 stash-button
702 (lambda (x) 774 stash-string)
703 (propertize x
704 'face 'font-lock-variable-name-face
705 'mouse-face 'highlight
706 'help-echo "mouse-3: Show stash menu\nRET: Show stash\nA: Apply stash\nP: Apply and remove stash (pop)\nC-k: Delete stash"
707 'keymap vc-git-stash-map))
708 stash "\n"))
709 (concat 775 (concat
710 (propertize "Stash : " 'face 'font-lock-type-face 776 (propertize "\nStash : " 'face 'font-lock-type-face
711 'help-echo stash-help-echo) 777 'help-echo stash-help-echo)
712 (propertize "Nothing stashed" 778 (propertize "Nothing stashed"
713 'help-echo stash-help-echo 779 'help-echo stash-help-echo