diff --git a/modules/ui/nav-flash/autoload.el b/modules/ui/nav-flash/autoload.el index 04eaf8691..1e8f2a03d 100644 --- a/modules/ui/nav-flash/autoload.el +++ b/modules/ui/nav-flash/autoload.el @@ -1,24 +1,40 @@ ;;; ui/nav-flash/autoload.el -*- lexical-binding: t; -*- ;;;###autoload -(defun +nav-flash*blink-cursor-maybe (orig-fn &rest args) - "Blink current line if the window has moved." - (if (or (not (window-start)) - (derived-mode-p 'term-mode)) - (apply orig-fn args) - (let* ((win-beg (window-start)) - (point (save-excursion (goto-char win-beg) (point-marker)))) - (apply orig-fn args) - (unless (equal point (save-excursion (goto-char win-beg) (point-marker))) - (+nav-flash/blink-cursor))))) +(defun +nav-flash-blink-cursor (&rest _) + "Blinks the current line in the current window, to make it clear where the +cursor has landed (typically after a large motion, like switching windows or +jumping to another part of the file)." + (unless (minibufferp) + (nav-flash-show) + ;; only show in the current window + (overlay-put compilation-highlight-overlay 'window (selected-window)))) + +;;;###autoload +(defun +nav-flash-blink-cursor-maybe (&rest _) + "Like `+nav-flash-blink-cursor', but no-ops if in special-mode or term-mode, +or triggered from one of `+nav-flash-exclude-commands'." + (unless (or (derived-mode-p 'special-mode 'term-mode) + (memq this-command +nav-flash-exclude-commands)) + (+nav-flash-blink-cursor))) + +;;;###autoload +(defun +nav-flash|delayed-blink-cursor (&rest _) + "Like `+nav-flash-blink-cursor', but links after a tiny pause, in case it +isn't clear at run-time if the point will be in the correct window/buffer (like +for `org-follow-link-hook')." + (run-at-time 0.1 nil #'+nav-flash|blink-cursor)) + +;;;###autoload +(defalias '+nav-flash|blink-cursor #'+nav-flash-blink-cursor) +;;;###autoload +(defalias '+nav-flash|blink-cursor-maybe #'+nav-flash-blink-cursor-maybe) + +;;;###autoload +(defalias '+nav-flash*blink-cursor #'+nav-flash-blink-cursor-maybe) ;;;###autoload (defun +nav-flash/blink-cursor (&rest _) "Blink current line using `nav-flash'." (interactive) - (unless (or (minibufferp) - (derived-mode-p 'special-mode) - (memq this-command '(mouse-set-point evil-mouse-drag-region))) - (nav-flash-show) - ;; only show in the current window - (overlay-put compilation-highlight-overlay 'window (selected-window)))) + (+nav-flash-blink-cursor-maybe)) diff --git a/modules/ui/nav-flash/config.el b/modules/ui/nav-flash/config.el index 3adf6ed9f..d59b7e2be 100644 --- a/modules/ui/nav-flash/config.el +++ b/modules/ui/nav-flash/config.el @@ -1,5 +1,10 @@ ;;; ui/nav-flash/config.el -*- lexical-binding: t; -*- +(defvar +nav-flash-exclude-commands + '(mouse-set-point evil-mouse-drag-region + +org/dwim-at-point org-find-file org-find-file-at-mouse) + "A list of commands that should not trigger nav-flash.") + (def-package! nav-flash :defer t :init @@ -9,13 +14,16 @@ '(doom-enter-window-hook imenu-after-jump-hook evil-jumps-post-jump-hook counsel-grep-post-action-hook dumb-jump-after-jump-hook) - #'+nav-flash/blink-cursor) + #'+nav-flash|blink-cursor-maybe) + + ;; `org' + (add-hook 'org-follow-link-hook #'+nav-flash|delayed-blink-cursor) ;; `saveplace' - (advice-add #'save-place-find-file-hook :after #'+nav-flash/blink-cursor) + (advice-add #'save-place-find-file-hook :after #'+nav-flash*blink-cursor) ;; `evil' - (advice-add #'evil-window-top :after #'+nav-flash/blink-cursor) - (advice-add #'evil-window-middle :after #'+nav-flash/blink-cursor) - (advice-add #'evil-window-bottom :after #'+nav-flash/blink-cursor)) + (advice-add #'evil-window-top :after #'+nav-flash*blink-cursor) + (advice-add #'evil-window-middle :after #'+nav-flash*blink-cursor) + (advice-add #'evil-window-bottom :after #'+nav-flash*blink-cursor))