Skip to content

Instantly share code, notes, and snippets.

@takaxp
Last active December 3, 2018 07:40
Show Gist options
  • Save takaxp/1e1d57164af68ad7f995dd8b83a1b3ee to your computer and use it in GitHub Desktop.
Save takaxp/1e1d57164af68ad7f995dd8b83a1b3ee to your computer and use it in GitHub Desktop.
move-cursor-hook
(defcustom move-cursor-hook nil
"Hook runs when you move the cursor."
:type 'hook
:group 'convenience)
(defun ad:cur:next-line (&optional _arg _try-vscroll)
(run-hooks 'move-cursor-hook))
(defun ad:cur:previous-line (&optional _arg _try-vscroll)
(run-hooks 'move-cursor-hook))
(defun ad:cur:forward-char (&optional _N)
(run-hooks 'move-cursor-hook))
(defun ad:cur:backward-char (&optional _N)
(run-hooks 'move-cursor-hook))
(defun ad:cur:syntax-subword-forward (&optional _N)
(run-hooks 'move-cursor-hook))
(defun ad:cur:syntax-subword-backward (&optional _N)
(run-hooks 'move-cursor-hook))
(defun ad:cur:move-beginning-of-line (_ARG)
(run-hooks 'move-cursor-hook))
(defun ad:cur:move-end-of-line (_ARG)
(run-hooks 'move-cursor-hook))
(advice-add 'next-line :before #'ad:cur:next-line)
(advice-add 'previous-line :before #'ad:cur:previous-line)
(advice-add 'forward-char :before #'ad:cur:forward-char)
(advice-add 'backward-char :before #'ad:cur:backward-char)
(advice-add 'syntax-subword-forward :before #'ad:cur:syntax-subword-forward)
(advice-add 'syntax-subword-backward :before #'ad:cur:syntax-subword-backward)
(advice-add 'move-beginning-of-line :before #'ad:cur:move-beginning-of-line)
(advice-add 'move-end-of-line :before #'ad:cur:move-end-of-line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment