From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: sbaugh@catern.com Newsgroups: gmane.emacs.bugs Subject: bug#64619: [PATCH] Add toggle-window-dedicated command Date: Mon, 21 Aug 2023 13:00:48 +0000 (UTC) Message-ID: <878ra4pn28.fsf@catern.com> References: <87h6ovgnpn.fsf@catern.com> <874jkvvwm2.fsf@posteo.net> <87jztr0zt7.fsf@catern.com> <87zg2nuho0.fsf@posteo.net> <877cpqreat.fsf@catern.com> <83il9axnll.fsf@gnu.org> 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="26183"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: sbaugh@janestreet.com, philipk@posteo.net, rudalics@gmx.at, drew.adams@oracle.com, 64619@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Aug 21 15:02:42 2023 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 1qY4YJ-0006YQ-Vw for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 21 Aug 2023 15:02:40 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qY4Wz-0000tQ-Ng; Mon, 21 Aug 2023 09:01:17 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qY4Wi-0000bz-F2 for bug-gnu-emacs@gnu.org; Mon, 21 Aug 2023 09:01:03 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qY4Wi-0001In-5o for bug-gnu-emacs@gnu.org; Mon, 21 Aug 2023 09:01:00 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qY4Wk-0003w0-0L for bug-gnu-emacs@gnu.org; Mon, 21 Aug 2023 09:01:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: sbaugh@catern.com Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 21 Aug 2023 13:01:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 64619 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 64619-submit@debbugs.gnu.org id=B64619.169262286115107 (code B ref 64619); Mon, 21 Aug 2023 13:01:01 +0000 Original-Received: (at 64619) by debbugs.gnu.org; 21 Aug 2023 13:01:01 +0000 Original-Received: from localhost ([127.0.0.1]:55816 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qY4Wh-0003va-RP for submit@debbugs.gnu.org; Mon, 21 Aug 2023 09:01:00 -0400 Original-Received: from s.wfbtzhsv.outbound-mail.sendgrid.net ([159.183.224.104]:51998) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qY4We-0003vF-Su for 64619@debbugs.gnu.org; Mon, 21 Aug 2023 09:00:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=catern.com; h=from:subject:in-reply-to:references:mime-version:to:cc:content-type: cc:content-type:from:subject:to; s=s1; bh=G5qIsniV2um4SZ7/2XOIipzxHeyF6AxfNSxQZ8c2bYI=; b=Z3Z6ZH1Z+mAYnp5C9ufQFukeonKuZQtMhhvFy/u0OWRcOSEzfZi9ohrJeXnBcwoX6+l7 Kdt03yr1C1IHB8Y/Qr1WvsiH+OaXDrq/2fpuEhHDjy0O6Q99Dj/9KID9MlUbY7xughzDNC J6Tqmkyca0Q+g8X4yHLaM4TBvv6ufYPU9OKffoa1nPJA/KbpUG4x+R7+Xw9a61OBwxpvth HZuAJvm4QXRk+EmLo3eA2ec8Rjx4wWDhR5vQmCJm1JMnWcBRIUKdS5ce1RxIu5No6b5e+Y AE0bCoamLZwWh1Ptl+SRtP4fZuGXfxt5frrh7b4zud7KoAUPiRgzNob3VFzMZRPA== Original-Received: by filterdrecv-canary-6699d5694c-nnmg4 with SMTP id filterdrecv-canary-6699d5694c-nnmg4-1-64E36000-1B 2023-08-21 13:00:48.176952827 +0000 UTC m=+1183456.931318939 Original-Received: from earth.catern.com (unknown) by geopod-ismtpd-9 (SG) with ESMTP id JR1wWO6YRnynd3rVWe4MwQ Mon, 21 Aug 2023 13:00:47.983 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=::1; helo=localhost; envelope-from=sbaugh@catern.com; receiver=gnu.org Original-Received: from localhost (localhost [IPv6:::1]) by earth.catern.com (Postfix) with ESMTPSA id 8924A6016B; Mon, 21 Aug 2023 09:00:47 -0400 (EDT) In-Reply-To: <83il9axnll.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 20 Aug 2023 08:57:26 +0300") X-SG-EID: ZgbRq7gjGrt0q/Pjvxk7wM0yQFRdOkTJAtEbkjCkHbKsY9GtyUQB5ZvOBcg5tTqSXEDVhCW09kgG6W6IoKrBVwyHUPQKDOI1ks/Y2SY0IE5nzfO/qGgWUqK/Xu2MVoGifqLEDzFFHxjmWwD/CcKAEA/kxcpjS4Upviw14jsb5NPiCaDSyjSrKu0bAwlkI+ydAr4nhNXo7P0ee1dTpEwxQW6nYvv6ma05Gvzu7kE/u6k= X-Entity-ID: d/0VcHixlS0t7iB1YKCv4Q== 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:268093 Archived-At: --=-=-= Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Applied Eli's comments and added support for customizing which flag toggle-window-dedicated sets by default. New patch attached. Eli Zaretskii writes: >> From: sbaugh@catern.com >> Date: Sat, 19 Aug 2023 20:02:35 +0000 (UTC) >> Cc: Spencer Baugh , Eli Zaretskii , >> martin rudalics , Drew Adams , >> 64619@debbugs.gnu.org >> + >> +@kindex C-x w d >> +@findex toggle-window-dedicated >> + Toggle whether the current window is dedicated to the current > ^^^^^^^ > "selected", not "current". Or maybe "currently-selected". Selected seems more common than currently-selected so went with that. >> @@ -675,6 +696,7 @@ mode-line-end-spaces >> 'mode-line-modified >> 'mode-line-remote) >> 'display '(min-width (5.0))) >> + 'mode-line-window-dedicated >> 'mode-line-frame-identification >> 'mode-line-buffer-identification >> " " > > Why not add this to the group with the min-width property (and enlarge > that to 6.0)? That way, we prevent annoying horizontal movement of > the rest of the mode-line display when toggling the state. Hm, I tried doing that, but maybe I don't understand min-width, because there's still horizontal movement of the mode-line when I toggle it on and off. I tried various combinations of strings, but they all had this behavior, maybe I'm doing something obviously wrong? Also, if we make it fixed-size in this way, should we display "-" instead of nothing when the window is not dedicated? Or just an empty space? --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Add-toggle-window-dedicated-command-and-mode-line-wi.patch >From b92b7dcb9e8dcb017e69462f8f7e580dba2b8fce Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Sat, 19 Aug 2023 16:01:54 -0400 Subject: [PATCH] Add toggle-window-dedicated command and mode-line-window-dedicated It's sometimes useful to interactively make certain windows dedicated. This allows a level of interactive control over which window display-buffer uses. Additionally, when a window is dedicated (even without this new command) it can affect display-buffer behavior in ways which may be unexpected for users. Let's display the window dedicated status in the mode-line to help indicate what's going on. * doc/emacs/windows.texi (Displaying Buffers): Add information about dedicated windows and toggle-window-dedicated. * doc/emacs/screen.texi (Mode Line): Add information about the window dedicated indicator. * etc/NEWS: Announce mode-line-window-dedicated and toggle-window-dedicated. * lisp/window.el (toggle-window-dedicated): Add. (window-prefix-map): Add C-x w d binding. * lisp/bindings.el (mode-line-window-control): Add. (mode-line-window-dedicated): Add. (standard-mode-line-format): Insert mode-line-window-dedicated. --- doc/emacs/screen.texi | 8 +++++- doc/emacs/windows.texi | 22 +++++++++++++++++ etc/NEWS | 16 ++++++++++++ lisp/bindings.el | 34 ++++++++++++++++++++++++-- lisp/window.el | 55 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 132 insertions(+), 3 deletions(-) diff --git a/doc/emacs/screen.texi b/doc/emacs/screen.texi index 5e9e89e6b11..d4e92c035b8 100644 --- a/doc/emacs/screen.texi +++ b/doc/emacs/screen.texi @@ -173,7 +173,7 @@ Mode Line The text displayed in the mode line has the following format: @example - @var{cs}:@var{ch}-@var{fr} @var{buf} @var{pos} @var{line} (@var{major} @var{minor}) + @var{cs}:@var{ch}-@var{D}@var{fr} @var{buf} @var{pos} @var{line} (@var{major} @var{minor}) @end example @noindent @@ -231,6 +231,12 @@ Mode Line However, if @code{default-directory} (@pxref{File Names}) for the current buffer is on a remote machine, @samp{@@} is displayed instead. + @var{D} appears if the window is dedicated to its current buffer. +It appears as @samp{D} for strong dedication and @samp{d} for other +forms of dedication. If the window is not dedicated, @var{d} does not +appear. @xref{Dedicated Windows,, elisp, The Emacs Lisp Reference +Manual}. + @var{fr} gives the selected frame name (@pxref{Frames}). It appears only on text terminals. The initial frame's name is @samp{F1}. diff --git a/doc/emacs/windows.texi b/doc/emacs/windows.texi index e4abdef76be..b1c36aec426 100644 --- a/doc/emacs/windows.texi +++ b/doc/emacs/windows.texi @@ -411,6 +411,28 @@ Displaying Buffers window on some other frame to display the desired buffer. Several of these commands are bound in the @kbd{C-x 5} prefix key. +@cindex dedicated window + Sometimes, a window is ``dedicated'' to its current buffer +@xref{Dedicated Windows,, elisp, The Emacs Lisp Reference Manual}. +@code{display-buffer} will avoid reusing dedicated windows most of the +time. This is indicated by a ``d'' in the mode line (@pxref{Mode +Line}). A window can also be strongly dedicated, which prevents any +changes to the buffer displayed in the window this is indicated by a +``D'' in the mode line. + +Usually, dedicated windows are used to display specialized buffers, +but dedication can sometimes be useful interactively. For example, +when viewing errors with @kbd{M-g M-n} @code{next-error}, newly +displayed source code may replace a buffer you want to refer to. If +you dedicate a window to that buffer, the command (through +@code{display-buffer}) will prefer to use a different window instead. + +@kindex C-x w d +@findex toggle-window-dedicated + Toggle whether the selected window is dedicated to the current +buffer. With a prefix argument, make the window strongly dedicated +instead. + @menu * Window Choice:: How @code{display-buffer} works. * Temporary Displays:: Displaying non-editable buffers. diff --git a/etc/NEWS b/etc/NEWS index 3cfc36e10da..cd4c414a64c 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -92,6 +92,22 @@ plus, minus, check-mark, start, etc. The 'tool-bar-position' frame parameter can be set to 'bottom' on all window systems other than Nextstep. ++++ +** 'd' in the mode line now indicates that the window is dedicated. +Windows have always been able to be dedicated to a specific buffer; +see 'window-dedicated-p'. Now the mode line indicates the dedicated +status of a window, with 'd' appearing in the mode line if a window is +dedicated and 'D' if the window is strongly dedicated. This indicator +appears before the buffer name, and after the buffer modification and +remote buffer indicators (usually "---" together). + ++++ +** New command 'toggle-window-dedicated'. +This makes it easy to interactively mark a specific window as +dedicated, so it won't be reused by 'display-buffer'. This can be +useful for complicated window setups. It is bound to 'C-x w d' +globally. + ** cl-print *** You can expand the "..." truncation everywhere. The code that allowed "..." to be expanded in the *Backtrace* should diff --git a/lisp/bindings.el b/lisp/bindings.el index f1a75b080be..1e05c1de43c 100644 --- a/lisp/bindings.el +++ b/lisp/bindings.el @@ -298,6 +298,35 @@ mode-line-frame-identification ;;;###autoload (put 'mode-line-frame-identification 'risky-local-variable t) +(defvar mode-line-window-dedicated-keymap + (let ((map (make-sparse-keymap))) + (define-key map [mode-line mouse-1] #'toggle-window-dedicated) + (purecopy map)) "\ +Keymap for what is displayed by `mode-line-window-dedicated'.") + +(defun mode-line-window-control () + "Compute mode line construct for window dedicated state. +Value is used for `mode-line-window-dedicated', which see." + (cond + ((eq (window-dedicated-p) t) + `(:propertize + "D" + help-echo "Window strongly dedicated to its buffer\nmouse-1: Toggle" + local-map ,mode-line-window-dedicated-keymap + mouse-face 'mode-line-highlight)) + ((window-dedicated-p) + `(:propertize + "d" + help-echo "Window dedicated to its buffer\nmouse-1: Toggle" + local-map ,mode-line-window-dedicated-keymap + mouse-face 'mode-line-highlight)) + (t " "))) + +(defvar mode-line-window-dedicated '(:eval (mode-line-window-control)) + "Mode line construct to describe the current window.") +;;;###autoload +(put 'mode-line-window-dedicated 'risky-local-variable t) + (defvar-local mode-line-process nil "Mode line construct for displaying info on process status. Normally nil in most modes, since there is no process to display.") @@ -673,8 +702,9 @@ mode-line-end-spaces 'mode-line-mule-info 'mode-line-client 'mode-line-modified - 'mode-line-remote) - 'display '(min-width (5.0))) + 'mode-line-remote + 'mode-line-window-dedicated) + 'display '(min-width (6.0))) 'mode-line-frame-identification 'mode-line-buffer-identification " " diff --git a/lisp/window.el b/lisp/window.el index d91bbabc010..f1677060310 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -7463,6 +7463,60 @@ display-buffer-mark-dedicated The actual non-nil value of this variable will be copied to the `window-dedicated-p' flag.") +(defcustom toggle-window-dedicated-flag 'interactive + "What dedicated flag should `toggle-window-dedicated' use by default. + +If `toggle-window-dedicated' does not receive a flag argument, +the value of this variable is used and passed to +`set-window-dedicated-p'. Setting this to t will make +`toggle-window-dedicated' use strong dedication by default. Any +other non-nil value will result in the same kind of non-strong +dedication." + :type '(choice (const :tag "Strongly dedicated" t) + (const :tag "Dedicated" interactive)) + :version "30.0" + :group 'windows) + +(defun toggle-window-dedicated (&optional window flag interactive) + "Toggle whether WINDOW is dedicated to its current buffer. + +WINDOW must be a live window and defaults to the selected one. +If FLAG is t (interactively, the prefix argument), make the window +\"strongly\" dedicated to its buffer. FLAG defaults to a non-nil, +non-t value, and is passed to `set-window-dedicated-p', which see. +If INTERACTIVE is non-nil, print a message describing the dedication +status of WINDOW, after toggling it. Interactively, this argument is +always non-nil. + +When a window is dedicated to its buffer, `display-buffer' will avoid +displaying another buffer in it, if possible. When a window is +strongly dedicated to its buffer, changing the buffer shown in the +window will usually signal an error. + +You can control the default of FLAG with +`toggle-window-dedicated-flag'. Consequently, if you set that +variable to t, strong dedication will be used by default. + +See the info node `(elisp)Dedicated Windows' for more details." + (interactive "i\nP\np") + (setq window (window-normalize-window window)) + (setq flag (cond + ((consp flag) t) + ((null flag) toggle-window-dedicated-flag) + (t flag))) + (if (window-dedicated-p window) + (set-window-dedicated-p window nil) + (set-window-dedicated-p window flag)) + (when interactive + (message "Window is %s dedicated to buffer %s" + (let ((status (window-dedicated-p window))) + (cond + ((null status) "no longer") + ((eq status t) "now strongly") + (t "now"))) + (current-buffer)) + (force-mode-line-update))) + (defconst display-buffer--action-function-custom-type '(choice :tag "Function" (const :tag "--" ignore) ; default for insertion @@ -10746,6 +10800,7 @@ window-prefix-map "2" #'split-root-window-below "3" #'split-root-window-right "s" #'window-toggle-side-windows + "d" #'toggle-window-dedicated "^ f" #'tear-off-window "^ t" #'tab-window-detach "-" #'fit-window-to-buffer -- 2.41.0 --=-=-=--