aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2013-06-03 11:51:50 +0300
committerJuri Linkov2013-06-03 11:51:50 +0300
commite5e4a94293d5a9a157557e53b4fea4e5d280673e (patch)
tree2384760b1e0aae2ec3622021c6438463ed8fb0af
parent26b3353ad0200b6e3dae8bacbf61c7c069a26b2a (diff)
downloademacs-e5e4a94293d5a9a157557e53b4fea4e5d280673e.tar.gz
emacs-e5e4a94293d5a9a157557e53b4fea4e5d280673e.zip
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
-rw-r--r--doc/emacs/ChangeLog6
-rw-r--r--doc/emacs/display.texi48
-rw-r--r--etc/NEWS14
-rw-r--r--lisp/ChangeLog22
-rw-r--r--lisp/bindings.el1
-rw-r--r--lisp/hi-lock.el38
-rw-r--r--lisp/isearch.el27
-rw-r--r--lisp/subr.el14
8 files changed, 153 insertions, 17 deletions
diff --git a/doc/emacs/ChangeLog b/doc/emacs/ChangeLog
index b1f9fb2a40d..f0b89a15fcc 100644
--- a/doc/emacs/ChangeLog
+++ b/doc/emacs/ChangeLog
@@ -1,3 +1,9 @@
12013-06-03 Juri Linkov <juri@jurta.org>
2
3 * display.texi (Highlight Interactively): Add global keybindings
4 with the key prefix `M-s h'. Document old command `highlight-phrase'.
5 Document new command `highlight-symbol-at-point'.
6
12013-06-01 Glenn Morris <rgm@gnu.org> 72013-06-01 Glenn Morris <rgm@gnu.org>
2 8
3 * programs.texi (Semantic): Fix typo. 9 * programs.texi (Semantic): Fix typo.
diff --git a/doc/emacs/display.texi b/doc/emacs/display.texi
index f5ec8946e1b..482d7e7741a 100644
--- a/doc/emacs/display.texi
+++ b/doc/emacs/display.texi
@@ -903,14 +903,16 @@ that you specify explicitly the regular expressions to highlight. You
903control them with these commands: 903control them with these commands:
904 904
905@table @kbd 905@table @kbd
906@item C-x w h @var{regexp} @key{RET} @var{face} @key{RET} 906@item M-s h r @var{regexp} @key{RET} @var{face} @key{RET}
907@itemx C-x w h @var{regexp} @key{RET} @var{face} @key{RET}
908@kindex M-s h r
907@kindex C-x w h 909@kindex C-x w h
908@findex highlight-regexp 910@findex highlight-regexp
909Highlight text that matches @var{regexp} using face @var{face} 911Highlight text that matches @var{regexp} using face @var{face}
910(@code{highlight-regexp}). The highlighting will remain as long as 912(@code{highlight-regexp}). The highlighting will remain as long as
911the buffer is loaded. For example, to highlight all occurrences of 913the buffer is loaded. For example, to highlight all occurrences of
912the word ``whim'' using the default face (a yellow background) 914the word ``whim'' using the default face (a yellow background)
913@kbd{C-x w h whim @key{RET} @key{RET}}. Any face can be used for 915@kbd{M-s h r whim @key{RET} @key{RET}}. Any face can be used for
914highlighting, Hi Lock provides several of its own and these are 916highlighting, Hi Lock provides several of its own and these are
915pre-loaded into a list of default values. While being prompted 917pre-loaded into a list of default values. While being prompted
916for a face use @kbd{M-n} and @kbd{M-p} to cycle through them. 918for a face use @kbd{M-n} and @kbd{M-p} to cycle through them.
@@ -918,7 +920,9 @@ for a face use @kbd{M-n} and @kbd{M-p} to cycle through them.
918You can use this command multiple times, specifying various regular 920You can use this command multiple times, specifying various regular
919expressions to highlight in different ways. 921expressions to highlight in different ways.
920 922
921@item C-x w r @var{regexp} @key{RET} 923@item M-s h u @var{regexp} @key{RET}
924@itemx C-x w r @var{regexp} @key{RET}
925@kindex M-s h u
922@kindex C-x w r 926@kindex C-x w r
923@findex unhighlight-regexp 927@findex unhighlight-regexp
924Unhighlight @var{regexp} (@code{unhighlight-regexp}). 928Unhighlight @var{regexp} (@code{unhighlight-regexp}).
@@ -926,13 +930,15 @@ Unhighlight @var{regexp} (@code{unhighlight-regexp}).
926If you invoke this from the menu, you select the expression to 930If you invoke this from the menu, you select the expression to
927unhighlight from a list. If you invoke this from the keyboard, you 931unhighlight from a list. If you invoke this from the keyboard, you
928use the minibuffer. It will show the most recently added regular 932use the minibuffer. It will show the most recently added regular
929expression; use @kbd{M-p} to show the next older expression and 933expression; use @kbd{M-n} to show the next older expression and
930@kbd{M-n} to select the next newer expression. (You can also type the 934@kbd{M-p} to select the next newer expression. (You can also type the
931expression by hand, with completion.) When the expression you want to 935expression by hand, with completion.) When the expression you want to
932unhighlight appears in the minibuffer, press @kbd{@key{RET}} to exit 936unhighlight appears in the minibuffer, press @kbd{@key{RET}} to exit
933the minibuffer and unhighlight it. 937the minibuffer and unhighlight it.
934 938
935@item C-x w l @var{regexp} @key{RET} @var{face} @key{RET} 939@item M-s h l @var{regexp} @key{RET} @var{face} @key{RET}
940@itemx C-x w l @var{regexp} @key{RET} @var{face} @key{RET}
941@kindex M-s h l
936@kindex C-x w l 942@kindex C-x w l
937@findex highlight-lines-matching-regexp 943@findex highlight-lines-matching-regexp
938@cindex lines, highlighting 944@cindex lines, highlighting
@@ -940,7 +946,31 @@ the minibuffer and unhighlight it.
940Highlight entire lines containing a match for @var{regexp}, using face 946Highlight entire lines containing a match for @var{regexp}, using face
941@var{face} (@code{highlight-lines-matching-regexp}). 947@var{face} (@code{highlight-lines-matching-regexp}).
942 948
943@item C-x w b 949@item M-s h p @var{phrase} @key{RET} @var{face} @key{RET}
950@itemx C-x w p @var{phrase} @key{RET} @var{face} @key{RET}
951@kindex M-s h p
952@kindex C-x w p
953@findex highlight-phrase
954@cindex phrase, highlighting
955@cindex highlighting phrase
956Highlight matches of @var{phrase}, using face @var{face}
957(@code{highlight-phrase}). @var{phrase} can be any regexp,
958but spaces will be replaced by matches to whitespace and
959initial lower-case letters will become case insensitive.
960
961@item M-s h .
962@itemx C-x w .
963@kindex M-s h .
964@kindex C-x w .
965@findex highlight-symbol-at-point
966@cindex symbol, highlighting
967@cindex highlighting symbol at point
968Highlight the symbol found near point without prompting, using the next
969available face automatically (@code{highlight-symbol-at-point}).
970
971@item M-s h w
972@itemx C-x w b
973@kindex M-s h w
944@kindex C-x w b 974@kindex C-x w b
945@findex hi-lock-write-interactive-patterns 975@findex hi-lock-write-interactive-patterns
946Insert all the current highlighting regexp/face pairs into the buffer 976Insert all the current highlighting regexp/face pairs into the buffer
@@ -952,7 +982,9 @@ These patterns are extracted from the comments, if appropriate, if you
952invoke @kbd{M-x hi-lock-find-patterns}, or if you visit the file while 982invoke @kbd{M-x hi-lock-find-patterns}, or if you visit the file while
953Hi Lock mode is enabled (since that runs @code{hi-lock-find-patterns}). 983Hi Lock mode is enabled (since that runs @code{hi-lock-find-patterns}).
954 984
955@item C-x w i 985@item M-s h f
986@itemx C-x w i
987@kindex M-s h f
956@kindex C-x w i 988@kindex C-x w i
957@findex hi-lock-find-patterns 989@findex hi-lock-find-patterns
958Extract regexp/face pairs from comments in the current buffer 990Extract regexp/face pairs from comments in the current buffer
diff --git a/etc/NEWS b/etc/NEWS
index b2ecba79684..bb66faa183c 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -260,8 +260,22 @@ callers to fit the image to a frame other than the selected frame.
260entries displayed by `Info-index-next', `Info-virtual-index' and 260entries displayed by `Info-index-next', `Info-virtual-index' and
261`info-apropos'. 261`info-apropos'.
262 262
263** Hi-Lock
264
265*** New option `hi-lock-auto-select-face'. When non-nil, hi-lock commands
266will cycle through faces in `hi-lock-face-defaults' without prompting.
267
268+++
269*** New global command `M-s h .' (`highlight-symbol-at-point')
270highlights the symbol found near point without prompting,
271using the next face automatically.
272
263** Search and Replace 273** Search and Replace
264 274
275*** New global command `M-s .' (`isearch-forward-symbol-at-point')
276starts a symbol (identifier) incremental search forward with the
277symbol found near point added to the search string initially.
278
265*** `C-x 8 RET' in Isearch mode reads a character by its Unicode name 279*** `C-x 8 RET' in Isearch mode reads a character by its Unicode name
266and adds it to the search string. 280and adds it to the search string.
267 281
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 7ee43e602f9..35ea3231c93 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,25 @@
12013-06-03 Juri Linkov <juri@jurta.org>
2
3 * bindings.el (search-map): Bind `highlight-symbol-at-point' to
4 `M-s h .'. (Bug#14427)
5
6 * hi-lock.el (highlight-symbol-at-point): New alias for the new
7 command `hi-lock-face-symbol-at-point'.
8 (hi-lock-face-symbol-at-point): New command.
9 (hi-lock-map): Bind `highlight-symbol-at-point' to `C-x w .'.
10 (hi-lock-menu): Add `highlight-symbol-at-point'.
11 (hi-lock-mode): Doc fix.
12
13 * isearch.el (isearch-forward-symbol-at-point): New command.
14 (search-map): Bind `isearch-forward-symbol-at-point' to `M-s .'.
15 (isearch-highlight-regexp): Add a regexp which matches
16 words/symbols for word/symbol mode.
17
18 * subr.el (find-tag-default-bounds): New function with the body
19 mostly moved from `find-tag-default'.
20 (find-tag-default): Move most code to `find-tag-default-bounds',
21 call it and apply `buffer-substring-no-properties' afterwards.
22
12013-06-03 Tassilo Horn <tsdh@gnu.org> 232013-06-03 Tassilo Horn <tsdh@gnu.org>
2 24
3 * eshell/em-term.el (eshell-term-initialize): Use 25 * eshell/em-term.el (eshell-term-initialize): Use
diff --git a/lisp/bindings.el b/lisp/bindings.el
index fe0eabb77af..2013c079820 100644
--- a/lisp/bindings.el
+++ b/lisp/bindings.el
@@ -894,6 +894,7 @@ if `inhibit-field-text-motion' is non-nil."
894(define-key search-map "hr" 'highlight-regexp) 894(define-key search-map "hr" 'highlight-regexp)
895(define-key search-map "hp" 'highlight-phrase) 895(define-key search-map "hp" 'highlight-phrase)
896(define-key search-map "hl" 'highlight-lines-matching-regexp) 896(define-key search-map "hl" 'highlight-lines-matching-regexp)
897(define-key search-map "h." 'highlight-symbol-at-point)
897(define-key search-map "hu" 'unhighlight-regexp) 898(define-key search-map "hu" 'unhighlight-regexp)
898(define-key search-map "hf" 'hi-lock-find-patterns) 899(define-key search-map "hf" 'hi-lock-find-patterns)
899(define-key search-map "hw" 'hi-lock-write-interactive-patterns) 900(define-key search-map "hw" 'hi-lock-write-interactive-patterns)
diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el
index e2dc4eac67b..d0a82cd97b0 100644
--- a/lisp/hi-lock.el
+++ b/lisp/hi-lock.el
@@ -37,18 +37,18 @@
37;; 37;;
38;; In program source code highlight a variable to quickly see all 38;; In program source code highlight a variable to quickly see all
39;; places it is modified or referenced: 39;; places it is modified or referenced:
40;; M-x highlight-regexp ground_contact_switches_closed RET RET 40;; M-x highlight-regexp RET ground_contact_switches_closed RET RET
41;; 41;;
42;; In a shell or other buffer that is showing lots of program 42;; In a shell or other buffer that is showing lots of program
43;; output, highlight the parts of the output you're interested in: 43;; output, highlight the parts of the output you're interested in:
44;; M-x highlight-regexp Total execution time [0-9]+ RET hi-blue-b RET 44;; M-x highlight-regexp RET Total execution time [0-9]+ RET hi-blue-b RET
45;; 45;;
46;; In buffers displaying tables, highlight the lines you're interested in: 46;; In buffers displaying tables, highlight the lines you're interested in:
47;; M-x highlight-lines-matching-regexp January 2000 RET hi-black-b RET 47;; M-x highlight-lines-matching-regexp RET January 2000 RET hi-black-b RET
48;; 48;;
49;; When writing text, highlight personal cliches. This can be 49;; When writing text, highlight personal cliches. This can be
50;; amusing. 50;; amusing.
51;; M-x highlight-phrase as can be seen RET RET 51;; M-x highlight-phrase RET as can be seen RET RET
52;; 52;;
53;; Setup: 53;; Setup:
54;; 54;;
@@ -252,6 +252,10 @@ a library is being loaded.")
252 '(menu-item "Highlight Lines..." highlight-lines-matching-regexp 252 '(menu-item "Highlight Lines..." highlight-lines-matching-regexp
253 :help "Highlight lines containing match of PATTERN (a regexp).")) 253 :help "Highlight lines containing match of PATTERN (a regexp)."))
254 254
255 (define-key-after map [highlight-symbol-at-point]
256 '(menu-item "Highlight Symbol at Point" highlight-symbol-at-point
257 :help "Highlight symbol found near point without prompting."))
258
255 (define-key-after map [unhighlight-regexp] 259 (define-key-after map [unhighlight-regexp]
256 '(menu-item "Remove Highlighting..." unhighlight-regexp 260 '(menu-item "Remove Highlighting..." unhighlight-regexp
257 :help "Remove previously entered highlighting pattern." 261 :help "Remove previously entered highlighting pattern."
@@ -274,6 +278,7 @@ a library is being loaded.")
274 (define-key map "\C-xwl" 'highlight-lines-matching-regexp) 278 (define-key map "\C-xwl" 'highlight-lines-matching-regexp)
275 (define-key map "\C-xwp" 'highlight-phrase) 279 (define-key map "\C-xwp" 'highlight-phrase)
276 (define-key map "\C-xwh" 'highlight-regexp) 280 (define-key map "\C-xwh" 'highlight-regexp)
281 (define-key map "\C-xw." 'highlight-symbol-at-point)
277 (define-key map "\C-xwr" 'unhighlight-regexp) 282 (define-key map "\C-xwr" 'unhighlight-regexp)
278 (define-key map "\C-xwb" 'hi-lock-write-interactive-patterns) 283 (define-key map "\C-xwb" 'hi-lock-write-interactive-patterns)
279 map) 284 map)
@@ -333,6 +338,10 @@ which can be called interactively, are:
333\\[highlight-lines-matching-regexp] REGEXP FACE 338\\[highlight-lines-matching-regexp] REGEXP FACE
334 Highlight lines containing matches of REGEXP in current buffer with FACE. 339 Highlight lines containing matches of REGEXP in current buffer with FACE.
335 340
341\\[highlight-symbol-at-point]
342 Highlight the symbol found near point without prompting, using the next
343 available face automatically.
344
336\\[unhighlight-regexp] REGEXP 345\\[unhighlight-regexp] REGEXP
337 Remove highlighting on matches of REGEXP in current buffer. 346 Remove highlighting on matches of REGEXP in current buffer.
338 347
@@ -490,6 +499,27 @@ highlighting will not update as you type."
490 (unless hi-lock-mode (hi-lock-mode 1)) 499 (unless hi-lock-mode (hi-lock-mode 1))
491 (hi-lock-set-pattern regexp face)) 500 (hi-lock-set-pattern regexp face))
492 501
502;;;###autoload
503(defalias 'highlight-symbol-at-point 'hi-lock-face-symbol-at-point)
504;;;###autoload
505(defun hi-lock-face-symbol-at-point ()
506 "Set face of each match of the symbol at point.
507Use `find-tag-default-as-regexp' to retrieve the symbol at point.
508Use non-nil `hi-lock-auto-select-face' to retrieve the next face
509from `hi-lock-face-defaults' automatically.
510
511Use Font lock mode, if enabled, to highlight symbol at point.
512Otherwise, use overlays for highlighting. If overlays are used,
513the highlighting will not update as you type."
514 (interactive)
515 (let* ((regexp (hi-lock-regexp-okay
516 (find-tag-default-as-regexp)))
517 (hi-lock-auto-select-face t)
518 (face (hi-lock-read-face-name)))
519 (or (facep face) (setq face 'hi-yellow))
520 (unless hi-lock-mode (hi-lock-mode 1))
521 (hi-lock-set-pattern regexp face)))
522
493(defun hi-lock-keyword->face (keyword) 523(defun hi-lock-keyword->face (keyword)
494 (cadr (cadr (cadr keyword)))) ; Keyword looks like (REGEXP (0 'FACE) ...). 524 (cadr (cadr (cadr keyword)))) ; Keyword looks like (REGEXP (0 'FACE) ...).
495 525
diff --git a/lisp/isearch.el b/lisp/isearch.el
index acecc74d1be..c49b0d7fc59 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -667,6 +667,7 @@ Each set is a vector of the form:
667(define-key esc-map "\C-r" 'isearch-backward-regexp) 667(define-key esc-map "\C-r" 'isearch-backward-regexp)
668(define-key search-map "w" 'isearch-forward-word) 668(define-key search-map "w" 'isearch-forward-word)
669(define-key search-map "_" 'isearch-forward-symbol) 669(define-key search-map "_" 'isearch-forward-symbol)
670(define-key search-map "." 'isearch-forward-symbol-at-point)
670 671
671;; Entry points to isearch-mode. 672;; Entry points to isearch-mode.
672 673
@@ -806,6 +807,25 @@ as a regexp. See the command `isearch-forward' for more information."
806 (interactive "P\np") 807 (interactive "P\np")
807 (isearch-mode nil (null not-regexp) nil (not no-recursive-edit))) 808 (isearch-mode nil (null not-regexp) nil (not no-recursive-edit)))
808 809
810(defun isearch-forward-symbol-at-point ()
811 "Do incremental search forward for a symbol found near point.
812Like ordinary incremental search except that the symbol found at point
813is added to the search string initially as a regexp surrounded
814by symbol boundary constructs \\_< and \\_>.
815See the command `isearch-forward-symbol' for more information."
816 (interactive)
817 (isearch-forward-symbol nil 1)
818 (let ((bounds (find-tag-default-bounds)))
819 (cond
820 (bounds
821 (when (< (car bounds) (point))
822 (goto-char (car bounds)))
823 (isearch-yank-string
824 (buffer-substring-no-properties (car bounds) (cdr bounds))))
825 (t
826 (setq isearch-error "No symbol at point")
827 (isearch-update)))))
828
809 829
810;; isearch-mode only sets up incremental search for the minor mode. 830;; isearch-mode only sets up incremental search for the minor mode.
811;; All the work is done by the isearch-mode commands. 831;; All the work is done by the isearch-mode commands.
@@ -1752,7 +1772,10 @@ and reads its face argument using `hi-lock-read-face-name'."
1752 (isearch-done nil t) 1772 (isearch-done nil t)
1753 (isearch-clean-overlays)) 1773 (isearch-clean-overlays))
1754 (require 'hi-lock nil t) 1774 (require 'hi-lock nil t)
1755 (let ((string (cond (isearch-regexp isearch-string) 1775 (let ((regexp (cond ((functionp isearch-word)
1776 (funcall isearch-word isearch-string))
1777 (isearch-word (word-search-regexp isearch-string))
1778 (isearch-regexp isearch-string)
1756 ((if (and (eq isearch-case-fold-search t) 1779 ((if (and (eq isearch-case-fold-search t)
1757 search-upper-case) 1780 search-upper-case)
1758 (isearch-no-upper-case-p 1781 (isearch-no-upper-case-p
@@ -1768,7 +1791,7 @@ and reads its face argument using `hi-lock-read-face-name'."
1768 (regexp-quote s)))) 1791 (regexp-quote s))))
1769 isearch-string "")) 1792 isearch-string ""))
1770 (t (regexp-quote isearch-string))))) 1793 (t (regexp-quote isearch-string)))))
1771 (hi-lock-face-buffer string (hi-lock-read-face-name))) 1794 (hi-lock-face-buffer regexp (hi-lock-read-face-name)))
1772 (and isearch-recursive-edit (exit-recursive-edit))) 1795 (and isearch-recursive-edit (exit-recursive-edit)))
1773 1796
1774 1797
diff --git a/lisp/subr.el b/lisp/subr.el
index 23684f02b87..6b1dd48258e 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -2717,8 +2717,9 @@ customize the variable `user-emacs-directory-warning'."
2717 "Return non-nil if the current buffer is narrowed." 2717 "Return non-nil if the current buffer is narrowed."
2718 (/= (- (point-max) (point-min)) (buffer-size))) 2718 (/= (- (point-max) (point-min)) (buffer-size)))
2719 2719
2720(defun find-tag-default () 2720(defun find-tag-default-bounds ()
2721 "Determine default tag to search for, based on text at point. 2721 "Determine the boundaries of the default tag, based on text at point.
2722Return a cons cell with the beginning and end of the found tag.
2722If there is no plausible default, return nil." 2723If there is no plausible default, return nil."
2723 (let (from to bound) 2724 (let (from to bound)
2724 (when (or (progn 2725 (when (or (progn
@@ -2742,7 +2743,14 @@ If there is no plausible default, return nil."
2742 (< (setq from (point)) bound) 2743 (< (setq from (point)) bound)
2743 (skip-syntax-forward "w_") 2744 (skip-syntax-forward "w_")
2744 (setq to (point))))) 2745 (setq to (point)))))
2745 (buffer-substring-no-properties from to)))) 2746 (cons from to))))
2747
2748(defun find-tag-default ()
2749 "Determine default tag to search for, based on text at point.
2750If there is no plausible default, return nil."
2751 (let ((bounds (find-tag-default-bounds)))
2752 (when bounds
2753 (buffer-substring-no-properties (car bounds) (cdr bounds)))))
2746 2754
2747(defun find-tag-default-as-regexp () 2755(defun find-tag-default-as-regexp ()
2748 "Return regexp that matches the default tag at point. 2756 "Return regexp that matches the default tag at point.