6

When I grep something inside emacs and click to open one of the matching files. The matching line is always displayed at the bottom of the screen, and I have to scroll it up for a better view.

Is it possible to focus the matching line at the center of the screen automatically when opening one of the grep results?

2 Answers2

2

Displaying the source line in the middle of the window is the default behaviour, so something in your own config has caused your problem.

The variable C-hv next-error-recenter usually determines where the line is positioned. A value of -1 will place it at the bottom of the window (which may be the cause of your problem); a value of 0 at the top; nil means "if the line is already visible somewhere in the window simply move point to there, but otherwise display the line in the centre of the window".

If you want to centre the line even when the line was already visible, you can use a value of '(4) (which mimics passing a prefix argument C-u to recenter), but I think you'll find the nil behaviour less disorientating.

Failing anything else (or if the above is not the cause of your problem), have a look at C-hv next-error-hook in case something is using that.

phils
  • 48,657
  • 3
  • 76
  • 115
1

I recently faced the same problem. Searching around, I found centered-cursor-mode. It does not solve the problem directly, but by enabling it when looking at search results, I solved the problem well enough for my needs. Perhaps it will work for you as well.

mhucka
  • 163
  • 6