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: Sat, 19 Aug 2023 20:02:35 +0000 (UTC) Message-ID: <877cpqreat.fsf@catern.com> References: <87h6ovgnpn.fsf@catern.com> <874jkvvwm2.fsf@posteo.net> <87jztr0zt7.fsf@catern.com> <87zg2nuho0.fsf@posteo.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="22954"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Spencer Baugh , Eli Zaretskii , 64619@debbugs.gnu.org, Drew Adams , martin rudalics To: Philip Kaludercic Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Aug 19 22:03:16 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 1qXSAC-0005cX-Ti for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 19 Aug 2023 22:03:13 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qXSA5-0000xn-VS; Sat, 19 Aug 2023 16:03:05 -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 1qXSA1-0000xW-H9 for bug-gnu-emacs@gnu.org; Sat, 19 Aug 2023 16:03: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 1qXSA1-0002qb-8e for bug-gnu-emacs@gnu.org; Sat, 19 Aug 2023 16:03:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qXSA2-0000xO-Cw for bug-gnu-emacs@gnu.org; Sat, 19 Aug 2023 16:03: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: Sat, 19 Aug 2023 20:03: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.16924753683659 (code B ref 64619); Sat, 19 Aug 2023 20:03:02 +0000 Original-Received: (at 64619) by debbugs.gnu.org; 19 Aug 2023 20:02:48 +0000 Original-Received: from localhost ([127.0.0.1]:52347 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qXS9n-0000ww-TL for submit@debbugs.gnu.org; Sat, 19 Aug 2023 16:02:48 -0400 Original-Received: from s.wrqvtbkv.outbound-mail.sendgrid.net ([149.72.123.24]:50816) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qXS9i-0000wf-HO for 64619@debbugs.gnu.org; Sat, 19 Aug 2023 16:02:46 -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=fwNGFBP9MzZ4gQGc1hFzIHW88jLy2j5Q4PMJDJWiMNc=; b=b5PAloECSDVT6R76k42ilSIeVY32BjdXIwstzXgL/98DtcPkKjShlUMg98Bjq186F0Ps 4NCswF0nx/lP26xeQZ0oOmwA5+GhvG30xXUdinyIYz2/n5F0XHFrtTNDtsVmDamqi8srvI sJq4xgNZAYcSn7u4id5tEierY17nziSpNKiHWfl+xuA2LJnhu/EeSh1FuJ4fLzV3XoFIYZ Gy+NzVxnZ2wN85A6EPjWq6dGdHvHlpC8QXFGyX9Oz3qw4vjou+egHkiJE6KStNCy3dLOm9 uizAc7R56basDBWPwTI1BhpoQw/agGkR8bMduxt7X5qaRcvsQghnTZ2505RpI50A== Original-Received: by filterdrecv-66949dbc98-p7b6v with SMTP id filterdrecv-66949dbc98-p7b6v-1-64E11FDB-10 2023-08-19 20:02:35.19988688 +0000 UTC m=+8713369.251518835 Original-Received: from earth.catern.com (unknown) by geopod-ismtpd-29 (SG) with ESMTP id Uktpuem5Qbq_yNM2CGWFkA Sat, 19 Aug 2023 20:02:35.035 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=::1; helo=localhost; envelope-from=sbaugh@catern.com; receiver=posteo.net Original-Received: from localhost (localhost [IPv6:::1]) by earth.catern.com (Postfix) with ESMTPSA id 7F0986257B; Sat, 19 Aug 2023 16:02:34 -0400 (EDT) In-Reply-To: <87zg2nuho0.fsf@posteo.net> (Philip Kaludercic's message of "Sat, 19 Aug 2023 16:21:35 +0000") X-SG-EID: ZgbRq7gjGrt0q/Pjvxk7wM0yQFRdOkTJAtEbkjCkHbJjDFq7v/YiFOBL0YJnlO0XGALxdYmllMUFQeoJ6On9UMZ+2P+91vfpI+q2BtKSL7arBnZvTdUbjheBhheCi4YDWI9RmXRSDi+VFz9z0jhc1fp56vcp+e1YbZBfW5JCAd6aoGUcxej5lteQWnA1mG3cIC/w0eJpR2Yp+xCCxjcRmw== 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:267913 Archived-At: --=-=-= Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Philip Kaludercic writes: > sbaugh@catern.com writes: > >> Philip Kaludercic writes: >> >>> sbaugh@catern.com writes: >>> >>>> Spencer Baugh writes: >>>>> OK, this patch adds support for making the buffer strongly dedicated >>>>> with a prefix argument, and also adds an indicator to the mode line of >>>>> whether the current window is dedicated (which seems useful even if we >>>>> don't apply the toggle part of this patch). >>>> >>>> Any thoughts on this patch? >>> >>> I just tried it out and it works as advertised. The only question is if >>> a NEWS entry should be added, or if it is worth mentioning it in the >>> manual? >> >> Yes, I think definitely a NEWS entry is warranted, if only because it >> adds an indicator the mode line. But I wanted to settle the format >> before writing it. > > I think it is fine the way it is right now. OK, added a NEWS entry and information in the manual. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Add-toggle-window-dedicated-command-and-mode-line-wi.patch >From dc02ad0891c3a832617d6b234bd30a0bc8f8ef69 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. * etc/NEWS: Announce the 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/windows.texi | 16 ++++++++++++++++ etc/NEWS | 14 ++++++++++++++ lisp/bindings.el | 22 ++++++++++++++++++++++ lisp/window.el | 28 ++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+) diff --git a/doc/emacs/windows.texi b/doc/emacs/windows.texi index e4abdef76be..f24ffc20464 100644 --- a/doc/emacs/windows.texi +++ b/doc/emacs/windows.texi @@ -411,6 +411,22 @@ 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. + Sometimes, a window is ``dedicated'' to its current buffer. +@code{display-buffer} will avoid reusing dedicated windows most of the +time. This is indicated by a ``d'' in the mode line. A window can +also be strongly dedicated, which prevents any changes to what buffer +that window displays; 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 to interactively control +@code{display-buffer}'s window choices. + +@kindex C-x w d +@findex toggle-window-dedicated + Toggle whether the current 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..6368d640fb7 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -92,6 +92,20 @@ 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. + ++++ +** 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..b751fed22ce 100644 --- a/lisp/bindings.el +++ b/lisp/bindings.el @@ -298,6 +298,27 @@ mode-line-frame-identification ;;;###autoload (put 'mode-line-frame-identification 'risky-local-variable t) +(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 is strongly dedicated to current buffer" + mouse-face 'mode-line-highlight)) + ((window-dedicated-p) + '(:propertize + " d" + help-echo "Window is dedicated to current buffer" + 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.") @@ -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 " " diff --git a/lisp/window.el b/lisp/window.el index d91bbabc010..259c1e679ac 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -7463,6 +7463,33 @@ display-buffer-mark-dedicated The actual non-nil value of this variable will be copied to the `window-dedicated-p' flag.") +(defun toggle-window-dedicated (&optional window flag interactive) + "Toggle whether WINDOW is dedicated. + +See `set-window-dedicated-p' for more details. WINDOW defaults +to the currently selected window. FLAG defaults to +`dedicated' (weak dedication) or `t' (strong dedication) with a +prefix argument. If INTERACTIVE is non-nil, will print a message +about the dedication status of the window afterwards." + (interactive "i\nP\np") + (setq window (window-normalize-window window)) + (setq flag (cond + ((consp flag) t) + ((null flag) 'dedicated) + (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 +10773,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 --=-=-=--