all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Yuan Fu <casouri@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 39181@debbugs.gnu.org
Subject: bug#39181: 27.0.50; [PATCH] Allow users to store & restore gdb-mi layout
Date: Sat, 15 Feb 2020 15:37:43 -0500	[thread overview]
Message-ID: <06950D5B-902C-49C9-81B2-9989FB35F0DB@gmail.com> (raw)
In-Reply-To: <835zg8noep.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 687 bytes --]



> On Feb 15, 2020, at 5:19 AM, Eli Zaretskii <eliz@gnu.org> wrote:
> 
>> Cc: 39181@debbugs.gnu.org
>> From: martin rudalics <rudalics@gmx.at>
>> Date: Sat, 15 Feb 2020 10:55:34 +0100
>> 
>>> Martin, any comments?
>> 
>> IMHO "restoring the previous window layout when gdb quits" should be
>> opt-in (or at least opt-out).  Maybe it also should restore the layout
>> only when 'gdb-many-windows' is non-nil, so we'd have the three option
>> values nil, t, and if-gdb-many-windows (in a menu entry).
> 
> I had the same thoughts myself, and I agree on both counts.

I agree. I made it into a custom variable with choices, is that what you mean by menu entry?

Yuan


[-- Attachment #2.1: Type: text/html, Size: 2607 bytes --]

[-- Attachment #2.2: restore-after-quit-new.patch --]
[-- Type: application/octet-stream, Size: 3652 bytes --]

From 03ab125435ca145ca81707e09524c64d63c80183 Mon Sep 17 00:00:00 2001
From: Yuan Fu <casouri@gmail.com>
Date: Sat, 15 Feb 2020 15:15:20 -0500
Subject: [PATCH] Restore previous window layout when gdb quits

Make gdb preserve the window configuration that the user had before
starting gdb.
* lisp/progmodes/gdb-mi.el (gdb--window-configuration-before): New
variable.
(gdb-restore-window-layout-after-quit): New custom variable.
(gdb): Save configuration on startup.
(gdb-reset): Restore window configuration after quit.
---
 lisp/progmodes/gdb-mi.el | 43 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)

diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el
index da5a2a503a..313fc58dce 100644
--- a/lisp/progmodes/gdb-mi.el
+++ b/lisp/progmodes/gdb-mi.el
@@ -253,6 +253,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-layout-after-quit nil
+  "Specify whether to restore the window layout the user had before gdb starts.
+
+Possible values are:
+    t -- Always restore.
+    nil -- Don't restore.
+    'if-show-main -- Restore only if `gdb-show-main' is non-nil
+    'if-many-windows -- Restore only if variable `gdb-many-windows' is non-nil."
+  :type '(choice
+          (const :tag "Always restore" t)
+          (const :tag "Don't restore" nil)
+          (const :tag "Depends on `gdb-show-main'" 'if-gdb-show-main)
+          (const :tag "Depends on `gdb-many-windows'" 'if-gdb-many-windows))
+  :group 'gdb
+  :version "28.1")
+
 (defcustom gdb-discard-unordered-replies t
   "Non-nil means discard any out-of-order GDB replies.
 This protects against lost GDB replies, assuming that GDB always
@@ -761,6 +780,16 @@ gdb
     (gdb-restore-windows)
     (error
      "Multiple debugging requires restarting in text command mode"))
+
+  ;; Save window configuration before starting gdb so we can restore
+  ;; it after gdb quits.
+  (when (or (eq gdb-restore-window-layout-after-quit t)
+            (and (eq gdb-restore-window-layout-after-quit 'if-show-main)
+                 gdb-show-main)
+            (and (eq gdb-restore-window-layout-after-quit 'if-many-windows)
+                 gdb-many-windows))
+    (setq gdb--window-configuration-before (window-state-get)))
+
   ;;
   (gud-common-init command-line nil 'gud-gdbmi-marker-filter)
 
@@ -4705,7 +4734,19 @@ gdb-reset
   (if (boundp 'speedbar-frame) (speedbar-timer-fn))
   (setq gud-running nil)
   (setq gdb-active-process nil)
-  (remove-hook 'after-save-hook 'gdb-create-define-alist t))
+  (remove-hook 'after-save-hook 'gdb-create-define-alist t)
+  ;; Recover window configuration.
+  (when (or (eq gdb-restore-window-layout-after-quit t)
+            (and (eq gdb-restore-window-layout-after-quit 'if-show-main)
+                 gdb-show-main)
+            (and (eq gdb-restore-window-layout-after-quit 'if-many-windows)
+                 gdb-many-windows))
+    (when gdb--window-configuration-before
+      (window-state-put gdb--window-configuration-before)
+      ;; This way we don't accidentally restore an outdated window
+      ;; configuration.  Maybe the user changed the configuration
+      ;; after starting GDB, who knows.
+      (setq gdb--window-configuration-before nil))))
 
 (defun gdb-get-source-file ()
   "Find the source file where the program starts and display it with related
-- 
2.25.0


[-- Attachment #2.3: Type: text/html, Size: 226 bytes --]

  reply	other threads:[~2020-02-15 20:37 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <5e950f28.1c69fb81.61726.5731.GMR@mx.google.com>
2020-01-18 20:57 ` bug#39181: 27.0.50; [PATCH] Allow users to store & restore gdb-mi layout Yuan Fu
2020-01-31 10:13   ` Eli Zaretskii
2020-02-02 14:22     ` Yuan Fu
2020-02-07 22:28       ` Yuan Fu
2020-02-10  4:56         ` Yuan Fu
2020-02-15  8:08           ` Eli Zaretskii
2020-02-15  9:55             ` martin rudalics
2020-02-15 10:19               ` Eli Zaretskii
2020-02-15 20:37                 ` Yuan Fu [this message]
2020-02-16 10:00                   ` martin rudalics
2020-03-03 23:41                     ` Yuan Fu
2020-03-04 13:28                       ` Fu Yuan
2020-03-05  6:12                         ` Yuan Fu
2020-03-05  9:14                           ` martin rudalics
2020-03-07 18:09                             ` Yuan Fu
2020-03-07 19:07                               ` Štěpán Němec
2020-03-07 19:17                                 ` Yuan Fu
2020-03-09  9:01                                   ` martin rudalics
2020-03-09 17:59                                     ` Yuan Fu
2020-03-09 19:18                                       ` Štěpán Němec
2020-03-09 20:17                                         ` Yuan Fu
2020-03-09 20:54                                           ` Štěpán Němec
2020-03-10  8:49                                           ` martin rudalics
2020-03-10 18:05                                             ` Fu Yuan
2020-03-11  8:52                                               ` martin rudalics
2020-03-11  9:26                                                 ` Štěpán Němec
2020-03-12  8:22                                                   ` martin rudalics
2020-03-12  8:49                                                     ` Štěpán Němec
2020-03-12 19:21                                                       ` Yuan Fu
2020-03-13 20:09                                                         ` Yuan Fu
     [not found]                                                           ` <87lfo4netg.fsf@gmail.com>
2020-03-13 21:13                                                             ` Štěpán Němec
2020-03-13 21:40                                                               ` Yuan Fu
2020-03-13 22:12                                                                 ` Štěpán Němec
2020-03-15 15:55                                                                 ` martin rudalics
2020-03-16  0:13                                                                   ` Yuan Fu
2020-03-16  9:24                                                                     ` martin rudalics
2020-03-20 20:03                                                                       ` Yuan Fu
2020-03-20 20:58                                                                         ` Štěpán Němec
2020-03-21 18:00                                                                           ` Yuan Fu
2020-03-21 18:39                                                                             ` Štěpán Němec
2020-03-21 21:03                                                                               ` Yuan Fu
2020-03-21 21:49                                                                                 ` Štěpán Němec
2020-03-24 16:14                                                                                   ` Yuan Fu
2020-03-27  9:01                                                                                     ` martin rudalics
2020-03-27 16:28                                                                                       ` Yuan Fu
2020-04-14  8:05                                                                                         ` martin rudalics
2020-03-10  8:48                                       ` martin rudalics
2020-04-14  1:17   ` bug#39181: Fwd: Delivery Status Notification (Failure) Yuan Fu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=06950D5B-902C-49C9-81B2-9989FB35F0DB@gmail.com \
    --to=casouri@gmail.com \
    --cc=39181@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.