Subject: bug#64619: [PATCH] Add toggle-window-dedicated command

From: Philip Kaludercic <[email-masked]>
Date: Fri, 14 Jul 2023 19:42:47 +0000

Spencer Baugh <[email-masked]> writes:

> Tags: patch
>
>
> It's sometimes useful to interactively make certain windows dedicated.
> This allows a level of interactive control over which window
> display-buffer uses.

I think this sounds interesting, I think there is a lot that can be
improved when it comes to window management.

> * lisp/window.el (toggle-window-dedicated): Add.
> (window-prefix-map): Add C-x w d binding.
>
>
> In GNU Emacs 29.0.92 (build 5, x86_64-pc-linux-gnu, X toolkit, cairo
>  version 1.15.12, Xaw scroll bars) of 2023-07-10 built on
>  igm-qws-u22796a
> Repository revision: dd15432ffacbeff0291381c0109f5b1245060b1d
> Repository branch: emacs-29
> Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
> System Description: CentOS Linux 7 (Core)
>
> Configured using:
>  'configure --config-cache --with-x-toolkit=lucid
>  --with-gif=ifavailable'
>
>>>From 2e8caf7d1f0a402568fac9e8767064a452499d60 Mon Sep 17 00:00:00 2001
> From: Spencer Baugh <[email-masked]>
> Date: Fri, 14 Jul 2023 11:38:24 -0400
> Subject: [PATCH] Add toggle-window-dedicated command
>
> It's sometimes useful to interactively make certain windows dedicated.
> This allows a level of interactive control over which window
> display-buffer uses.
>
> * lisp/window.el (toggle-window-dedicated): Add.
> (window-prefix-map): Add C-x w d binding.
> ---
>  lisp/window.el | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
>
> diff --git a/lisp/window.el b/lisp/window.el
> index d91bbabc010..f884d9aaf16 100644
> --- a/lisp/window.el
> +++ b/lisp/window.el
> @@ -7463,6 +7463,20 @@ 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 interactive)
> +  "Toggle whether WINDOW is dedicated.
> +
> +See `set-window-dedicated-p' for more details.  WINDOW defaults
> +to the currently selected window."

Shouldn't "interactive" be documented as well?  

> +  (interactive "i\np")

How about

  (interactive (list (window-normalize-window window) t))

> +  (setq window (window-normalize-window window))
> +  (if (window-dedicated-p window)
> +      (progn
> +        (set-window-dedicated-p window nil)
> +        (when interactive (message "Window can now be used to display other buffers")))
> +    (set-window-dedicated-p window 'dedicated)
> +    (when interactive (message "Window will now display only its current buffer"))))
> +
>  (defconst display-buffer--action-function-custom-type
>    '(choice :tag "Function"
>  	   (const :tag "--" ignore) ; default for insertion
> @@ -10746,6 +10760,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