aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Pluim2019-10-22 09:31:15 +0200
committerRobert Pluim2019-10-22 09:36:17 +0200
commit4a9d8bdca3e502c1e87c4c50df3926c629475d39 (patch)
treec927e0355a9937ec827381c2c9d328077a9c4a85
parentd45740cd9f4f9f2cc132fb81626236789a97b2c9 (diff)
downloademacs-4a9d8bdca3e502c1e87c4c50df3926c629475d39.tar.gz
emacs-4a9d8bdca3e502c1e87c4c50df3926c629475d39.zip
Show stash counts in button in vc-dir
Based on suggestions from Mattias EngdegÄrd. * lisp/vc/vc-git.el (vc-git--make-button-text): New function to generate text for stash button. (vc-git-make-stash-button): Show stash counts. Delete and recreate button when toggling. (vc-git-dir-extra-headers): Pass counts to vc-git-make-stash-button. Treat stash count <= vc-git-show-stash as equivalent to showing entire list.
-rw-r--r--lisp/vc/vc-git.el53
1 files changed, 37 insertions, 16 deletions
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 70f53990733..ce8e57df768 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -650,17 +650,34 @@ or an empty string if none."
650 (define-key map "S" 'vc-git-stash-snapshot) 650 (define-key map "S" 'vc-git-stash-snapshot)
651 map)) 651 map))
652 652
653(defun vc-git-make-stash-button () 653(defun vc-git--make-button-text (show count1 count2)
654 (make-text-button "Show/hide stashes" nil 654 (if show
655 'action 655 (format "Show all stashes (%s)" count2)
656 (lambda (&rest _ignore) 656 (if (= count1 count2)
657 (let* ((inhibit-read-only t) 657 (format "Hide all stashes (%s)" count2)
658 (start (next-single-property-change (point-min) 'vc-git-hideable)) 658 (format "Show %s stash%s (of %s)" count1 (if (= count1 1) "" "es") count2))))
659 (end (next-single-property-change start 'vc-git-hideable))) 659
660 (add-text-properties 660(defun vc-git-make-stash-button (show count1 count2)
661 start end 661 (let ((orig-text (vc-git--make-button-text show count1 count2)))
662 `(invisible ,(not (get-text-property start 'invisible)))))) 662 (make-text-button
663 'help-echo "mouse-2, RET: Show/hide stashes")) 663 orig-text nil
664 'action
665 (lambda (counts)
666 (let* ((inhibit-read-only t)
667 (start (next-single-property-change
668 (point-min) 'vc-git-hideable))
669 (end (next-single-property-change
670 start 'vc-git-hideable))
671 (state (get-text-property start 'invisible)))
672 (add-text-properties
673 start end
674 `(invisible ,(not state)))
675 (save-excursion
676 (delete-region (button-start (point)) (button-end (point)))
677 (insert (vc-git-make-stash-button
678 (not state) (car counts) (cdr counts))))))
679 'button-data (cons count1 count2)
680 'help-echo "mouse-2, RET: Show/hide stashes")))
664 681
665(defvar vc-git-stash-menu-map 682(defvar vc-git-stash-menu-map
666 (let ((map (make-sparse-keymap "Git Stash"))) 683 (let ((map (make-sparse-keymap "Git Stash")))
@@ -707,14 +724,18 @@ or an empty string if none."
707 (setq remote-url (match-string 1 remote-url)))) 724 (setq remote-url (match-string 1 remote-url))))
708 (setq branch "not (detached HEAD)")) 725 (setq branch "not (detached HEAD)"))
709 (when stash-list 726 (when stash-list
710 (let* ((limit 727 (let* ((len (length stash-list))
728 (limit
711 (if (integerp vc-git-show-stash) 729 (if (integerp vc-git-show-stash)
712 (min vc-git-show-stash (length stash-list)) 730 (min vc-git-show-stash len)
713 (length stash-list))) 731 len))
714 (shown-stashes (cl-subseq stash-list 0 limit)) 732 (shown-stashes (cl-subseq stash-list 0 limit))
715 (hidden-stashes (cl-subseq stash-list limit)) 733 (hidden-stashes (cl-subseq stash-list limit))
716 (all-hideable (eq vc-git-show-stash t))) 734 (all-hideable (or (eq vc-git-show-stash t)
717 (setq stash-button (vc-git-make-stash-button) 735 (<= len vc-git-show-stash))))
736 (setq stash-button (if all-hideable
737 (vc-git-make-stash-button nil limit limit)
738 (vc-git-make-stash-button t vc-git-show-stash len))
718 stash-string 739 stash-string
719 (concat 740 (concat
720 (when shown-stashes 741 (when shown-stashes