Ctrl 押下しながら単語上でマウスクリックでバッファ上の同じ単語をハイライト表示する機能。

emacsなのにマウスで操作って邪道だとか言われそうですが・・・。
この変数どこで使われてるんだ?とかいう時に気軽に使えます。
コードを読む時、occur使うまでもないかなって時にかなーり重宝してます。

(global-set-key [C-down-mouse-1] 'hilight-current-word)
(global-set-key [M-down-mouse-1] 'hilight-current-word-lenient)
(defun hilight-current-word(e)
  (interactive "e")
  (delete-all-overlays)
  (mouse-set-point e)
  (save-excursion
	(setq str
		  (buffer-substring-no-properties
		   (progn (skip-syntax-backward "w_") (point))
		   (progn (skip-syntax-forward "w_")  (point))))
	(unless (= 0 (length str)) (hilight-a-word (concat "\\<" str "\\>") ))))
(defun hilight-current-word-lenient(e)
  (interactive "e")
  (delete-all-overlays)
  (mouse-set-point e)
  (save-excursion
	(setq str
		  (buffer-substring-no-properties
		   (progn (skip-syntax-backward "w_") (point))
		   (progn (skip-syntax-forward "w_")  (point))))
	(unless (= 0 (length str)) (hilight-a-word str ))))
  
(defface my-hilight '*1
	(while (re-search-forward word nil t)
	  (overlay-put (make-overlay (match-beginning 0) (match-end 0)) 'face 'my-hilight))))

(defun delete-all-overlays()
  (dolist (overlay (overlays-in (point-min) (point-max)))
	(delete-overlay overlay)))

*1:t (:background "salmon"))) nil) (defun hilight-a-word (word) (save-excursion (goto-char (point-min