aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorJuri Linkov2013-06-03 11:51:50 +0300
committerJuri Linkov2013-06-03 11:51:50 +0300
commite5e4a94293d5a9a157557e53b4fea4e5d280673e (patch)
tree2384760b1e0aae2ec3622021c6438463ed8fb0af /lisp
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
Diffstat (limited to 'lisp')
-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
5 files changed, 93 insertions, 9 deletions
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.