Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Highlight symbol at point on mouse click (emacs)
;; Only tested with spacemacs
(defvar my-current-focus-symbol nil)
(make-variable-buffer-local 'my-current-focus-symbol)
(defvar my-focus-symbol-face 'hi-yellow)
(defun mouse-set-point-and-hl-symbol (event)
(interactive "e")
(mouse-set-point event)
;; Evil workaround crap (without this every other click visual state is activated...)
;; (not 100% sure why this works, but see the binding of [down-mouse-1] and
;; the white-listing of mouse-set-point in that code)
(let ((symbol (thing-at-point 'symbol)))
(when my-current-focus-symbol
(hlt-unhighlight-symbol my-current-focus-symbol nil))
(when symbol
(hlt-highlight-symbol symbol nil my-focus-symbol-face))
(setq my-current-focus-symbol symbol)
(global-set-key [mouse-1] 'mouse-set-point-and-hl-symbol)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment