When selecting an item from the occur buffer, the highlighted line is at the very bottom of the visible screen. This is less useful than having it 25-50% of the way down the screen(so it's easy to read the text around the found line). Is this possible?
1 Answer
I don't see the behavior that you describe, at all. For me, when I choose an occurrence in buffer *Occur*
it visits the occurrence in the source buffer, putting that smack in the middle of the source-buffer window (vertically).
But if you see what you describe, then just put some window-recentering code on occur-mode-find-occurrence-hook
.
Something like this. You can use any comparison condition you like. Here, I used "within 10 lines of the top or bottom", but you could use percentages etc.
(defun foo ()
(let ((line (line-number-at-pos)))
(cond ((<= line (+ (line-number-at-pos (window-start)) 10))
(recenter 10))
((>= line (- (line-number-at-pos (window-end)) 10))
(recenter -10)))))
(add-hook 'occur-mode-find-occurrence-hook 'foo)
-
1
-
Strange that I do not, then.
emacs -Q
on MS Windows 7. Any hits I click (or useRET
on) in the occur buffer are shown centered vertically in the source buffer.– DrewCommented Nov 17, 2014 at 2:51 -
You're right,
emacs -Q
(on Linux) gives the behavior you describe. Something must be buried somewhere is the setup.– Dan ♦Commented Nov 17, 2014 at 2:53