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?


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)
        (goto-line (ad-get-arg 1))
  • Doesn't work for me. When I say 'next' in gdb, emacs gives an error in process filter: Symbol's value as variable is void: gud-overlay-arrow-position – dehmann Apr 19 '10 at 2:22
  • 1
    fyi, works for me in GNU Emacs 24.3.1 (x86_64-unknown-linux-gnu, GTK+ Version 2.18.9). thanks! – simpleuser Jan 27 '15 at 20:42
  • It seems gdb-source-window can be Void. which causes errors. emacs 26.2 9 years later – MMM Jun 14 '19 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.