emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master a5ca89d: Add button to vc-dir to toggle visibility


From: Robert Pluim
Subject: [Emacs-diffs] master a5ca89d: Add button to vc-dir to toggle visibility of stash list
Date: Mon, 21 Oct 2019 05:37:44 -0400 (EDT)

branch: master
commit a5ca89d35c9762b1ff850235e0df5fdb4e77079d
Author: Robert Pluim <address@hidden>
Commit: Robert Pluim <address@hidden>

    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.
---
 etc/NEWS          |   5 +++
 lisp/vc/vc-git.el | 102 ++++++++++++++++++++++++++++++++++++++++++++----------
 2 files changed, 89 insertions(+), 18 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index cf6b066..5021322 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -815,6 +815,11 @@ The default value is 'find-dired-sort-by-filename'.
 *** New command 'log-edit-generate-changelog-from-diff', bound to 'C-c C-w'.
 This generates ChangeLog entries from the VC fileset diff.
 
+*** 'vc-dir' now shows a button allowing you to hide the stash list.
+Controlled by user option 'vc-git-show-stash'.  Default t means show
+the entire list as before.  An integer value limits the list length
+(but still allows you to show the entire list via the button).
+
 *** Recording ChangeLog entries doesn't require an actual file.
 If a ChangeLog file doesn't exist, and if the new user option
 '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 9715aea..70f5399 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -102,8 +102,8 @@
 
 ;;; Code:
 
+(require 'cl-lib)
 (eval-when-compile
-  (require 'cl-lib)
   (require 'subr-x) ; for string-trim-right
   (require 'vc)
   (require 'vc-dir))
@@ -192,6 +192,21 @@ The following place holders should be present in the 
string:
   :type 'string
   :version "27.1")
 
+(defcustom vc-git-show-stash t
+  "How much of the git stash list to show by default.
+Default t means all, otherwise an integer specifying the maximum
+number to show.  A text button is always shown allowing you to
+toggle display of the entire list."
+  :type '(choice (const :tag "All" t)
+                 (integer :tag "Limit"
+                          :validate
+                          (lambda (widget)
+                            (unless (>= (widget-value widget) 0)
+                              (widget-put widget :error
+                                          "Invalid value: must be a 
non-negative integer")
+                              widget))))
+  :version "27.1")
+
 ;; History of Git commands.
 (defvar vc-git-history nil)
 
@@ -635,6 +650,18 @@ 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"))
+
 (defvar vc-git-stash-menu-map
   (let ((map (make-sparse-keymap "Git Stash")))
     (define-key map [de]
@@ -655,9 +682,11 @@ or an empty string if none."
   (let ((str (with-output-to-string
                (with-current-buffer standard-output
                  (vc-git--out-ok "symbolic-ref" "HEAD"))))
-       (stash (vc-git-stash-list))
+       (stash-list (vc-git-stash-list))
        (stash-help-echo "Use M-x vc-git-stash to create stashes.")
-       branch remote remote-url)
+        (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)
        (progn
          (setq branch (match-string 2 str))
@@ -677,6 +706,50 @@ or an empty string if none."
          (when (string-match "\\([^\n]+\\)" remote-url)
            (setq remote-url (match-string 1 remote-url))))
       (setq branch "not (detached HEAD)"))
+    (when stash-list
+      (let* ((limit
+              (if (integerp vc-git-show-stash)
+                  (min vc-git-show-stash (length stash-list))
+                (length stash-list)))
+             (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)
+              stash-string
+              (concat
+               (when shown-stashes
+                 (concat
+                  (propertize "\n"
+                              'vc-git-hideable all-hideable)
+                  (mapconcat
+                   (lambda (x)
+                     (propertize x
+                                 'face 'font-lock-variable-name-face
+                                 'mouse-face 'highlight
+                                 'vc-git-hideable all-hideable
+                                 'help-echo stash-list-help-echo
+                                 'keymap vc-git-stash-map))
+                   shown-stashes
+                   (propertize "\n"
+                               'vc-git-hideable all-hideable))))
+               (when hidden-stashes
+                 (concat
+                  (propertize "\n"
+                              'invisible t
+                              'vc-git-hideable t)
+                  (mapconcat
+                   (lambda (x)
+                     (propertize x
+                                 'face 'font-lock-variable-name-face
+                                 'mouse-face 'highlight
+                                 'invisible t
+                                 'vc-git-hideable t
+                                 'help-echo stash-list-help-echo
+                                 'keymap vc-git-stash-map))
+                   hidden-stashes
+                   (propertize "\n"
+                               'invisible t
+                               'vc-git-hideable t))))))))
     ;; FIXME: maybe use a different face when nothing is stashed.
     (concat
      (propertize "Branch     : " 'face 'font-lock-type-face)
@@ -688,26 +761,19 @@ or an empty string if none."
        (propertize "Remote     : " 'face 'font-lock-type-face)
        (propertize remote-url
                    'face 'font-lock-variable-name-face)))
-     "\n"
      ;; For now just a heading, key bindings can be added later for various 
bisect actions
      (when (file-exists-p (expand-file-name ".git/BISECT_START" (vc-git-root 
dir)))
-       (propertize  "Bisect     : in progress\n" 'face 
'font-lock-warning-face))
+       (propertize  "\nBisect     : in progress" 'face 
'font-lock-warning-face))
      (when (file-exists-p (expand-file-name ".git/rebase-apply" (vc-git-root 
dir)))
-       (propertize  "Rebase     : in progress\n" 'face 
'font-lock-warning-face))
-     (if stash
+       (propertize  "\nRebase     : in progress" 'face 
'font-lock-warning-face))
+     (if stash-list
        (concat
-       (propertize "Stash      :\n" 'face 'font-lock-type-face
-                   'help-echo stash-help-echo)
-       (mapconcat
-        (lambda (x)
-          (propertize x
-                      'face 'font-lock-variable-name-face
-                      'mouse-face 'highlight
-                      'help-echo "mouse-3: Show stash menu\nRET: Show 
stash\nA: Apply stash\nP: Apply and remove stash (pop)\nC-k: Delete stash"
-                      'keymap vc-git-stash-map))
-        stash "\n"))
+        (propertize "\nStash      : " 'face 'font-lock-type-face
+                    'help-echo stash-help-echo)
+        stash-button
+        stash-string)
        (concat
-       (propertize "Stash      : " 'face 'font-lock-type-face
+       (propertize "\nStash      : " 'face 'font-lock-type-face
                    'help-echo stash-help-echo)
        (propertize "Nothing stashed"
                    'help-echo stash-help-echo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]