Skip to content

Instantly share code, notes, and snippets.

@olejorgenb
Created November 26, 2016 22:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olejorgenb/ae562bb0aee796a9c41eae3587f181ac to your computer and use it in GitHub Desktop.
Save olejorgenb/ae562bb0aee796a9c41eae3587f181ac to your computer and use it in GitHub Desktop.
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)
(deactivate-mark)
(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