Emacs: Mouse Click to Highlight Matching Words

By Xah Lee. Date: . Last updated: .

You can set mouse right-click to call isearch-forward-symbol-at-point (highlight clicked word).

Here's the command.

(defun xah-mouse-click-to-search (Click)
  "Mouse click to start `isearch-forward-symbol-at-point' (emacs 24.4) at clicked point.
URL `http://xahlee.info/emacs/emacs/emacs_mouse_click_highlight_word.html'
Version 2016-07-18"
  (interactive "e")
  (let ((xp1 (posn-point (event-start Click))))
    (goto-char xp1)
    (isearch-forward-symbol-at-point)))

Here's the code to set the mouse (this example is for Linux only):

;; set mouse
(cond
 ((eq system-type 'windows-nt)
  nil
  )
 ((eq system-type 'gnu/linux)
  ; right button
  (global-set-key (kbd "<mouse-3>") 'xah-click-to-search))
 ((eq system-type 'darwin) ; Mac
  nil
  ))

Emacs Init, Mouse