summaryrefslogtreecommitdiff
path: root/lisp/isearch.el
diff options
context:
space:
mode:
authorJuri Linkov <juri@jurta.org>2013-06-03 11:51:50 +0300
committerJuri Linkov <juri@jurta.org>2013-06-03 11:51:50 +0300
commite5e4a94293d5a9a157557e53b4fea4e5d280673e (patch)
tree2384760b1e0aae2ec3622021c6438463ed8fb0af /lisp/isearch.el
parent26b3353ad0200b6e3dae8bacbf61c7c069a26b2a (diff)
downloademacs-e5e4a94293d5a9a157557e53b4fea4e5d280673e.tar.gz
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/isearch.el')
-rw-r--r--lisp/isearch.el27
1 files changed, 25 insertions, 2 deletions
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:
(define-key esc-map "\C-r" 'isearch-backward-regexp)
(define-key search-map "w" 'isearch-forward-word)
(define-key search-map "_" 'isearch-forward-symbol)
+(define-key search-map "." 'isearch-forward-symbol-at-point)
;; Entry points to isearch-mode.
@@ -806,6 +807,25 @@ as a regexp. See the command `isearch-forward' for more information."
(interactive "P\np")
(isearch-mode nil (null not-regexp) nil (not no-recursive-edit)))
+(defun isearch-forward-symbol-at-point ()
+ "Do incremental search forward for a symbol found near point.
+Like ordinary incremental search except that the symbol found at point
+is added to the search string initially as a regexp surrounded
+by symbol boundary constructs \\_< and \\_>.
+See the command `isearch-forward-symbol' for more information."
+ (interactive)
+ (isearch-forward-symbol nil 1)
+ (let ((bounds (find-tag-default-bounds)))
+ (cond
+ (bounds
+ (when (< (car bounds) (point))
+ (goto-char (car bounds)))
+ (isearch-yank-string
+ (buffer-substring-no-properties (car bounds) (cdr bounds))))
+ (t
+ (setq isearch-error "No symbol at point")
+ (isearch-update)))))
+
;; isearch-mode only sets up incremental search for the minor mode.
;; 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'."
(isearch-done nil t)
(isearch-clean-overlays))
(require 'hi-lock nil t)
- (let ((string (cond (isearch-regexp isearch-string)
+ (let ((regexp (cond ((functionp isearch-word)
+ (funcall isearch-word isearch-string))
+ (isearch-word (word-search-regexp isearch-string))
+ (isearch-regexp isearch-string)
((if (and (eq isearch-case-fold-search t)
search-upper-case)
(isearch-no-upper-case-p
@@ -1768,7 +1791,7 @@ and reads its face argument using `hi-lock-read-face-name'."
(regexp-quote s))))
isearch-string ""))
(t (regexp-quote isearch-string)))))
- (hi-lock-face-buffer string (hi-lock-read-face-name)))
+ (hi-lock-face-buffer regexp (hi-lock-read-face-name)))
(and isearch-recursive-edit (exit-recursive-edit)))