Skip to content

Instantly share code, notes, and snippets.

@lawlist
Created August 8, 2020 02:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lawlist/5bca55b088f4f00d67ea219365f94002 to your computer and use it in GitHub Desktop.
Save lawlist/5bca55b088f4f00d67ea219365f94002 to your computer and use it in GitHub Desktop.
Draft of recentering while running isearch.
(defvar my-isearch-window-start '(nil 0)
"Record the `selected-window' and the Y-axis coordinate of point each time that
`isearch-update' calls `my-isearch-update-recenter' (via an advice). The value
of this variable will be a cons cell with the CAR being the `selected-window' and
the CDR being the Y-axis coordinate of point.")
(defun my-isearch-update-recenter ()
(let* ((win (selected-window))
(pt (point))
(y (cdr (nth 2 (posn-at-point pt win))))
(same-y-p (and y
(eq win (car my-isearch-window-start))
(= y (cdr my-isearch-window-start)))))
(when (and y (not same-y-p))
(recenter)
(setq my-isearch-window-start (cons win y)))))
(advice-add 'isearch-update :before 'my-isearch-update-recenter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment