From: Robert Pluim Date: Tue, 22 Oct 2019 07:31:15 +0000 (+0200) Subject: Show stash counts in button in vc-dir X-Git-Tag: emacs-27.0.90~920 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=4a9d8bdca3e502c1e87c4c50df3926c629475d39;p=emacs.git 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. --- 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." (define-key map "S" 'vc-git-stash-snapshot) map)) -(defun vc-git-make-stash-button () - (make-text-button "Show/hide stashes" nil - 'action - (lambda (&rest _ignore) - (let* ((inhibit-read-only t) - (start (next-single-property-change (point-min) 'vc-git-hideable)) - (end (next-single-property-change start 'vc-git-hideable))) - (add-text-properties - start end - `(invisible ,(not (get-text-property start 'invisible)))))) - 'help-echo "mouse-2, RET: Show/hide stashes")) +(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)))) + +(defun vc-git-make-stash-button (show count1 count2) + (let ((orig-text (vc-git--make-button-text show count1 count2))) + (make-text-button + orig-text nil + 'action + (lambda (counts) + (let* ((inhibit-read-only t) + (start (next-single-property-change + (point-min) 'vc-git-hideable)) + (end (next-single-property-change + start 'vc-git-hideable)) + (state (get-text-property start 'invisible))) + (add-text-properties + start end + `(invisible ,(not state))) + (save-excursion + (delete-region (button-start (point)) (button-end (point))) + (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"))) (defvar vc-git-stash-menu-map (let ((map (make-sparse-keymap "Git Stash"))) @@ -707,14 +724,18 @@ or an empty string if none." (setq remote-url (match-string 1 remote-url)))) (setq branch "not (detached HEAD)")) (when stash-list - (let* ((limit + (let* ((len (length stash-list)) + (limit (if (integerp vc-git-show-stash) - (min vc-git-show-stash (length stash-list)) - (length stash-list))) + (min vc-git-show-stash len) + len)) (shown-stashes (cl-subseq stash-list 0 limit)) (hidden-stashes (cl-subseq stash-list limit)) - (all-hideable (eq vc-git-show-stash t))) - (setq stash-button (vc-git-make-stash-button) + (all-hideable (or (eq vc-git-show-stash t) + (<= len vc-git-show-stash)))) + (setq stash-button (if all-hideable + (vc-git-make-stash-button nil limit limit) + (vc-git-make-stash-button t vc-git-show-stash len)) stash-string (concat (when shown-stashes