From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Robert Pluim Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Allow hiding stashes from vc-dir Date: Thu, 17 Oct 2019 18:26:10 +0200 Message-ID: References: <831rvegnub.fsf@gnu.org> <871rvex9ue.fsf@mail.linkov.net> <87eezdpjh4.fsf@gnus.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="88533"; mail-complaints-to="usenet@blaine.gmane.org" Cc: Eli Zaretskii , Juri Linkov , emacs-devel@gnu.org To: Lars Ingebrigtsen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Oct 17 19:04:55 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iL9Cn-000Msx-EP for ged-emacs-devel@m.gmane.org; Thu, 17 Oct 2019 19:04:53 +0200 Original-Received: from localhost ([::1]:53688 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL9Cl-0006Wg-Ha for ged-emacs-devel@m.gmane.org; Thu, 17 Oct 2019 13:04:51 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38790) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iL8bQ-0001Ho-TD for emacs-devel@gnu.org; Thu, 17 Oct 2019 12:26:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iL8bP-0008N4-1C for emacs-devel@gnu.org; Thu, 17 Oct 2019 12:26:16 -0400 Original-Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:37047) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iL8bO-0008ME-Nd; Thu, 17 Oct 2019 12:26:14 -0400 Original-Received: by mail-wm1-x343.google.com with SMTP id f22so3199535wmc.2; Thu, 17 Oct 2019 09:26:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:mail-copies-to:gmane-reply-to-list :date:in-reply-to:message-id:mime-version; bh=RD54BcdV58cwqDWcmS9CAZd2uKS2pNbFdqfH79k6RLA=; b=Dtmb4FNUlN7kZ9ny9p15shG2mE2ANz9Lauil0mKinonvq9Y0MGzDuzTg8xl5HrGz6h Jwi1fiUYwQFM2yU4fUsKPbB3gGevd1Z6fg+NKEC80g7LzB2r1oYPAfQ99DdFhN1fvtAk 2HG3VUxJJoDqsaMbLQsPqJVn9+BImfJdMJOZJ3Rbbv5+W7R2QutXvhzuSt/VntOSALyC SigMdip6gvX/josdvE6zimg8YlhrNH0qfYCLhFn1Kvw5/axs63AHYIURZCZ5nGWQq5xG f5u6VHpXiukDVoAtipzZt/PztNZUxiPR3DVQbBPaeBevTq1dkvSotPUeEAq+niCXzFPp xsmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:mail-copies-to :gmane-reply-to-list:date:in-reply-to:message-id:mime-version; bh=RD54BcdV58cwqDWcmS9CAZd2uKS2pNbFdqfH79k6RLA=; b=Dnihmvibg7p9LNS/w8CpIeq7ZNhBubtvdraEAQ1QDxHHqHuz/h/JOFNg8J26dAxlJn y90OPFrerJLvL0EAErrkiV/uOmcoXH0skDavGo/WQQcRGjiFOT3wVxcCQY7kV0TlwPUN AdR15cxmGe0ROotGg3HqSNKLt6TiCsfr7Jgka8U8txEZk4Cl3/dsMnTEea8U+E2NMSfC yUXczMJ2LV6tnfDWReHCkDKDNToQsAqsb9xuXybaH6+3jfN0Rph5Q3yJ/0xWrplhySis FTgE+5+o9s82JOdnxjiC3+rZYYjRiJXnhU0A2XA0Y6mMX7X8hS40UUBuw0nOx9kZVyDG opww== X-Gm-Message-State: APjAAAVmJDBGS3Mv9Wn2Jbu06DeCI+Hc+bPGoz932Oks8WZ32xg3IHE0 MyEEhYkpEQF71JeyrqfNMZ4= X-Google-Smtp-Source: APXvYqx7Cm+z1USQtpUYzJUvFl9BBnvAch1gGiqh4s4sPhdTHy4Ow2q6MmAc9bFv+2X7p3+NdZwXNg== X-Received: by 2002:a7b:ce89:: with SMTP id q9mr3659349wmj.2.1571329573033; Thu, 17 Oct 2019 09:26:13 -0700 (PDT) Original-Received: from rpluim-mac ([149.5.228.1]) by smtp.gmail.com with ESMTPSA id b5sm2611210wmj.18.2019.10.17.09.26.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2019 09:26:11 -0700 (PDT) Mail-Copies-To: never Gmane-Reply-To-List: yes In-Reply-To: (Robert Pluim's message of "Wed, 16 Oct 2019 10:57:18 +0200") X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::343 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:241151 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable >>>>> On Wed, 16 Oct 2019 10:57:18 +0200, Robert Pluim s= aid: >>>>> On Wed, 16 Oct 2019 03:28:07 +0200, Lars Ingebrigtsen said: Lars> Yes, that'd be great. I periodically have a whole bunch of stash= es in Lars> my Emacs repo, and toggling the list interactively would be the b= est Lars> solution, I think. Robert> OK, I=CA=BCll rework the patch a bit. I=CA=BCve also discovered= that vc-dir has Robert> commands for manipulating stashes, so limiting it to eg 5 would= help Robert> me (those commands are only bound when you=CA=BCre in the stash= list, which Robert> is why I never noticed them). Toggling with a configurable limit implemented in attached. I did feel like I was reinventing the wheel a bit, is there no "create a bunch of strings/regions and apply properties to them" library? --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Add-button-to-vc-dir-to-toggle-visibility-of-stash-l.patch >From 3197794363e16a617db86de32912e7a1085364e7 Mon Sep 17 00:00:00 2001 From: Robert Pluim Date: Thu, 17 Oct 2019 15:55:06 +0200 Subject: [PATCH] Add button to vc-dir to toggle visibility of stash list To: emacs-devel@gnu.org * 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, 90 insertions(+), 17 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index e1eb74f86e..9126b007ea 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -810,6 +810,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 9715aea1fd..1976aca1c9 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el @@ -108,6 +108,8 @@ (require 'vc) (require 'vc-dir)) +(declare-function cl-subseq "cl-extra" (seq start &optional end)) + (defgroup vc-git nil "VC Git backend." :version "24.1" @@ -192,6 +194,21 @@ vc-git-grep-template :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 +652,18 @@ vc-git-stash-map (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 +684,11 @@ vc-git-dir-extra-headers (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 +708,50 @@ vc-git-dir-extra-headers (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 +763,19 @@ vc-git-dir-extra-headers (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 -- 2.23.0 --=-=-=--