I'm using emacs 23.1.1 with gdb and gdb-many-windows.
My question is if it's possible to force gdb to always use the main source window for stepping through the code. What happens is that as I move through stack frames, if I happen to have the source file up in another emacs frames, emacs brings that frame to the foreground while leaving the gud frame in the background with keyboard foc开发者_如何学Cus.
What I'd like to do is to force emacs/gdb to use the primary source window for all tracing even if there is another frame with the same source file laying around somewhere.
Any ideas?
My emacs version is 24.3. So I am not really sure whether the following advice will solve your problem:
(defadvice gud-display-line (before one-source-window activate)
"Always use the same window to show source code."
(let ((buf (get-file-buffer true-file)))
(when (and buf gdb-source-window)
(set-window-buffer gdb-source-window buf))))
I found gud-display-line
with the arg true-file
in the old source there:
http://www.mit.edu/~mkgray/stuff/ath/afs/oldfiles/project/silk/root/afs/athena.mit.edu/contrib/xemacs/OldFiles/share/xemacs-packages/lisp/debug/gdb.el
Furthermore, gdb-source-window
can be found in a discussion about 23.1:
https://groups.google.com/forum/#!topic/gnu.emacs.bug/KS6bhNeJ9rc
Therefore, it looks like the things I used should be available in 23.1.
To avoid splitting of the window you can try this one:
(defadvice gud-display-line (around one-source-window activate)
"Always use the same window to show source code."
(let ((buf (get-file-buffer true-file)))
(when (and buf gdb-source-window)
(set-window-buffer gdb-source-window buf)))
(let (split-width-threshold split-width-threshold)
ad-do-it
))
Update for more recent versions of emacs based on Tobias' advice (tested on emacs 27):
(defun my-set-source-window (wrapped true-file line)
"Always use the same window to show source code."
(let ((buf (get-file-buffer true-file)))
(when (and buf gdb-source-window)
(set-window-buffer gdb-source-window buf)))
(let (split-width-threshold split-width-threshold)
(apply wrapped (list true-file line))))
(advice-add 'gud-display-line :around #'my-set-source-window)
精彩评论