ui/nav-flash: refactor
+ Add +nav-flash-exclude-commands to control where +nav-flash-blink-cursor-maybe should not trigger nav-flash. + Rename API to conform to Doom naming conventions + +nav-flash-blink-cursor + +nav-flash-blink-cursor-maybe + +nav-flash|delayed-blink-cursor + +nav-flash|blink-cursor + +nav-flash|blink-cursor-maybe + +nav-flash*blink-cursor
This commit is contained in:
parent
ebd3b0223e
commit
f58f3c3604
2 changed files with 45 additions and 21 deletions
|
@ -1,24 +1,40 @@
|
||||||
;;; ui/nav-flash/autoload.el -*- lexical-binding: t; -*-
|
;;; ui/nav-flash/autoload.el -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +nav-flash*blink-cursor-maybe (orig-fn &rest args)
|
(defun +nav-flash-blink-cursor (&rest _)
|
||||||
"Blink current line if the window has moved."
|
"Blinks the current line in the current window, to make it clear where the
|
||||||
(if (or (not (window-start))
|
cursor has landed (typically after a large motion, like switching windows or
|
||||||
(derived-mode-p 'term-mode))
|
jumping to another part of the file)."
|
||||||
(apply orig-fn args)
|
(unless (minibufferp)
|
||||||
(let* ((win-beg (window-start))
|
(nav-flash-show)
|
||||||
(point (save-excursion (goto-char win-beg) (point-marker))))
|
;; only show in the current window
|
||||||
(apply orig-fn args)
|
(overlay-put compilation-highlight-overlay 'window (selected-window))))
|
||||||
(unless (equal point (save-excursion (goto-char win-beg) (point-marker)))
|
|
||||||
(+nav-flash/blink-cursor)))))
|
;;;###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
|
;;;###autoload
|
||||||
(defun +nav-flash/blink-cursor (&rest _)
|
(defun +nav-flash/blink-cursor (&rest _)
|
||||||
"Blink current line using `nav-flash'."
|
"Blink current line using `nav-flash'."
|
||||||
(interactive)
|
(interactive)
|
||||||
(unless (or (minibufferp)
|
(+nav-flash-blink-cursor-maybe))
|
||||||
(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))))
|
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
;;; ui/nav-flash/config.el -*- lexical-binding: t; -*-
|
;;; 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
|
(def-package! nav-flash
|
||||||
:defer t
|
:defer t
|
||||||
:init
|
:init
|
||||||
|
@ -9,13 +14,16 @@
|
||||||
'(doom-enter-window-hook
|
'(doom-enter-window-hook
|
||||||
imenu-after-jump-hook evil-jumps-post-jump-hook
|
imenu-after-jump-hook evil-jumps-post-jump-hook
|
||||||
counsel-grep-post-action-hook dumb-jump-after-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'
|
;; `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'
|
;; `evil'
|
||||||
(advice-add #'evil-window-top :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-middle :after #'+nav-flash*blink-cursor)
|
||||||
(advice-add #'evil-window-bottom :after #'+nav-flash/blink-cursor))
|
(advice-add #'evil-window-bottom :after #'+nav-flash*blink-cursor))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue