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: Fri, 13 Oct 2023 01:33:11 +0000 (UTC) Message-ID: <875y3bz4q1.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> <878ra4pn28.fsf@catern.com> <83r0nwtd6z.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="5871"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: sbaugh@janestreet.com, philipk@posteo.net, 64619@debbugs.gnu.org, drew.adams@oracle.com, rudalics@gmx.at To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Oct 13 03:34:03 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 1qr73y-0001GM-0x for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 13 Oct 2023 03:34:02 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qr73d-0002fP-43; Thu, 12 Oct 2023 21:33:41 -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 1qr73c-0002fH-0f for bug-gnu-emacs@gnu.org; Thu, 12 Oct 2023 21:33:40 -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 1qr73b-0006t3-NR for bug-gnu-emacs@gnu.org; Thu, 12 Oct 2023 21:33:39 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qr73y-0004wt-2Q for bug-gnu-emacs@gnu.org; Thu, 12 Oct 2023 21:34: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: Fri, 13 Oct 2023 01:34:02 +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.169716082618998 (code B ref 64619); Fri, 13 Oct 2023 01:34:02 +0000 Original-Received: (at 64619) by debbugs.gnu.org; 13 Oct 2023 01:33:46 +0000 Original-Received: from localhost ([127.0.0.1]:44503 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qr73h-0004wL-4n for submit@debbugs.gnu.org; Thu, 12 Oct 2023 21:33:46 -0400 Original-Received: from s.wfbtzhsw.outbound-mail.sendgrid.net ([159.183.224.105]:34982) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qr73c-0004w2-Iv for 64619@debbugs.gnu.org; Thu, 12 Oct 2023 21:33:43 -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=KjOSU2lKJ3gSeuKfUbycog/o5RzSIy8v6iYxzJ7tNoc=; b=IO/DYY9Oy7hQ6OjMzWdAQNMLq3eRbxcQjpcLy6cGx1rLpA8swRM2L9fGslgpahkaovzd uJAqr4BNwBHBe0WwkVo2r/pu/esge+OlXG3xw5xGYx9xiHS/xPUzIu4K/Y0Ob7ei9QBdIz YeKag1GJ8ORFaTyuANyt2wms/oIcasdfhcMSZ0eEut+GPs/ytPD6ae3aDV3ZAof/EwBG52 3wuAhIibK7JaMzMjqZhPWbezV9i2KKR5ay0S9OtZbwNxJNfxGNm46a1A8zgPVKvQ8fnl+E QEUeIauPobTbAyHSq7R0ZZuqnRKmrpL28ftPaEX5gWuxx51QVZOweT1Bz63XUyow== Original-Received: by filterdrecv-6488dc484d-ddjr6 with SMTP id filterdrecv-6488dc484d-ddjr6-1-65289E57-14 2023-10-13 01:33:11.397231885 +0000 UTC m=+191429.230150949 Original-Received: from earth.catern.com (unknown) by geopod-ismtpd-1 (SG) with ESMTP id VmYD42NfTomCpfpzC0StpQ Fri, 13 Oct 2023 01:33:11.278 +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 C4AA6633C9; Thu, 12 Oct 2023 21:33:10 -0400 (EDT) In-Reply-To: <83r0nwtd6z.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 21 Aug 2023 22:20:20 +0300") X-SG-EID: ZgbRq7gjGrt0q/Pjvxk7wM0yQFRdOkTJAtEbkjCkHbIgG4W0kgbMRV7xgq4PR/QSYMaGJzkKgX6dq+Kuhx30USNefr00FJGih2Q5fXqNSCwDNDicqdjEaoOOrdg1b26UBV3KnUXQofppk+GF3N9b+JV2O1utG8bjq0CEWcHuU5zsPwMXVANILfosCbOpxObjoK1BSss3iXWnYUMjn8rAxQ== 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:272330 Archived-At: --=-=-= Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Eli Zaretskii writes: >> From: sbaugh@catern.com >> Date: Mon, 21 Aug 2023 13:00:48 +0000 (UTC) >> Cc: sbaugh@janestreet.com, philipk@posteo.net, 64619@debbugs.gnu.org, >> drew.adams@oracle.com, rudalics@gmx.at >> >> >> @@ -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? > > Look at how modeline-client was fixed recently, it had the same > problem. > >> 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? > > Empty space is fine, and min-width will do that. > >> - @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. > > This should be @var{d}, lower-case, as all the arguments of @var are. > makeinfo will either up-case it (for Info) or produce a slanted > typeface (for other output formats). > >> +@cindex dedicated window >> + Sometimes, a window is ``dedicated'' to its current buffer > ^ > A period is missing there. > >> +@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. > > Why use ``d'' and ``D'' and not @samp? > >> +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. > > The last sentence should say at the end "...and \\[universal-argument] > will make the window weakly dedicated." All fixed, here's my revised patch. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Add-toggle-window-dedicated-command-and-mode-line-wi.patch >From d17c90d084a29430b2c131e34ff76d4e9762b8dc 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. (bug#64619) (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 | 21 +++++++++++++++ lisp/bindings.el | 34 ++++++++++++++++++++++-- lisp/window.el | 59 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 141 insertions(+), 3 deletions(-) diff --git a/doc/emacs/screen.texi b/doc/emacs/screen.texi index 5e9e89e6b11..3b910587260 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 665fd80e53b..ca5e424d939 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 @samp{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 +@samp{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 cfcb8104cca..647562143de 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -135,6 +135,27 @@ window systems other than Nextstep. When this minor mode is enabled, buttons representing modifier keys are displayed along the tool bar. ++++ +** '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 +now work anywhere the data is generated by `cl-print`. + --- ** New user option 'uniquify-dirname-transform'. This can be used to customize how buffer names are uniquified, by diff --git a/lisp/bindings.el b/lisp/bindings.el index 70e4087e131..418ee265e69 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.") @@ -676,8 +705,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 2f9b46ebb0a..7c2ead7e5fe 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -7468,6 +7468,64 @@ 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 and +\\[universal-argument] will make the window weakly dedicated. + +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) + (if (eq toggle-window-dedicated-flag t) + 'interactive + 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 @@ -10750,6 +10808,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 --=-=-=--