1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 18:40:39 -08:00

Search and highlight symbol at point.

* doc/emacs/display.texi (Highlight Interactively): Add global keybindings
with the key prefix `M-s h'.  Document old command `highlight-phrase'.
Document new command `highlight-symbol-at-point'.

* lisp/bindings.el (search-map): Bind `highlight-symbol-at-point' to
`M-s h .'. 

* lisp/hi-lock.el (highlight-symbol-at-point): New alias for the new
command `hi-lock-face-symbol-at-point'.
(hi-lock-face-symbol-at-point): New command.
(hi-lock-map): Bind `highlight-symbol-at-point' to `C-x w .'.
(hi-lock-menu): Add `highlight-symbol-at-point'.
(hi-lock-mode): Doc fix.

* lisp/isearch.el (isearch-forward-symbol-at-point): New command.
(search-map): Bind `isearch-forward-symbol-at-point' to `M-s .'.
(isearch-highlight-regexp): Add a regexp which matches
words/symbols for word/symbol mode.

* lisp/subr.el (find-tag-default-bounds): New function with the body
mostly moved from `find-tag-default'.
(find-tag-default): Move most code to `find-tag-default-bounds',
call it and apply `buffer-substring-no-properties' afterwards.

Fixes: debbugs:14427
This commit is contained in:
Juri Linkov 2013-06-03 11:51:50 +03:00
parent 26b3353ad0
commit e5e4a94293
8 changed files with 153 additions and 17 deletions

View file

@ -37,18 +37,18 @@
;;
;; In program source code highlight a variable to quickly see all
;; places it is modified or referenced:
;; M-x highlight-regexp ground_contact_switches_closed RET RET
;; M-x highlight-regexp RET ground_contact_switches_closed RET RET
;;
;; In a shell or other buffer that is showing lots of program
;; output, highlight the parts of the output you're interested in:
;; M-x highlight-regexp Total execution time [0-9]+ RET hi-blue-b RET
;; M-x highlight-regexp RET Total execution time [0-9]+ RET hi-blue-b RET
;;
;; In buffers displaying tables, highlight the lines you're interested in:
;; M-x highlight-lines-matching-regexp January 2000 RET hi-black-b RET
;; M-x highlight-lines-matching-regexp RET January 2000 RET hi-black-b RET
;;
;; When writing text, highlight personal cliches. This can be
;; amusing.
;; M-x highlight-phrase as can be seen RET RET
;; M-x highlight-phrase RET as can be seen RET RET
;;
;; Setup:
;;
@ -252,6 +252,10 @@ a library is being loaded.")
'(menu-item "Highlight Lines..." highlight-lines-matching-regexp
:help "Highlight lines containing match of PATTERN (a regexp)."))
(define-key-after map [highlight-symbol-at-point]
'(menu-item "Highlight Symbol at Point" highlight-symbol-at-point
:help "Highlight symbol found near point without prompting."))
(define-key-after map [unhighlight-regexp]
'(menu-item "Remove Highlighting..." unhighlight-regexp
:help "Remove previously entered highlighting pattern."
@ -274,6 +278,7 @@ a library is being loaded.")
(define-key map "\C-xwl" 'highlight-lines-matching-regexp)
(define-key map "\C-xwp" 'highlight-phrase)
(define-key map "\C-xwh" 'highlight-regexp)
(define-key map "\C-xw." 'highlight-symbol-at-point)
(define-key map "\C-xwr" 'unhighlight-regexp)
(define-key map "\C-xwb" 'hi-lock-write-interactive-patterns)
map)
@ -333,6 +338,10 @@ which can be called interactively, are:
\\[highlight-lines-matching-regexp] REGEXP FACE
Highlight lines containing matches of REGEXP in current buffer with FACE.
\\[highlight-symbol-at-point]
Highlight the symbol found near point without prompting, using the next
available face automatically.
\\[unhighlight-regexp] REGEXP
Remove highlighting on matches of REGEXP in current buffer.
@ -490,6 +499,27 @@ highlighting will not update as you type."
(unless hi-lock-mode (hi-lock-mode 1))
(hi-lock-set-pattern regexp face))
;;;###autoload
(defalias 'highlight-symbol-at-point 'hi-lock-face-symbol-at-point)
;;;###autoload
(defun hi-lock-face-symbol-at-point ()
"Set face of each match of the symbol at point.
Use `find-tag-default-as-regexp' to retrieve the symbol at point.
Use non-nil `hi-lock-auto-select-face' to retrieve the next face
from `hi-lock-face-defaults' automatically.
Use Font lock mode, if enabled, to highlight symbol at point.
Otherwise, use overlays for highlighting. If overlays are used,
the highlighting will not update as you type."
(interactive)
(let* ((regexp (hi-lock-regexp-okay
(find-tag-default-as-regexp)))
(hi-lock-auto-select-face t)
(face (hi-lock-read-face-name)))
(or (facep face) (setq face 'hi-yellow))
(unless hi-lock-mode (hi-lock-mode 1))
(hi-lock-set-pattern regexp face)))
(defun hi-lock-keyword->face (keyword)
(cadr (cadr (cadr keyword)))) ; Keyword looks like (REGEXP (0 'FACE) ...).