Emacs 23.1.1与gdb - 强制源窗口

6
我正在使用带有gdb和gdb-many-windows的emacs 23.1.1。
我的问题是是否可能强制gdb始终在主源窗口中跟踪代码。 当我浏览堆栈框架时,如果我恰好在另一个emacs框架中打开了源文件,那么emacs会将该框架置于前台,同时将框架留在后台并保持键盘焦点。
我想做的是强制emacs/gdb在所有跟踪中使用主要源窗口,即使有另一个具有相同源文件的框架。
有什么想法吗?

在Debian上使用Emacs 24.4.1,我仍然遇到了这个问题。顺便说一下,我找到了一个错误报告,但是还没有(至今)任何补丁:http://lists.gnu.org/archive/html/bug-gnu-emacs/2014-06/msg00097.html - pestophagous
2个回答

4

我的emacs版本是24.3,所以我不确定以下建议是否能解决您的问题:

(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))))

我在旧源代码中找到了带有参数true-filegud-display-linehttp://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 此外,关于23.1版本也可以找到gdb-source-window的讨论: https://groups.google.com/forum/#!topic/gnu.emacs.bug/KS6bhNeJ9rc 因此,看起来我使用的这些东西应该在23.1版本中可用。
为了避免窗口分割,您可以尝试这个方法:
(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
    ))

它只在第一个新文件上工作,如果GDB打开另一个源文件,它会分割主窗口。 - Mario Giovinazzo
1
我们来看一下gud是否能够合理地拆分。您能否尝试将'split-height-threshold'和'split-width-threshold'设置为'nil'? - Tobias
2
@MarioGiovinazzo 我添加了一个变量,其中我将 split-width-thresholdsplit-height-threshold 暂时设置为 nil,以防止主窗口分割。请尝试。 - Tobias
我发现defadvice可能会修复gdb-many-windows和gud将源文件加载到gdb窗口中的一些烦人问题(例如使用comint缓冲区而不是中左侧的源窗口)。然而,它似乎并不可靠,我仍然能够触发这个问题。我怀疑这是与框架相同的错误。我在这里记录了我的观察结果:http://nurpax.github.io/posts/2014-10-12-fixing-gdb-many-windows-source-buffer.html。 - Nurpax
1
@Nurpax 请参阅https://dev59.com/JnnZa4cB1Zd3GeqPr5n1 - OLL

1

根据Tobias的建议,针对更近期版本的emacs进行更新(在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)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接