Subject: Re: bug#39181: 27.0.50; [PATCH] Allow users to store & restore gdb-mi layout

From: Štěpán Němec <[email-masked]>
Date: Fri, 13 Mar 2020 22:13:05 +0100

[resending to Cc: Martin and the bug list, sorry]

On Fri, 13 Mar 2020 16:09:06 -0400
Yuan Fu wrote:

> Apart from fixing all the mentioned issues,

Almost... :-)

> The window layout that we save to a file in gdb is a window
> configuration structure with some small differences: simply loading
> that window configuration with `window-state-put' doesn’t give back
> your gdb layout. (because all the buffers (local, breakpoint, etc) are
> different from session to session.) `gdb-load-window-configuration`
> does some trick to recreate each buffers. Apart from that the layout
> and window configuration is the same thing.

Thank you for the clarification! It would be nice to have that in the
documentation as well.

> @@ -253,6 +255,25 @@ gdb-output-sink
>                disposition of output generated by commands that
>                gdb mode sends to gdb on its own behalf.")
> 
> +(defvar gdb--window-configuration-before nil
> +  "Stores the window configuration before starting gdb.")
> +
> +(defcustom gdb-restore-window-configuration-after-quit nil
> +  "Whether to restore the window configuration the user had before gdb starts.

Probably better stick to the standard "If non-nil, restore...".

> @@ -4491,6 +4538,15 @@ gdb-preempt-existing-or-display-buffer
>    (define-key gud-menu-map [displays]
>      `(menu-item "GDB-Windows" ,menu
>                 :visible (eq gud-minor-mode 'gdbmi)))
> +  (define-key menu [gdb-restore-windows]
> +    '(menu-item "Restore Default Layout" gdb-restore-windows
> +      :help "Restore standard layout for debug session. I.e., the layout we get when session starts."))

How about just "Restore standard layout for debug session (the layout we
get when session starts)." Or, even more concisely, "Restore the initial
GDB window layout"?

> +  (define-key menu [load-layout] '("Load Layout" "Load GDB window configuration (i.e. window layout) from a file" . gdb-load-window-configuration))

You can omit the "i.e.". Actually, even better perhaps just "window
configuration (layout)"? Similarly below.

> @@ -4606,41 +4659,174 @@ gdb-set-window-buffer
>    (set-window-buffer window (get-buffer name))
>    (set-window-dedicated-p window t))
> 
> +(defun gdb-toggle-restore-window-configuration ()
> +  "Toggle whether to restore window configuration when GDB quit."
                                                               ^^^^
quits

> +  (interactive)
> +  (setq gdb-restore-window-configuration-after-quit
> +        (not gdb-restore-window-configuration-after-quit)))
> +
> +(defun gdb-get-source-buffer ()
> +  "Return a buffer displaying source file or nil if we can't find one.
> +
> +The source file is the file that contains the source location
> +where GDB stops.  There could be multiple source files during a
> +debugging session, we get the most recently showed one.  If
> +program hasn't start running yet, the source file is the \"main
                   ^^^^^
started

> +file\" where the GDB session starts (see `gdb-main-file')."
> +  (if gud-last-last-frame
> +      (gud-find-file (car gud-last-last-frame))
> +    (when gdb-main-file
> +      (gud-find-file gdb-main-file))))
> +
>  (defun gdb-setup-windows ()
>    "Layout the window pattern for option `gdb-many-windows'."
       ^^^^^^
"Lay out" (verb)

> @@ -4658,7 +4844,12 @@ gdb-many-windows
> 
>  (defun gdb-restore-windows ()
>    "Restore the basic arrangement of windows used by gdb.
> -This arrangement depends on the value of option `gdb-many-windows'."
> +This arrangement depends on the value of option
> +`gdb-many-windows' and `gdb-default-window-configuration-file'."

How about "This arrangement depends on the values of `gdb-many-windows'
and `gdb-default-window-configuration-file'."

> diff --git a/lisp/window.el b/lisp/window.el
> index bd825c09e1..d774d906cd 100644
> --- a/lisp/window.el
> +++ b/lisp/window.el
> @@ -278,6 +278,24 @@ with-displayed-buffer-window
>              (funcall ,vquit-function ,window ,value)
>            ,value)))))
> 
> +(defmacro with-window-non-dedicated (window &rest body)
> +  "Evaluate BODY with WINDOW selected and temporarily made non-dedicated.
                                 ^^^^^^^^^^^^
This is now no longer true.

Thank you,

  Štěpán

P.S.: This time your patch somehow ended up hidden as
application/ocet-stream after the HTML part, instead of inline in plain
text.