Preserve cursor+window position, rather than recenter
After n/N or */# searches with evil.
This commit is contained in:
parent
7481bfd4d5
commit
fb8d96f1cb
2 changed files with 12 additions and 2 deletions
|
@ -28,9 +28,19 @@ are open."
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom-recenter-a (&rest _)
|
(defun doom-recenter-a (&rest _)
|
||||||
"Generic advisor for recentering window (typically :after other functions)."
|
"Generic advice for recentering window (typically :after other functions)."
|
||||||
(recenter))
|
(recenter))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun doom-preserve-window-position-a (orig-fn &rest args)
|
||||||
|
"Generic advice for preserving cursor position on screen after scrolling."
|
||||||
|
(let ((row (cdr (posn-col-row (posn-at-point)))))
|
||||||
|
(prog1 (apply orig-fn args)
|
||||||
|
(save-excursion
|
||||||
|
(let ((target-row (- (line-number-at-pos) row)))
|
||||||
|
(unless (< target-row 0)
|
||||||
|
(evil-scroll-line-to-top target-row)))))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun doom-shut-up-a (orig-fn &rest args)
|
(defun doom-shut-up-a (orig-fn &rest args)
|
||||||
"Generic advisor for silencing noisy functions.
|
"Generic advisor for silencing noisy functions.
|
||||||
|
|
|
@ -174,7 +174,7 @@ directives. By default, this only recognizes C directives.")
|
||||||
evil-ex-search-previous
|
evil-ex-search-previous
|
||||||
evil-ex-search-forward
|
evil-ex-search-forward
|
||||||
evil-ex-search-backward))
|
evil-ex-search-backward))
|
||||||
(advice-add fn :after #'doom-recenter-a))
|
(advice-add fn :around #'doom-preserve-window-position-a))
|
||||||
|
|
||||||
;; --- custom interactive codes -----------
|
;; --- custom interactive codes -----------
|
||||||
;; These arg types will highlight matches in the current buffer
|
;; These arg types will highlight matches in the current buffer
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue