GNU bug report logs - #52855
vc-shrink-buffer

Previous Next

Package: emacs;

Reported by: Juri Linkov <juri <at> linkov.net>

Date: Tue, 28 Dec 2021 18:32:02 UTC

Severity: wishlist

Tags: patch

Merged with 36859, 51062

Fixed in version 29.0.50

Done: Juri Linkov <juri <at> linkov.net>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 52855 in the body.
You can then email your comments to 52855 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#52855; Package emacs. (Tue, 28 Dec 2021 18:32:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Juri Linkov <juri <at> linkov.net>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 28 Dec 2021 18:32:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: bug-gnu-emacs <at> gnu.org
Subject: vc-shrink-buffer
Date: Tue, 28 Dec 2021 20:29:09 +0200
[Message part 1 (text/plain, inline)]
When no shrink is needed, two new hooks are added in this patch
with the default value containing vc-shrink-buffer to preserve
the current behavior that can be easily removed in user configuration
by e.g.:

  (remove-hook 'vc-diff-finish-functions 'vc-shrink-buffer)
  (remove-hook 'vc-log-finish-functions 'vc-shrink-buffer)

[vc-shrink-buffer.patch (text/x-diff, inline)]
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index ba94d908d1..7b710efff7 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -1730,12 +1730,22 @@ vc-switches
       ;; any switches in diff-switches.
       (when (listp switches) switches))))
 
+(defun vc-shrink-buffer (&optional buffer)
+  "Call `shrink-window-if-larger-than-buffer' only when BUFFER is visible.
+BUFFER defaults to the current buffer."
+  (let ((window (get-buffer-window buffer t)))
+    (when window
+      (shrink-window-if-larger-than-buffer window))))
+
+(defvar vc-diff-finish-functions '(vc-shrink-buffer)
+  "Functions run at the end of the diff command.
+Each function runs in the diff output buffer without args.")
+
 (defun vc-diff-finish (buffer messages)
   ;; The empty sync output case has already been handled, so the only
   ;; possibility of an empty output is for an async process.
   (when (buffer-live-p buffer)
-    (let ((window (get-buffer-window buffer t))
-	  (emptyp (zerop (buffer-size buffer))))
+    (let ((emptyp (zerop (buffer-size buffer))))
       (with-current-buffer buffer
 	(and messages emptyp
 	     (let ((inhibit-read-only t))
@@ -1744,8 +1754,7 @@ vc-diff-finish
 	(diff-setup-whitespace)
 	(diff-setup-buffer-type)
 	(goto-char (point-min))
-	(when window
-	  (shrink-window-if-larger-than-buffer window)))
+	(run-hooks 'vc-diff-finish-functions))
       (when (and messages (not emptyp))
 	(message "%sdone" (car messages))))))
 
@@ -2498,6 +2507,10 @@ vc-log-view-type
 (put 'vc-log-view-type 'permanent-local t)
 (defvar vc-sentinel-movepoint)
 
+(defvar vc-log-finish-functions '(vc-shrink-buffer)
+  "Functions run at the end of the log command.
+Each function runs in the log output buffer without args.")
+
 (defun vc-log-internal-common (backend
 			       buffer-name
 			       files
@@ -2529,11 +2542,11 @@ vc-log-internal-common
     (vc-run-delayed
      (let ((inhibit-read-only t))
        (funcall setup-buttons-func backend files retval)
-       (shrink-window-if-larger-than-buffer)
        (when goto-location-func
          (funcall goto-location-func backend)
          (setq vc-sentinel-movepoint (point)))
-       (set-buffer-modified-p nil)))))
+       (set-buffer-modified-p nil)
+       (run-hooks 'vc-log-finish-functions)))))
 
 (defun vc-incoming-outgoing-internal (backend remote-location buffer-name type)
   (vc-log-internal-common

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#52855; Package emacs. (Tue, 28 Dec 2021 23:55:02 GMT) Full text and rfc822 format available.

Message #8 received at 52855 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Juri Linkov <juri <at> linkov.net>, 52855 <at> debbugs.gnu.org
Subject: Re: bug#52855: vc-shrink-buffer
Date: Wed, 29 Dec 2021 01:53:26 +0200
On 28.12.2021 21:29, Juri Linkov wrote:
> When no shrink is needed, two new hooks are added in this patch
> with the default value containing vc-shrink-buffer to preserve
> the current behavior that can be easily removed in user configuration
> by e.g.:
> 
>    (remove-hook 'vc-diff-finish-functions 'vc-shrink-buffer)
>    (remove-hook 'vc-log-finish-functions 'vc-shrink-buffer)

So the idea is to allow customizing this behavior off?

For those users who don't see the benefits?

LGTM.




Added tag(s) patch. Request was from Stefan Kangas <stefan <at> marxist.se> to control <at> debbugs.gnu.org. (Wed, 29 Dec 2021 00:11:01 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#52855; Package emacs. (Wed, 29 Dec 2021 08:30:02 GMT) Full text and rfc822 format available.

Message #13 received at 52855 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Dmitry Gutov <dgutov <at> yandex.ru>
Cc: 52855 <at> debbugs.gnu.org
Subject: Re: bug#52855: vc-shrink-buffer
Date: Wed, 29 Dec 2021 10:23:08 +0200
>> When no shrink is needed, two new hooks are added in this patch
>> with the default value containing vc-shrink-buffer to preserve
>> the current behavior that can be easily removed in user configuration
>> by e.g.:
>>    (remove-hook 'vc-diff-finish-functions 'vc-shrink-buffer)
>>    (remove-hook 'vc-log-finish-functions 'vc-shrink-buffer)
>
> So the idea is to allow customizing this behavior off?
>
> For those users who don't see the benefits?

What for one is a benefit, for others is an annoyance.

> LGTM.

Before pushing I only have a doubt about 'vc-shrink-buffer'.
Currently it's a wrapper around 'shrink-window-if-larger-than-buffer'
that has nothing to do with vc:

  (defun vc-shrink-buffer (&optional buffer)
    "Call `shrink-window-if-larger-than-buffer' only when BUFFER is visible.
  BUFFER defaults to the current buffer."
    (let ((window (get-buffer-window buffer t)))
      (when window
        (shrink-window-if-larger-than-buffer window))))

Maybe it should be in window.el and renamed to

  shrink-buffer-if-larger-than-buffer




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#52855; Package emacs. (Wed, 29 Dec 2021 15:48:01 GMT) Full text and rfc822 format available.

Message #16 received at 52855 <at> debbugs.gnu.org (full text, mbox):

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: Juri Linkov <juri <at> linkov.net>
Cc: 52855 <at> debbugs.gnu.org
Subject: Re: bug#52855: vc-shrink-buffer
Date: Wed, 29 Dec 2021 17:45:48 +0200
On 29.12.2021 11:23, Juri Linkov wrote:
> Maybe it should be in window.el and renamed to
> 
>    shrink-buffer-if-larger-than-buffer

Depends on whether we have similar code anywhere in Emacs, I guess? So 
it can reuse the new function.




Forcibly Merged 36859 51062 52855. Request was from Juri Linkov <juri <at> linkov.net> to control <at> debbugs.gnu.org. (Wed, 29 Dec 2021 17:33:03 GMT) Full text and rfc822 format available.

bug marked as fixed in version 29.0.50, send any further explanations to 51062 <at> debbugs.gnu.org and Juri Linkov <juri <at> linkov.net> Request was from Juri Linkov <juri <at> linkov.net> to control <at> debbugs.gnu.org. (Tue, 11 Jan 2022 17:37:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 09 Feb 2022 12:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 76 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.