Emacs: Setup 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://ergoemacs.org/emacs/emacs_mouse_click_highlight_word.html'
Version 2016-07-18"
  (interactive "e")
  (let ((p1 (posn-point (event-start @click))))
    (goto-char p1)
    (isearch-forward-symbol-at-point)))

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

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

Note: mouse button and wheel have different syntax on {Microsoft Windows, Mac OS X, Linux}. To find the syntax, Alt+x describe-key, then press the button or wheel. [see Emacs: Mouse Config]

If you have a question, put $5 at patreon and message me on xah discord.
Or support me by Buy Xah Emacs Tutorial

Emacs Tutorial

Emacs Init

Emacs Keys

ELisp

ELisp Examples

ELisp Write Major Mode


ELisp Examples

Xah Commands

Text Transform Under Cursor

Commands Do thing-at-point

Command to Insert Things

Script Examples

Misc