unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Yuan Fu <casouri@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: martin rudalics <rudalics@gmx.at>,
	emacs-devel@gnu.org, monnier@iro.umontreal.ca,
	john@yates-sheets.org, Juri Linkov <juri@linkov.net>
Subject: Re: Extend gdb to filter registers
Date: Tue, 21 Jan 2020 20:50:46 -0500	[thread overview]
Message-ID: <2BEA3843-859E-481B-8561-35384438EF7F@gmail.com> (raw)
In-Reply-To: <83wo9mvwco.fsf@gnu.org>

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

>> So it seems the intension is to display source in new window, not using only one window as I originally
>> thought. I’d like to simplify it, put the decision logic into one place. And then we can add customizability to it.
> 
> Thanks, sounds like a good plan to me.

Here is my first attempt. I make every function that needs to display a source buffer (only 2: gdb-goto-breakpoint, gud-display-line) use gdb-display-source-buffer. Previously they either use (or gdb-display-source-buffer display-buffer) or use (display-buffer). 

Gdb-mi.el used to have a variable gdb-source-window, I changed it to gdb-source-window-list. And now reusing a window is as simple as looking at this list of windows. (No need to check for last-last-frame, etc). 

I added a variable for maximum number of windows used for source buffer. Right now the simple logic is to open as much windows as possible until the max is reached, then we start to reuse windows. Creating new window uses display-buffer-pop-up-window (I use this function just for completeness, I would modify this part when adding customization, maybe let user customize action for display-buffer?)

Overall this patch doesn’t change the behavior except 1) new window/not is now determined by gdb-maximum-source-window-count instead of display-buffer 2) now gud also uses gdb’s display function, so there is no check for gdb-mi vs gud anymore

You’ll also notice that, when you quit, all the source windows are left undeleted. That’s the original behavior and I have another patch that restores the old window configuration the user have before starting gdb. So I didn’t do anything about that.

If you think this patch is fine, I’ll do these next: 1) add a straightforward customization, preferably only one variable. 2) currently gdb opens windows everywhere, I want to make it open in only one continues area and maybe balance windows. Do you think this is worth doing? Or it is suffice to let user customize the display-buffer action?

Yuan


[-- Attachment #2: simplify.patch --]
[-- Type: application/octet-stream, Size: 6214 bytes --]

From 74a9a53ddf29b2caeeea0ddf3896418d59fada48 Mon Sep 17 00:00:00 2001
From: Yuan Fu <casouri@gmail.com>
Date: Tue, 21 Jan 2020 16:23:57 -0500
Subject: [PATCH] Simplify gdb-mi/gud display source buffer logic
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* lisp/progmodes/gdb-mi.el (gdb-source-window): remove
(gdb-source-window-list, gdb-max-source-window-count): new
(gdb-init-1, gdb-setup-windows, gdb-restore-windows):
change gdb-source-window to gdb-source-window-list
(gdb-display-source-buffer): use new logic
(gdb-goto-breakpoint): remove display-buffer
and don’t set gdb-source-buffer anymore

* lisp/progmodes/gud.el (gud-display-line): remove display-buffer
and don’t set gdb-source-buffer anymore; remove check for gdb-mi,
so we basically always set gdb-source-window-list
---
 lisp/progmodes/gdb-mi.el | 50 +++++++++++++++++++++++++---------------
 lisp/progmodes/gud.el    |  8 ++-----
 2 files changed, 34 insertions(+), 24 deletions(-)

diff --git a/lisp/progmodes/gdb-mi.el b/lisp/progmodes/gdb-mi.el
index e4233dacaf..27031e24f7 100644
--- a/lisp/progmodes/gdb-mi.el
+++ b/lisp/progmodes/gdb-mi.el
@@ -211,7 +211,11 @@ gdb-handler-list
 (defvar gdb-source-file-list nil
   "List of source files for the current executable.")
 (defvar gdb-first-done-or-error t)
-(defvar gdb-source-window nil)
+(defvar gdb-source-window-list nil
+  "List of windows used for displaying source files.
+Sorted in most recently visited first order.")
+(defvar gdb-max-source-window-count 2
+  "Maximum number of source windows to use.")
 (defvar gdb-inferior-status nil)
 (defvar gdb-continuation nil)
 (defvar gdb-supports-non-stop nil)
@@ -922,7 +926,7 @@ gdb-init-1
 	gdb-first-done-or-error t
 	gdb-buffer-fringe-width (car (window-fringes))
 	gdb-debug-log nil
-	gdb-source-window nil
+	gdb-source-window-list nil
 	gdb-inferior-status nil
 	gdb-continuation nil
         gdb-buf-publisher '()
@@ -2002,17 +2006,29 @@ gdb-show-stop-p
 ;; GDB frame (after up, down etc).  If no GDB frame is visible but the last
 ;; visited breakpoint is, use that window.
 (defun gdb-display-source-buffer (buffer)
-  (let* ((last-window (if gud-last-last-frame
-                          (get-buffer-window
-                           (gud-find-file (car gud-last-last-frame)))))
-	 (source-window (or last-window
-			    (if (and gdb-source-window
-				     (window-live-p gdb-source-window))
-				gdb-source-window))))
-    (when source-window
-      (setq gdb-source-window source-window)
-      (set-window-buffer source-window buffer))
-    source-window))
+  "Find a window to display BUFFER.
+Always find a window to display buffer, and return it."
+  ;; doesn't take care of setting up source window(s)
+  ;; if `buffer' is already shown, use that window
+  (or (get-buffer-window buffer)
+      (progn
+        ;; first update window list
+        (setq gdb-source-window-list
+              (cl-remove-if-not #'window-live-p
+                                gdb-source-window-list))
+        ;; create new or reuse?
+        (if (> gdb-max-source-window-count
+               (length gdb-source-window-list))
+            ;; create new window, push to list, return it
+            (car (push (display-buffer-pop-up-window buffer nil)
+                       gdb-source-window-list))
+          ;; reuse, we use the oldest window and put that to front
+          (let ((last-win (car (last gdb-source-window-list)))
+                (rest (butlast gdb-source-window-list)))
+            (set-window-buffer last-win buffer)
+            (setq gdb-source-window-list
+                  (cons last-win rest))
+            last-win)))))
 
 
 (defun gdbmi-start-with (str offset match)
@@ -3981,9 +3997,7 @@ gdb-goto-breakpoint
               (let* ((buffer (find-file-noselect
                               (if (file-exists-p file) file
                                 (cdr (assoc bptno gdb-location-alist)))))
-                     (window (or (gdb-display-source-buffer buffer)
-                                 (display-buffer buffer))))
-                (setq gdb-source-window window)
+                     (window (gdb-display-source-buffer buffer)))
                 (with-current-buffer buffer
                   (goto-char (point-min))
                   (forward-line (1- (string-to-number line)))
@@ -4597,7 +4611,7 @@ gdb-setup-windows
          ;; Put buffer list in window if we
          ;; can't find a source file.
          (list-buffers-noselect))))
-    (setq gdb-source-window (selected-window))
+    (setq gdb-source-window-list (list (selected-window)))
     (let ((win4 (split-window-right)))
       (gdb-set-window-buffer
        (gdb-get-buffer-create 'gdb-inferior-io) nil win4))
@@ -4639,7 +4653,7 @@ gdb-restore-windows
          (if gud-last-last-frame
              (gud-find-file (car gud-last-last-frame))
            (gud-find-file gdb-main-file)))
-        (setq gdb-source-window win)))))
+        (setq gdb-source-window-list (list win))))))
 
 ;; Called from `gud-sentinel' in gud.el:
 (defun gdb-reset ()
diff --git a/lisp/progmodes/gud.el b/lisp/progmodes/gud.el
index 567f452b93..ccf9026417 100644
--- a/lisp/progmodes/gud.el
+++ b/lisp/progmodes/gud.el
@@ -2826,9 +2826,7 @@ gud-display-line
 	 (buffer
 	  (with-current-buffer gud-comint-buffer
 	    (gud-find-file true-file)))
-	 (window (and buffer
-		      (or (get-buffer-window buffer)
-			  (display-buffer buffer '(nil (inhibit-same-window . t))))))
+	 (window (when buffer (gdb-display-source-buffer buffer)))
 	 (pos))
     (when buffer
       (with-current-buffer buffer
@@ -2858,9 +2856,7 @@ gud-display-line
 	       (widen)
 	       (goto-char pos))))
       (when window
-	(set-window-point window gud-overlay-arrow-position)
-	(if (eq gud-minor-mode 'gdbmi)
-	    (setq gdb-source-window window))))))
+	(set-window-point window gud-overlay-arrow-position)))))
 
 ;; The gud-call function must do the right thing whether its invoking
 ;; keystroke is from the GUD buffer itself (via major-mode binding)
-- 
2.25.0


  reply	other threads:[~2020-01-22  1:50 UTC|newest]

Thread overview: 104+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-03 16:40 Extend gdb to filter registers Yuan Fu
2019-10-04 16:13 ` Fu Yuan
2019-10-04 19:32   ` Eli Zaretskii
2019-10-04 19:49 ` Stefan Monnier
2019-10-04 21:55   ` Yuan Fu
2019-10-05  3:15     ` Yuan Fu
2019-10-05  7:08       ` Eli Zaretskii
2019-10-05 13:15         ` Yuan Fu
2019-10-05 13:53           ` Eli Zaretskii
2019-10-05 17:51             ` Yuan Fu
2019-10-05 19:01               ` Eli Zaretskii
2019-10-06  4:24                 ` Yuan Fu
2019-10-06 17:36                   ` Eli Zaretskii
2019-10-08  2:23                     ` Yuan Fu
2019-10-06  4:43               ` Michael Welsh Duggan
2019-10-07 15:50                 ` Yuan Fu
2019-10-07 16:19                   ` Michael Welsh Duggan
2019-10-08  0:19                     ` Yuan Fu
2019-10-08 17:26       ` Stefan Monnier
2019-10-09  3:44         ` Yuan Fu
2019-10-09  3:51           ` Yuan Fu
2019-10-15  3:05           ` Yuan Fu
2019-10-15  9:48             ` martin rudalics
2019-10-17  3:14               ` Yuan Fu
2019-10-17  3:27                 ` Yuan Fu
2019-10-17  8:26                 ` martin rudalics
2019-10-15 18:10             ` Juri Linkov
2019-10-15 20:51               ` Stefan Monnier
2019-10-17  3:08               ` Yuan Fu
2019-10-17  8:19                 ` Eli Zaretskii
2019-10-26 21:56                   ` Yuan Fu
2019-10-27  7:47                     ` martin rudalics
2019-10-27 17:38                       ` Yuan Fu
2020-01-16  4:25                         ` Yuan Fu
2020-01-16 14:51                           ` Eli Zaretskii
2020-01-16 15:04                             ` Yuan Fu
     [not found]                               ` <CAO0xp5w8PwAiy=JNVmCK652rCs_06cMAO5_+1ppHwppQ2js4VQ@mail.gmail.com>
2020-01-17 23:31                                 ` Yuan Fu
2020-01-18 11:15                               ` Eli Zaretskii
2020-01-18 13:32                                 ` Yuan Fu
2020-01-18 15:21                                   ` Eli Zaretskii
2020-01-18 15:41                                     ` Yuan Fu
2020-01-18 16:50                                       ` Eli Zaretskii
2020-01-18 16:20                                 ` John Yates
2020-01-18 16:53                                   ` Eli Zaretskii
2020-01-18 17:53                                     ` Yuan Fu
2020-01-18 17:56                                       ` Eli Zaretskii
2020-01-18 18:21                                     ` martin rudalics
2020-01-18 18:33                                       ` Eli Zaretskii
2020-01-18 18:36                                         ` Yuan Fu
2020-01-18 18:48                                           ` Eli Zaretskii
2020-01-18 20:10                                             ` Yuan Fu
2020-01-18 18:41                                         ` martin rudalics
2020-01-18 19:18                                           ` Eli Zaretskii
2020-01-18 21:43                                             ` martin rudalics
2020-01-19 15:40                                               ` Eli Zaretskii
2020-01-19 17:33                                                 ` Yuan Fu
2020-01-19 17:42                                                   ` Eli Zaretskii
2020-01-19 17:57                                                     ` Yuan Fu
2020-01-19 18:43                                                       ` Eli Zaretskii
2020-01-19 19:35                                                         ` Yuan Fu
2020-01-19 20:07                                                           ` Eli Zaretskii
2020-01-20  1:22                                                             ` Yuan Fu
2020-01-20 18:03                                                               ` Eli Zaretskii
2020-01-22  1:50                                                                 ` Yuan Fu [this message]
2020-01-24  7:16                                                                   ` Eli Zaretskii
2020-01-24 20:12                                                                     ` Yuan Fu
2020-01-24 22:37                                                                       ` John Yates
2020-01-25  7:45                                                                         ` Eli Zaretskii
2020-01-25 14:33                                                                           ` John Yates
2020-01-25 17:10                                                                             ` Eli Zaretskii
2020-01-25  8:43                                                                         ` martin rudalics
2020-01-25 14:56                                                                           ` John Yates
2020-01-25 17:14                                                                             ` martin rudalics
2020-01-25 20:17                                                                               ` John Yates
2020-01-26  8:41                                                                                 ` martin rudalics
2020-01-26  4:18                                                                         ` Richard Stallman
2020-01-26  5:09                                                                           ` Drew Adams
2020-01-26  5:31                                                                             ` Yuan Fu
2020-01-26 17:12                                                                           ` Eli Zaretskii
2020-01-25  8:24                                                                       ` Eli Zaretskii
2020-01-25  8:58                                                                         ` martin rudalics
2020-01-25 10:25                                                                           ` Eli Zaretskii
2020-01-25 10:30                                                                             ` Eli Zaretskii
2020-01-25 22:34                                                                         ` Yuan Fu
2020-01-26  8:42                                                                           ` martin rudalics
2020-01-26 16:12                                                                             ` Yuan Fu
2020-01-26 16:57                                                                               ` martin rudalics
2020-01-27 15:56                                                                                 ` Yuan Fu
2020-01-27 19:18                                                                                   ` martin rudalics
2020-01-27 19:53                                                                                     ` Yuan Fu
2020-01-28  9:49                                                                                       ` martin rudalics
2020-01-28 20:01                                                                                         ` Yuan Fu
2020-01-28 20:33                                                                                           ` John Yates
2020-01-31 13:58                                                                           ` Eli Zaretskii
2020-01-31 15:25                                                                             ` Yuan Fu
2020-01-31 15:35                                                                               ` Eli Zaretskii
2020-01-25  8:43                                                                       ` martin rudalics
2020-01-25 10:21                                                                         ` Eli Zaretskii
2020-01-25 12:11                                                                           ` martin rudalics
2020-01-25 13:35                                                                             ` Eli Zaretskii
2020-01-25  8:42                                                                     ` martin rudalics
2020-01-19 18:30                                                   ` martin rudalics
2020-01-19 18:47                                                     ` Eli Zaretskii
2020-01-19 18:05                                                 ` martin rudalics

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=2BEA3843-859E-481B-8561-35384438EF7F@gmail.com \
    --to=casouri@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=john@yates-sheets.org \
    --cc=juri@linkov.net \
    --cc=monnier@iro.umontreal.ca \
    --cc=rudalics@gmx.at \
    /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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).