Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

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))
share|improve this answer
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
fyi, works for me in GNU Emacs 24.3.1 (x86_64-unknown-linux-gnu, GTK+ Version 2.18.9). thanks! – user9999999 Jan 27 '15 at 20:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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