From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: martin rudalics Newsgroups: gmane.emacs.devel Subject: Re: Patch proposal: display symbol source code in help buffers Date: Sun, 26 Sep 2021 11:10:41 +0200 Message-ID: <44953054-5913-e501-d776-0e981bc24031@gmx.at> References: <83bl4n3hys.fsf@gnu.org> <87fstz3g6z.fsf@no.workgroup> <9ada9a31-4e44-7941-e9a2-ada86ba4e36e@gmx.at> <3438b87f-b24a-3bc3-871f-84818868d445@gmx.at> <87lf3q2ahs.fsf@mail.linkov.net> <87ilys28kp.fsf@mail.linkov.net> <61e73f21-5922-52f3-6655-463dd0eb20c5@gmx.at> <139ba228-b232-4844-bd21-0a434b6863f1@gmx.at> <87wnn7qowc.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------EC2406899FBDCF94B2F1370D" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12265"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Arthur Miller , emacs-devel@gnu.org To: Juri Linkov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Sep 26 11:16:18 2021 Return-path: Envelope-to: ged-emacs-devel@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 1mUQGg-00032b-AR for ged-emacs-devel@m.gmane-mx.org; Sun, 26 Sep 2021 11:16:18 +0200 Original-Received: from localhost ([::1]:43508 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mUQGf-0000pQ-9A for ged-emacs-devel@m.gmane-mx.org; Sun, 26 Sep 2021 05:16:17 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51884) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mUQBN-0001u4-Oh for emacs-devel@gnu.org; Sun, 26 Sep 2021 05:10:49 -0400 Original-Received: from mout.gmx.net ([212.227.17.20]:37305) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mUQBK-0005WZ-QJ for emacs-devel@gnu.org; Sun, 26 Sep 2021 05:10:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=badeba3b8450; t=1632647443; bh=q+CvOAXwMP1mx2vy0jIdtST2JL5qOxpFOiLKI1Gc44A=; h=X-UI-Sender-Class:Subject:To:Cc:References:From:Date:In-Reply-To; b=CfUVZca6enU6Nlhgw6f5JNoKQJw5Q5/V4uTyBZZWXhdSVbRsXIHeY6GVOPETu9e/m sUmExPFLVxjT34nZf63Pehlu+yxkGrrCvA+JyD7DwneTXdAe8cqeNjKb+hM5t5vXw5 D8LGirVQiXSbD+x0BOamohmb7kRdYP9txK0WvG1k= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from [192.168.1.101] ([212.95.5.179]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1M3UV8-1mUyPY478M-000cBR; Sun, 26 Sep 2021 11:10:43 +0200 In-Reply-To: <87wnn7qowc.fsf@mail.linkov.net> Content-Language: en-US X-Provags-ID: V03:K1:3k7zj0NNKlN8Uj9skCk9oF3esJwp4wP+ms/HGVgHKnCv2z1IGCF UvENGgFrclkMZ/joYHKbTsqOpRs2UQVr/uFxwohJwiIlj8OceyErb0CyXxBP/vIGdJVUviq sqciGU4I8RE3MEqEDs99shKq5ii5wL4YCO6A62ZUkfUOVGP1kU78F+0lM+Al+81QXp3PZx0 qPziajE4FcheU/6J66rJw== X-UI-Out-Filterresults: notjunk:1;V03:K0:rpQd4meXQIM=:EzzoGbxh/6YjGTPMjLu5CG 1ZxOBZ7MPqwNLtGQLVYuH6yEsYeeNKY4SJsxO6R4m4xLiylHy35h8EEyfYZfadIlRyHDMwMqZ HDIAomGWGY4F5hr7ZVayEgLSXENwIStEe4G3lzcLFqAMe2cz3oNlWt9kQ48KHdzNp8Xmy7HrB iQsfSPDrvXzYIUGU7JyCjUCdwkcdd2ZOB562hHe1DlPuvqifpqsj+gmC4Eca8WMvClqqUn3t7 ZjkE6bd4SAETazFur+jN6o01bHY8x5Xzfj8jC1j8/V6VvPeooVmvJ78uhfugW/Tj2UmA5jNT3 C2H1aOriaItd543WiUB0ahXJZnvuuyFaPbrsCNnaxJVJGPp2AiYynY6nyav8kWBYJTh02qffV WukOOvA+YBLBOfx8YJTw9zz6PqoinicklJspqi4XjrPYJfUJJWZxUI6nrZAA0qP8KCYRyLStI kW2+Mf3fP2x02JQ/Z+wCsKiXhg9AkP88XOwzLZhihN5d3mYM06rAdfY9xcV/PkIGMrJEtTfl6 I2023H4h8ybh+XIS5QrNq3W1UFdKluNvX7Yr531bHfQB5kK674+SfkmK97LnQ8Dw+4DxBiF/C EMYX8H8+ujq8MNzIqp7UuqzlzLAl/eIH9he9KtnmAouv6PuoxDtR2lHippD2R5QNVhqooNihu ylejWXYuCiiCaLfk0b1aXneVHplujVWsHHKbnXUxPy0KotPDYF07gI0Hez/2VbBGtO7cSdVdu OddCYcN8ABFp44vFgS8icfVGgiE6iZ5DZr9blmn3jAjYlYR+CHZmV/n+6Op4ZBv7RVqE5gRk Received-SPF: pass client-ip=212.227.17.20; envelope-from=rudalics@gmx.at; helo=mout.gmx.net X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001, 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: 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-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:275505 Archived-At: This is a multi-part message in MIME format. --------------EC2406899FBDCF94B2F1370D Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit > I guess this feature has effect when display-buffer-alist is customized > to contain (window-height . nil)? Then I confirm it works, thanks! It's inherently flawed because it works only for 'display-buffer-alist' - I couldn't justify that when documenting it. I attached a patch that addresses that (and fixes some other unrelated bugs). martin --------------EC2406899FBDCF94B2F1370D Content-Type: text/x-patch; name="resize-temp-buffer-window.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="resize-temp-buffer-window.diff" diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index 510efaf271..a5abfdb4c0 100644 =2D-- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi @@ -1334,6 +1334,11 @@ Temporary Displays (@pxref{Resizing Windows}) for resizing. You can specify a different function by customizing the options @code{temp-buffer-max-height} and @code{temp-buffer-max-width} below. + +The effect of this option can be overridden by providing a suitable +@code{window-height}, @code{window-width} or @code{window-size} action +alist entry for @code{display-buffer} (@pxref{Buffer Display Action +Alists}). @end defopt @defopt temp-buffer-max-height diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi index 679744884a..63af4c5fd9 100644 =2D-- a/doc/lispref/windows.texi +++ b/doc/lispref/windows.texi @@ -2924,9 +2924,9 @@ Buffer Display Action Alists selected, if the window chosen by @code{display-buffer} is displayed there. Primarily affected by this are @code{display-buffer-use-some-frame} and -@code{display-buffer-reuse-window}. -@code{display-buffer-pop-up-frame} should be affected as well, but -there is no guarantee that the window manager will comply. +@code{display-buffer-reuse-window}. Ideally, +@code{display-buffer-pop-up-frame} should be affected as well, but there +is no guarantee that the window manager will comply. @vindex window-parameters@r{, a buffer display action alist entry} @item window-parameters @@ -2972,8 +2972,8 @@ Buffer Display Action Alists If the value specifies a function, that function is called with one argument---the chosen window. The function is supposed to adjust the height of the window; its return value is ignored. Suitable functions -are @code{shrink-window-if-larger-than-buffer} and -@code{fit-window-to-buffer}, see @ref{Resizing Windows}. +are @code{fit-window-to-buffer} and +@code{shrink-window-if-larger-than-buffer}, see @ref{Resizing Windows}. @end itemize By convention, the height of the chosen window is adjusted only if the @@ -3007,11 +3007,31 @@ Buffer Display Action Alists width of the window; its return value is ignored. @end itemize -By convention, the width of the chosen window is adjusted only if the -window is part of a horizontal combination (@pxref{Windows and -Frames}) to avoid changing the width of other, unrelated windows. -Also, this entry should be processed under only certain conditions -which are specified right below this list. +@vindex window-size@r{, a buffer display action alist entry} +@item window-size +This entry is a combination of the two preceding ones and can be used to +adjust the chosen window's height and width. Since windows can be +resized in one direction only without affecting other windows, +@code{window-size} is effective only to set up the size of a window +appearing alone on a frame. The value can be one of the following: + +@itemize @bullet +@item +@code{nil} means to leave the size of the chosen window alone. + +@item +A cons cell of two integers specifies the desired total width and height +of the chosen window in lines and columns. It's effect is to adjust the +size of the frame accordingly. + +@item +If the value specifies a function, that function is called with one +argument---the chosen window. The function is supposed to adjust the +size of the window's frame; its return value is ignored. +@end itemize + +This entry should be processed under only certain conditions which are +specified right below this list. @vindex dedicated@r{, a buffer display action alist entry} @item dedicated @@ -3112,6 +3132,14 @@ Buffer Display Action Alists buffer and never was used to show another buffer until it was reused by the current invocation of @code{display-buffer}. +If no @code{window-height}, @code{window-width} or @code{window-size} +entry was specified, the window may still be resized automatically when +the buffer is temporary and @code{temp-buffer-resize-mode} has been +enabled, @ref{Temporary Displays}. In that case, the @sc{cdr} of a +@code{window-height}, @code{window-height} or @code{window-size} entry +can be used to inhibit or override the default behavior of +@code{temp-buffer-resize-mode} for specific buffers or invocations of +@code{display-buffer}. @node Choosing Window Options @subsection Additional Options for Displaying Buffers diff --git a/lisp/help.el b/lisp/help.el index 8f77167040..a5cdc9b786 100644 =2D-- a/lisp/help.el +++ b/lisp/help.el @@ -1589,10 +1589,16 @@ temp-buffer-resize-mode (add-hook 'temp-buffer-show-hook 'resize-temp-buffer-window 'append= ) (remove-hook 'temp-buffer-show-hook 'resize-temp-buffer-window))) +(defvar resize-temp-buffer-window-inhibit nil + "Non-nil means `resize-temp-buffer-window' should not resize.") + (defun resize-temp-buffer-window (&optional window) "Resize WINDOW to fit its contents. WINDOW must be a live window and defaults to the selected one. -Do not resize if WINDOW was not created by `display-buffer'. +Do not resize if WINDOW was not created by `display-buffer'. Do +not resize either if a `window-height', `window-width' or +`window-size' entry in `display-buffer-alist' prescribes some +alternative resizing for WINDOW's buffer. If WINDOW is part of a vertical combination, restrain its new size by `temp-buffer-max-height' and do not resize if its minimum @@ -1607,27 +1613,33 @@ resize-temp-buffer-window This function may call `preserve-window-size' to preserve the size of WINDOW." (setq window (window-normalize-window window t)) - (let ((height (if (functionp temp-buffer-max-height) + (let* ((buffer (window-buffer window)) + (height (if (functionp temp-buffer-max-height) + (with-selected-window window + (funcall temp-buffer-max-height buffer)) + temp-buffer-max-height)) + (width (if (functionp temp-buffer-max-width) (with-selected-window window - (funcall temp-buffer-max-height (window-buffer))) - temp-buffer-max-height)) - (width (if (functionp temp-buffer-max-width) - (with-selected-window window - (funcall temp-buffer-max-width (window-buffer))) - temp-buffer-max-width)) - (quit-cadr (cadr (window-parameter window 'quit-restore)))) - ;; Resize WINDOW iff it was made by `display-buffer'. + (funcall temp-buffer-max-width buffer)) + temp-buffer-max-width)) + (quit-cadr (cadr (window-parameter window 'quit-restore)))) + ;; Resize WINDOW only if it was made by `display-buffer'. (when (or (and (eq quit-cadr 'window) (or (and (window-combined-p window) (not (eq fit-window-to-buffer-horizontally 'only)) - (pos-visible-in-window-p (point-min) window)) + (pos-visible-in-window-p + (with-current-buffer buffer (point-min)) + window) + (not resize-temp-buffer-window-inhibit)) (and (window-combined-p window t) - fit-window-to-buffer-horizontally))) + fit-window-to-buffer-horizontally + (not resize-temp-buffer-window-inhibit)))) (and (eq quit-cadr 'frame) fit-frame-to-buffer - (eq window (frame-root-window window)))) - (fit-window-to-buffer window height nil width nil t)))) + (eq window (frame-root-window window)) + (not resize-temp-buffer-window-inhibit))) + (fit-window-to-buffer window height nil width nil t)))) ;;; Help windows. (defcustom help-window-select nil diff --git a/lisp/window.el b/lisp/window.el index b240b16f24..0eb26b0644 100644 =2D-- a/lisp/window.el +++ b/lisp/window.el @@ -108,11 +108,15 @@ temp-buffer-window-setup ;; Return the buffer. buffer))) +;; Defined in help.el. +(defvar resize-temp-buffer-window-inhibit) + (defun temp-buffer-window-show (buffer &optional action) "Show temporary buffer BUFFER in a window. Return the window showing BUFFER. Pass ACTION as action argument to `display-buffer'." - (let (window frame) + (let ((resize-temp-buffer-window-inhibit nil) + window) (with-current-buffer buffer (set-buffer-modified-p nil) (setq buffer-read-only t) @@ -130,9 +134,9 @@ temp-buffer-window-show t window-combination-limit))) (setq window (display-buffer buffer action))) - (setq frame (window-frame window)) - (unless (eq frame (selected-frame)) - (raise-frame frame)) + ;; We used to raise the window's frame here. Do not do that + ;; since it would override an `inhibit-switch-frame' entry + ;; specified for the action alist used by `display-buffer'. (setq minibuffer-scroll-window window) (set-window-hscroll window 0) (with-selected-window window @@ -7245,11 +7249,14 @@ window--display-buffer (inhibit-modification-hooks t)) (funcall (cdr (assq 'body-function alist)) window))) - (let ((quit-restore (window-parameter window 'quit-restore)) - (height (cdr (assq 'window-height alist))) - (width (cdr (assq 'window-width alist))) - (size (cdr (assq 'window-size alist))) - (preserve-size (cdr (assq 'preserve-size alist)))) + (let* ((quit-restore (window-parameter window 'quit-restore)) + (window-height (assq 'window-height alist)) + (height (cdr window-height)) + (window-width (assq 'window-width alist)) + (width (cdr window-width)) + (window-size (assq 'window-size alist)) + (size (cdr window-size)) + (preserve-size (cdr (assq 'preserve-size alist)))) (cond ((or (eq type 'frame) (and (eq (car quit-restore) 'same) @@ -7266,14 +7273,18 @@ window--display-buffer (height (cdr size)) (frame (window-frame window))) (when (and (numberp width) (numberp height)) - (set-frame-height - frame (+ (frame-height frame) - (- height (window-total-height window)))) - (set-frame-width - frame (+ (frame-width frame) - (- width (window-total-width window))))))) + ;; Modifying the parameters of a newly created frame might + ;; not work everywhere, but then `temp-buffer-resize-mode' + ;; will certainly fail in a similar fashion. + (modify-frame-parameters + frame `((height . ,(+ (frame-height frame) + (- height (window-total-height window)))) + (width . ,(+ (frame-width frame) + (- width (window-total-width window)))))))) + (setq resize-temp-buffer-window-inhibit t)) ((functionp size) - (ignore-errors (funcall size window))))) + (ignore-errors (funcall size window)) + (setq resize-temp-buffer-window-inhibit t)))) ((or (eq type 'window) (and (eq (car quit-restore) 'same) (eq (nth 1 quit-restore) 'window))) @@ -7293,9 +7304,11 @@ window--display-buffer (delta (- new-height (window-total-height window)))) (when (and (window--resizable-p window delta nil 'safe) (window-combined-p window)) - (window-resize window delta nil 'safe)))) + (window-resize window delta nil 'safe))) + (setq resize-temp-buffer-window-inhibit 'vertical)) ((functionp height) - (ignore-errors (funcall height window)))) + (ignore-errors (funcall height window)) + (setq resize-temp-buffer-window-inhibit 'vertical))) ;; Adjust width of window if asked for. (cond ((not width)) @@ -7309,9 +7322,11 @@ window--display-buffer (delta (- new-width (window-total-width window)))) (when (and (window--resizable-p window delta t 'safe) (window-combined-p window t)) - (window-resize window delta t 'safe)))) + (window-resize window delta t 'safe))) + (setq resize-temp-buffer-window-inhibit 'horizontal)) ((functionp width) - (ignore-errors (funcall width window)))) + (ignore-errors (funcall width window)) + (setq resize-temp-buffer-window-inhibit 'horizontal))) ;; Preserve window size if asked for. (when (consp preserve-size) (window-preserve-size window t (car preserve-size)) @@ -7556,9 +7571,11 @@ display-buffer Action alist entries are: `inhibit-same-window' -- A non-nil value prevents the same window from being used for display. - `inhibit-switch-frame' -- A non-nil value prevents any frame - used for showing the buffer from being raised or selected. - `reusable-frames' -- The value specifies the set of frames to +`inhibit-switch-frame' -- A non-nil value prevents any frame used + for showing the buffer from being raised or selected. Note + that a window manager may still raise a new frame and give it + focus, effectively overriding the value specified here. +`reusable-frames' -- The value specifies the set of frames to search for a window that already displays the buffer. Possible values are nil (the selected frame), t (any live frame), visible (any visible frame), 0 (any visible or @@ -7581,7 +7598,16 @@ display-buffer window) or a function to be called with one argument - the chosen window. The function is supposed to adjust the width of the window; its return value is ignored. - `preserve-size' -- The value should be either (t . nil) to + + `window-size' -- This entry is only useful for windows appearing + alone on their frame and specifies the desired size of that + window either as a cons of integers (the total width and + height of the window on that frame), or a function to be + called with one argument - the chosen window. The function + is supposed to adjust the size of the frame; its return value + is ignored. + +`preserve-size' -- The value should be either (t . nil) to preserve the width of the chosen window, (nil . t) to preserve its height or (t . t) to preserve its height and width in future changes of the window configuration. --------------EC2406899FBDCF94B2F1370D--