Skip to content

Instantly share code, notes, and snippets.

@tttuuu888
Created November 30, 2020 15:00
Show Gist options
  • Save tttuuu888/ab4bd54785927eb53668b68807809407 to your computer and use it in GitHub Desktop.
Save tttuuu888/ab4bd54785927eb53668b68807809407 to your computer and use it in GitHub Desktop.
Toggle highlighting current word
(require 'hi-lock)
(defun toggle-highlight-word ()
(interactive)
(let ((regex (concat "\\_<" (current-word) "\\_>")))
(if (member regex (mapcar #'car hi-lock-interactive-patterns))
(unhighlight-regexp regex)
(highlight-symbol-at-point))))
(defun unhighlight-all-highlighted-words ()
(interactive)
(let ((hi-regexs (mapcar #'car hi-lock-interactive-patterns)))
(mapcar (lambda (regex) (unhighlight-regexp regex)) hi-regexs)))
(global-set-key [f9] 'toggle-highlight-word)
(global-set-key [S-f9] 'unhighlight-all-highlighted-words)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment