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?
Asked
Active
Viewed 170 times
1 Answers
9
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)

Drew
- 75,699
- 9
- 109
- 225
-
1Yup, that'll do it. I get OP's behavior, FWIW. – Dan Nov 17 '14 at 02:50
-
Strange that I do not, then. `emacs -Q` on MS Windows 7. Any hits I click (or use `RET` on) in the occur buffer are shown centered vertically in the source buffer. – Drew Nov 17 '14 at 02:51
-
You're right, `emacs -Q` (on Linux) gives the behavior you describe. Something must be buried somewhere is the setup. – Dan Nov 17 '14 at 02:53