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: master 18b680cfd1: Fix bug#52467 by adding a new custom variable 'display-comint-buffer-action' Date: Thu, 6 Jan 2022 16:30:57 +0100 Message-ID: References: <164073060906.21430.4993248796177370312@vcs2.savannah.gnu.org> <20211228223009.6D0BAC002EE@vcs2.savannah.gnu.org> <871r1v8nhf.fsf@gnus.org> <83ilv7jqm7.fsf@gnu.org> <6a9cd581-1630-4a95-62c4-419603561072@gmx.at> <3499cedf-b170-3045-873d-d45d2972ae13@gmx.at> <0f492ac4-4167-5448-2c74-a5f67950eae4@yandex.ru> <2de2323b-6d34-9263-776b-dbeff036f8f4@gmx.at> <87zgog68ni.fsf@gnus.org> <8dfc6f22-d331-e7c1-b536-2d374197528f@gmx.at> <86v8z26o15.fsf@mail.linkov.net> <9d5f512f-dd10-fb6b-2fe7-db24ed92f7c8@gmx.at> <86y23xuv8g.fsf@mail.linkov.net> <867dbgtuls.fsf@mail.linkov.net> <7402a9b1-91cf-a14e-32dc-e9a0cd27dd82@gmx.at> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------4FF20C26BA7AC34D630A93AF" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38667"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Lars Ingebrigtsen , Dmitry Gutov , Eli Zaretskii , sdsg@amazon.com, emacs-devel@gnu.org To: Juri Linkov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Jan 06 16:35:29 2022 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 1n5UnZ-0009oM-Cw for ged-emacs-devel@m.gmane-mx.org; Thu, 06 Jan 2022 16:35:29 +0100 Original-Received: from localhost ([::1]:52696 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n5UnX-0007Wv-1p for ged-emacs-devel@m.gmane-mx.org; Thu, 06 Jan 2022 10:35:27 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:49150) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n5UjN-0003iI-Hh for emacs-devel@gnu.org; Thu, 06 Jan 2022 10:31:11 -0500 Original-Received: from mout.gmx.net ([212.227.15.15]:44713) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n5UjJ-00083m-M3; Thu, 06 Jan 2022 10:31:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1641483060; bh=TzyrFDBI2fFuOiztAMMUAgfo18W0kL2QLfqrihPDMY8=; h=X-UI-Sender-Class:Subject:From:To:Cc:References:Date:In-Reply-To; b=Np8eI6qdt42AaTLa0OAdMS9c1+wf6sGqRAIFbp9AerfRoQXQHGK8wJ0nD33QN12Ru FRNiAkmprymW1vZQlfgdrOhfXofzwBveTxuQDnolm9WJOq6ZiclyW8lkyXf/sf0OzS Kkbd0C6qjOGmJX7mXL/aSRCtuUfRAsYMNnemRt7k= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from [192.168.1.102] ([212.95.5.75]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MKbkM-1mp3oF2fJU-00L0Nr; Thu, 06 Jan 2022 16:30:59 +0100 In-Reply-To: <7402a9b1-91cf-a14e-32dc-e9a0cd27dd82@gmx.at> Content-Language: en-US X-Provags-ID: V03:K1:Oa0kwXfHoS6hw9STm/spvIc2yQs/w3eqqLbSiQ1NB9nC18v3j6S 6Gc7UrTRPKUdTwDHwOO8EOiME8dhVYPKbiTMfg16AyucXxLaB3xQKQg+sMvwBbhTFqW7bmZ bv+PLtnN3U4DVQLvlNcy5AugP0qnqsaPHKcDCbjmSlTYwBTg8Ql1ouwmXCmgorCjGmGePS+ ALc7IevB+p6JVXLaxsT5A== X-UI-Out-Filterresults: notjunk:1;V03:K0:AavFg65rebA=:kxnKbcdciR1F8a1UhtQ0QS +te6nSISl2uvaV01OMg+wE9gYgsWgvRA+pgqYxT8YKSVEHTjwazNiEZixdsvT+jul+IFg/R1s UY5BbTb2TnJczbd2SDCALDasVLsckrJjMT2hRUWpyLxVy5qia5NYK1nWMckx16gk1pXfL6qcV QvpVZm83+35Fjhov+pJlQnF+/SfesfzGshLtJ1qJjtb68soExoNaVVIFtci5wv4oUa/GUvrB0 K2hWbNg9ASAJn0qmmlmWN07v6yqSZ4WMSASusXx2KEHOJkZfBpd+a6LNgDU8nSWb7lbVYbU34 cT3XvMvVie/kXJoWnH3PsM2Tyfof4HzFs8Q+SOBpYjSJUOA6yqqEv2so/KNN8gFBT2UcNaXnV KrkkeJ6kI0Q3I+BzktFAKSr1sO5qvcvrTfuHG43FHGE7sVCqJtpsysuIxNfTZa7+cas6yQaXo cEIhcKkEikFwXznehlLrjOplrFoA9JqxkQgIDEv7GD+TI/PUJdTAbRYiG7yA3w8K4FGk48dv7 Yx94D9wXAcFnShNthazTsvtz4rtagIWTKZK6myNY9XCJ0C44DbSVDB2Y/XYcSdnxwey9FVVpg CkzIGOa0wAKT2qGX/gzpr82wpEHBaSSj9K03VmwFoMY34WtJHPIvtcGO0fru2773Aq1YEiLZk MhIgIF2CpXbX4YEt0v6hGUjj3Op5AkmNwsfUp9bGoo/cNo6mW8MUhwWslRuD8nOz44KIE631O Bq1TcRdetuDjdKm0Cmor8mob1a/H7qqsrSHyUhlkgNhM8iOrFROarkjN3azxwdry4zy2o07W Received-SPF: pass client-ip=212.227.15.15; envelope-from=rudalics@gmx.at; helo=mout.gmx.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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-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.29 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:284328 Archived-At: This is a multi-part message in MIME format. --------------4FF20C26BA7AC34D630A93AF Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit > IIRC I once used the term 'label' for it. It vanished soon. After trying to implement this idea I immediately started to dislike it for technical reasons ('pop-to-buffer-same-window' never had an ACTION argument so I had to invent some clumsy extra argument to make things work). I attach the diffs in case we still want to implement something the like. Otherwise, I think that harm has been done - 'pop-to-buffer-same-window' was invented as stand-in for 'switch-to-buffer' and should never have replaced 'pop-to-buffer' - but I missed that back then so I'm not in a good position to ask for reverting that change now. Sam's patch, although it does not restore the previous behavior, still looks like the least obtrusive solution in this regard. It's partially a misnomer - to my knowledge at least 'eshell' has no connection to "comint" - so we apparently cannot put 'display-comint-buffer-action' into comint.el where it would belong. Yet I'd tend to keep it, after applying Morgan's fix from Bug#52878, obviously. martin --------------4FF20C26BA7AC34D630A93AF Content-Type: text/x-patch; name="display-buffer-label.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="display-buffer-label.diff" diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi index 6d156ef861..dd09ddf931 100644 =2D-- a/doc/lispref/windows.texi +++ b/doc/lispref/windows.texi @@ -2969,7 +2969,7 @@ Switching Buffers @code{display-buffer} will affect it as well. @xref{Choosing Window}, for the documentation of @code{display-buffer}. -@deffn Command pop-to-buffer buffer-or-name &optional action norecord +@deffn Command pop-to-buffer buffer-or-name &optional action norecord lab= el This function makes @var{buffer-or-name} the current buffer and displays it in some window, preferably not the window currently selected. It then selects the displaying window. If that window is @@ -2990,6 +2990,9 @@ Switching Buffers window other than the selected one---even if the buffer is already displayed in the selected window. +If @var{label} is non-@code{nil}, it should specify the name of a buffer +display label and is passed on unaltered to @code{display-buffer}. + Like @code{switch-to-buffer}, this function updates the buffer list unless @var{norecord} is non-@code{nil}. @end deffn @@ -3065,7 +3068,7 @@ Choosing Window of them manages to display the buffer and returns a non-@code{nil} value. -@deffn Command display-buffer buffer-or-name &optional action frame +@deffn Command display-buffer buffer-or-name &optional action frame label This command makes @var{buffer-or-name} appear in some window, without selecting the window or making the buffer current. The argument @var{buffer-or-name} must be a buffer or the name of an existing @@ -3139,6 +3142,11 @@ Choosing Window . @var{frame})}} to the action alist of @var{action} (@pxref{Buffer Display Action Alists}). The @var{frame} argument is provided for compatibility reasons, Lisp programs should not use it. + +The optional argument @var{label}, if non-@code{nil}, should specify the +name of a buffer display label (@pxref{Buffer Display Action Alists}) +and is prepended as a cons of that name and the value @code{t} to the +action alist specified of @var{action}. @end deffn @defvar display-buffer-overriding-action @@ -3150,11 +3158,15 @@ Choosing Window @defopt display-buffer-alist The value of this option is an alist mapping conditions to display actions. Each condition may be either a regular expression matching a -buffer name or a function that takes two arguments: a buffer name and -the @var{action} argument passed to @code{display-buffer}. If either -the name of the buffer passed to @code{display-buffer} matches a -regular expression in this alist, or the function specified by a -condition returns non-@code{nil}, then @code{display-buffer} uses the +buffer name; a function that takes two arguments: a buffer name and the +@var{action} argument passed to @code{display-buffer}; or a symbol +naming a buffer display label (@pxref{Buffer Display Action Alists}). + +If either the name of the buffer passed to @code{display-buffer} matches +a regular expression in this alist, the function specified by a +condition returns non-@code{nil}, or the symbol specified by a condition +has a non-nil association found via @code{eq} in the action alist passed +to @code{display-buffer}, then @code{display-buffer} uses the corresponding display action to display the buffer. @end defopt @@ -3770,7 +3782,7 @@ 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} + 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 @@ -3779,6 +3791,45 @@ Buffer Display Action Alists @code{temp-buffer-resize-mode} for specific buffers or invocations of @code{display-buffer}. +@cindex buffer display label + In addition, action alists may contain @dfn{buffer display label}s - +entries handled and passed on by @code{display-buffer} as described +above. The @sc{car} of a label - a symbol - is the label's name and its +@sc{cdr} is its value. If that value is non-@code{nil}, it will advise +@code{display-buffer} to handle this call specially, provided it finds a +matching entry in @code{display-buffer-alist}. + + If, for example, a call to @code{pop-to-buffer} is coded as + +@example +(pop-to-buffer "foo" '(nil . ((*foo* . t)))) +@end example + +@noindent +specifying a label named @code{*foo*} whose value is @code{t} and +@code{display-buffer-alist} was customized as + +@example +@group +(customize-set-variable + 'display-buffer-alist + '((*foo* display-buffer-same-window (nil)))) +@end group +@end example + +@noindent +then @code{display-buffer} will try to pop to @code{foo} in the selected +window and not in a new window as originally proposed by +@code{pop-to-buffer}. + + Lisp programmers should be careful when choosing the name for a buffer +display label to avoid that it matches any of the other entries +mentioned in this section (including entries that may be added to it in +the future) or the name of a function that could be used as condition in +@code{display-buffer-alist}. In our example, the use of asterisks in +@code{*foo*} is an attempt to avoid such confusions. + + @node Choosing Window Options @subsection Additional Options for Displaying Buffers diff --git a/lisp/window.el b/lisp/window.el index 57861b091f..7f9983b998 100644 =2D-- a/lisp/window.el +++ b/lisp/window.el @@ -8169,9 +8169,10 @@ display-buffer-alist If non-nil, this is an alist of elements (CONDITION . ACTION), where: - CONDITION is either a regexp matching buffer names, or a - function that takes two arguments - a buffer name and the - ACTION argument of `display-buffer' - and returns a boolean. + CONDITION is either a regexp matching buffer names; a function + that takes two arguments - a buffer name and the ACTION + argument of `display-buffer' - and returns a boolean; or a + symbol that is interpreted as a label. ACTION is a cons cell (FUNCTIONS . ALIST), where FUNCTIONS is an action function or a list of action functions and ALIST is an @@ -8180,13 +8181,16 @@ display-buffer-alist ALIST. See `display-buffer' for details. `display-buffer' scans this alist until it either finds a -matching regular expression or the function specified by a -condition returns non-nil. In any of these cases, it adds the -associated action to the list of actions it will try." +matching regular expression, the function specified by a +condition returns non-nil, or the label specified by a condition +has an non-nil association found via `eq' in the action alist +passed to this `display-buffer' call. In any of these cases, it +adds the associated action to the list of actions it will try." :type `(alist :key-type (choice :tag "Condition" regexp - (function :tag "Matcher function")) + (function :tag "Matcher function") + (symbol :tag "Label")) :value-type ,display-buffer--action-custom-type) :risky t :version "24.1" @@ -8238,15 +8242,21 @@ display-buffer-assq-regexp is a string that matches BUFFER-NAME, as reported by `string-match-p'; or if the key is a function that returns non-nil when called with three arguments: the ALIST key, -BUFFER-NAME and ACTION. ACTION should have the form of the -action argument passed to `display-buffer'." +BUFFER-NAME and ACTION; or if the key is a symbol for which +'assq' finds an non-nil association in the action alist specified +by ACTION. + +ACTION should have the form of the action argument passed to +`display-buffer'." (catch 'match (dolist (entry alist) (let ((key (car entry))) (when (or (and (stringp key) (string-match-p key buffer-name)) (and (functionp key) - (funcall key buffer-name action))) + (funcall key buffer-name action)) + (and (symbolp key) + (cdr (assq key (cdr action))))) (throw 'match (cdr entry))))))) (defvar display-buffer--same-window-action @@ -8266,7 +8276,7 @@ display-buffer--other-frame-action fails, call `display-buffer-pop-up-frame'.") (put 'display-buffer--other-frame-action 'risky-local-variable t) -(defun display-buffer (buffer-or-name &optional action frame) +(defun display-buffer (buffer-or-name &optional action frame label) "Display BUFFER-OR-NAME in some window, without selecting it. To change which window is used, set `display-buffer-alist' to an expression containing one of these \"action\" functions: @@ -8390,6 +8400,13 @@ display-buffer `preserve-size' are applied only when the window used for displaying the buffer never showed another buffer before. +An action alist entry may also specify a buffer display label - a +cons cell whose car specifies the name of the label and whose cdr +its value. If `display-buffer-alist' contains an member whose +car names that label and the value of that label is non-nil, the +cdr of the `display-buffer-alist' specifies the action to +perform. + The ACTION argument can also have a non-nil and non-list value. This means to display the buffer in a window other than the selected one, even if it is already displayed in the selected @@ -8398,12 +8415,14 @@ display-buffer The optional third argument FRAME, if non-nil, acts like a \(reusable-frames . FRAME) entry appended to the action alist -specified by the ACTION argument." +specified by the ACTION argument. + +The optional argument LABEL, if non-nil, specifies the name of a +buffer display label and is prepended as a cons of that name and +the value t to the action alist." (interactive (list (read-buffer "Display buffer: " (other-buffer)) (if current-prefix-arg t))) - (let ((buffer (if (bufferp buffer-or-name) - buffer-or-name - (get-buffer buffer-or-name))) + (let ((buffer (get-buffer buffer-or-name)) ;; Make sure that when we split windows the old window keeps ;; point, bug#14829. (split-window-keep-point t) @@ -8416,7 +8435,10 @@ display-buffer ;; Otherwise, use the defined actions. (let* ((user-action (display-buffer-assq-regexp - (buffer-name buffer) display-buffer-alist action)) + (buffer-name buffer) display-buffer-alist + (if label + (cons (car action) (cons `(,label . t) (cdr action))) + action))) (special-action (display-buffer--special-action buffer)) ;; Extra actions from the arguments to this function: (extra-action @@ -9288,7 +9310,7 @@ display-buffer-no-window 'fail)) ;;; Display + selection commands: -(defun pop-to-buffer (buffer-or-name &optional action norecord) +(defun pop-to-buffer (buffer-or-name &optional action norecord label) "Display buffer specified by BUFFER-OR-NAME and select its window. BUFFER-OR-NAME may be a buffer, a string (a buffer name), or nil. If it is a string not naming an existent buffer, create a buffer @@ -9307,12 +9329,15 @@ pop-to-buffer input focus. Optional third arg NORECORD non-nil means do not put this buffer -at the front of the list of recently selected ones." +at the front of the list of recently selected ones. + +Optional fourth argument LABEL, if non-nil, must specify the name of a +buffer display label and is passed on to `display-buffer'." (interactive (list (read-buffer "Pop to buffer: " (other-buffer)) (if current-prefix-arg t))) (let* ((buffer (window-normalize-buffer-to-switch-to buffer-or-name)) (old-frame (selected-frame)) - (window (display-buffer buffer action))) + (window (display-buffer buffer action nil label))) ;; Don't assume that `display-buffer' has supplied us with a window ;; (Bug#24332). (if window @@ -9328,7 +9353,7 @@ pop-to-buffer ;; Return BUFFER even when we got no window. buffer)) -(defun pop-to-buffer-same-window (buffer &optional norecord) +(defun pop-to-buffer-same-window (buffer &optional norecord label) "Select buffer BUFFER in some window, preferably the same one. BUFFER may be a buffer, a string (a buffer name), or nil. If it is a string not naming an existent buffer, create a buffer with @@ -9338,6 +9363,9 @@ pop-to-buffer-same-window Optional argument NORECORD, if non-nil means do not put this buffer at the front of the list of recently selected ones. +Optional fourth argument LABEL, if non-nil, must specify the name +of a buffer display label and is passed on to `pop-to-buffer'. + Unlike `pop-to-buffer', this function prefers using the selected window over popping up a new window or frame. Specifically, if the selected window is neither a minibuffer window (as reported @@ -9345,7 +9373,8 @@ pop-to-buffer-same-window (see `window-dedicated-p'), BUFFER will be displayed in the currently selected window; otherwise it will be displayed in another window." - (pop-to-buffer buffer display-buffer--same-window-action norecord)) + (pop-to-buffer + buffer display-buffer--same-window-action norecord label)) (defun read-buffer-to-switch (prompt) "Read the name of a buffer to switch to, prompting with PROMPT. --------------4FF20C26BA7AC34D630A93AF--