During search and especially search-and-replace it would be nice to have the surrounding lines as context. But when jumping to the next hit, the cursor sometimes ends at the lowest visible line (or even worse at a corner).
I would like the text to follow the cursor during search. Is there a way to do this?
This question is similar to this one, but I don't want that all the time but only when jumping during search
(defadvice isearch-update (before my-isearch-update activate)
;; not the scrolling command
(not (eq this-command 'isearch-other-control-char))
;; not the empty string
(> (length isearch-string) 0)
;; not the first key (to lazy highlight all matches w/o recenter)
(> (length isearch-cmds) 2)
;; the point in within the given window boundaries
(let ((line (count-screen-lines (point) (window-start))))
(or (> line (* (/ (window-height) 4) 3))
(< line (* (/ (window-height) 9) 1)))))
(let ((recenter-position 0.3))