unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#52855: vc-shrink-buffer
@ 2021-12-28 18:29 Juri Linkov
  2021-12-28 23:53 ` Dmitry Gutov
  0 siblings, 1 reply; 4+ messages in thread
From: Juri Linkov @ 2021-12-28 18:29 UTC (permalink / raw)
  To: 52855

[-- Attachment #1: Type: text/plain, Size: 327 bytes --]

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)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: vc-shrink-buffer.patch --]
[-- Type: text/x-diff, Size: 2374 bytes --]

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#52855: vc-shrink-buffer
  2021-12-28 18:29 bug#52855: vc-shrink-buffer Juri Linkov
@ 2021-12-28 23:53 ` Dmitry Gutov
  2021-12-29  8:23   ` Juri Linkov
  0 siblings, 1 reply; 4+ messages in thread
From: Dmitry Gutov @ 2021-12-28 23:53 UTC (permalink / raw)
  To: Juri Linkov, 52855

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.





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#52855: vc-shrink-buffer
  2021-12-28 23:53 ` Dmitry Gutov
@ 2021-12-29  8:23   ` Juri Linkov
  2021-12-29 15:45     ` Dmitry Gutov
  0 siblings, 1 reply; 4+ messages in thread
From: Juri Linkov @ 2021-12-29  8:23 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: 52855

>> 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





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#52855: vc-shrink-buffer
  2021-12-29  8:23   ` Juri Linkov
@ 2021-12-29 15:45     ` Dmitry Gutov
  0 siblings, 0 replies; 4+ messages in thread
From: Dmitry Gutov @ 2021-12-29 15:45 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 52855

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.





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-12-29 15:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-28 18:29 bug#52855: vc-shrink-buffer Juri Linkov
2021-12-28 23:53 ` Dmitry Gutov
2021-12-29  8:23   ` Juri Linkov
2021-12-29 15:45     ` Dmitry Gutov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).