3

Using the debugger in emacs is nice: You can step through the code with the next command, and emacs will always show the code line that is currently executed, like this:

  int x;
  int y;
=>int z;

But unfortunately, if your file is long, that pointer => will eventually move to the bottom and always show the current line at the bottom of the buffer.

It would be nicer if the pointer => always stayed in the middle of the buffer (vertically centered), so that I can see what's coming up right after the current line, before I say next again, like here:

  int y;
=>int z;
  std::cout << z;

Is that possible? Can I set that somewhere?

bwDraco
  • 46,683
dehmann
  • 2,333

2 Answers2

4

There's no built-in mechanism to keep the line centered, however this advice does the trick for me:

(defadvice gud-display-line (after gud-display-line-centered activate)
  "Center the line in the window"
  (when (and gud-overlay-arrow-position gdb-source-window)
    (with-selected-window gdb-source-window
      ; (marker-buffer gud-overlay-arrow-position)
      (save-restriction
        (goto-line (ad-get-arg 1))
        (recenter)))))
Trey Jackson
  • 4,071
0

As @MMM mentioned, the gdb-source-window is void with the newer emacs. With the inspiration from code here: http://kousik.blogspot.com/2005/10/highlight-current-line-in-gdbemacs.html, I am able to make it work with the following code(NOTE: it works both for recenter and highlight the current line):

(defvar gud-overlay
  (let* ((ov (make-overlay (point-min) (point-min))))
    (overlay-put ov 'face '(:background "#F6FECD")) ;; colors for Leuven theme
    ov)
  "Overlay variable for GUD highlighting.")
(defadvice gud-display-line (after my-gud-highlight act)
 "Highlight current line."
 (let* ((ov gud-overlay)
        (bf (gud-find-file true-file)))
   (save-excursion
     (with-selected-window (get-buffer-window bf)
       (save-restriction
         (goto-line (ad-get-arg 1))
         (recenter)))
     (set-buffer bf)
     (move-overlay ov (line-beginning-position) (line-end-position)
                   (current-buffer)))))