From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#52855: vc-shrink-buffer Date: Tue, 28 Dec 2021 20:29:09 +0200 Organization: LINKOV.NET Message-ID: <867dbosit6.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22550"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu) To: 52855@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Dec 28 19:32:11 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1n2HGc-0005kX-M3 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 28 Dec 2021 19:32:10 +0100 Original-Received: from localhost ([::1]:45332 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n2HGb-0002Sp-HA for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 28 Dec 2021 13:32:09 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:36138) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n2HGU-0002SR-NQ for bug-gnu-emacs@gnu.org; Tue, 28 Dec 2021 13:32:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:35836) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n2HGU-0003iE-Dw for bug-gnu-emacs@gnu.org; Tue, 28 Dec 2021 13:32:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1n2HGU-0007PI-AF for bug-gnu-emacs@gnu.org; Tue, 28 Dec 2021 13:32:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 28 Dec 2021 18:32:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 52855 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.164071630828449 (code B ref -1); Tue, 28 Dec 2021 18:32:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 28 Dec 2021 18:31:48 +0000 Original-Received: from localhost ([127.0.0.1]:47382 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n2HGG-0007On-6R for submit@debbugs.gnu.org; Tue, 28 Dec 2021 13:31:48 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:46988) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1n2HGE-0007Og-M4 for submit@debbugs.gnu.org; Tue, 28 Dec 2021 13:31:46 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:36120) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n2HGE-0002Rx-Ev for bug-gnu-emacs@gnu.org; Tue, 28 Dec 2021 13:31:46 -0500 Original-Received: from relay3-d.mail.gandi.net ([217.70.183.195]:54163) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n2HGC-0003g7-1H for bug-gnu-emacs@gnu.org; Tue, 28 Dec 2021 13:31:45 -0500 Original-Received: (Authenticated sender: juri@linkov.net) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id A29CA60007 for ; Tue, 28 Dec 2021 18:31:38 +0000 (UTC) Received-SPF: pass client-ip=217.70.183.195; envelope-from=juri@linkov.net; helo=relay3-d.mail.gandi.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:223269 Archived-At: --=-=-= Content-Type: text/plain 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) --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=vc-shrink-buffer.patch 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 --=-=-=--