summaryrefslogtreecommitdiff
path: root/lisp/isearch.el
diff options
context:
space:
mode:
authorJuri Linkov <juri@linkov.net>2021-04-21 23:39:27 +0300
committerJuri Linkov <juri@linkov.net>2021-04-21 23:39:27 +0300
commit8c83231dae0f4701c2a6ddf140df13fe028b3612 (patch)
tree50847579848dc3f9434eb05425a3e4edaaa3c157 /lisp/isearch.el
parent57805231b2580d304dc2e0e642644ebe52c24f33 (diff)
downloademacs-8c83231dae0f4701c2a6ddf140df13fe028b3612.tar.gz
emacs-8c83231dae0f4701c2a6ddf140df13fe028b3612.tar.bz2
emacs-8c83231dae0f4701c2a6ddf140df13fe028b3612.zip
* lisp/isearch.el (isearch-forward-thing-at-point): New command (bug#39512).
(search-map): Bind "M-s M-." to isearch-forward-thing-at-point. (isearch-forward-thing-at-point): New defcustom.
Diffstat (limited to 'lisp/isearch.el')
-rw-r--r--lisp/isearch.el47
1 files changed, 42 insertions, 5 deletions
diff --git a/lisp/isearch.el b/lisp/isearch.el
index fb2633dbe8b..f1c61fc1677 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -972,12 +972,13 @@ Each element is an `isearch--state' struct where the slots are
(defvar-local isearch-mode nil) ;; Name of the minor mode, if non-nil.
(define-key global-map "\C-s" 'isearch-forward)
-(define-key esc-map "\C-s" 'isearch-forward-regexp)
+(define-key esc-map "\C-s" 'isearch-forward-regexp)
(define-key global-map "\C-r" 'isearch-backward)
-(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)
+(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)
+(define-key search-map "\M-." 'isearch-forward-thing-at-point)
;; Entry points to isearch-mode.
@@ -1157,6 +1158,42 @@ positive, or search for ARGth symbol backward if ARG is negative."
(isearch-push-state)
(isearch-update)))))
+(defcustom isearch-forward-thing-at-point '(region url symbol sexp)
+ "A list of symbols to try to get the \"thing\" at point.
+Each element of the list should be one of the symbols supported by
+`bounds-of-thing-at-point'. This variable is used by the command
+`isearch-forward-thing-at-point' to yank the initial \"thing\"
+as text to the search string."
+ :type '(repeat (symbol :tag "Thing symbol"))
+ :version "28.1")
+
+(defun isearch-forward-thing-at-point ()
+ "Do incremental search forward for the \"thing\" found near point.
+Like ordinary incremental search except that the \"thing\" found at point
+is added to the search string initially. The \"thing\" is defined by
+`bounds-of-thing-at-point'. You can customize the variable
+`isearch-forward-thing-at-point' to define a list of symbols to try
+to find a \"thing\" at point. For example, when the list contains
+the symbol `region' and the region is active, then text from the
+active region is added to the search string."
+ (interactive)
+ (isearch-forward nil 1)
+ (let ((bounds (seq-some (lambda (thing)
+ (bounds-of-thing-at-point thing))
+ isearch-forward-thing-at-point)))
+ (cond
+ (bounds
+ (when (use-region-p)
+ (deactivate-mark))
+ (when (< (car bounds) (point))
+ (goto-char (car bounds)))
+ (isearch-yank-string
+ (buffer-substring-no-properties (car bounds) (cdr bounds))))
+ (t
+ (setq isearch-error "No thing at point")
+ (isearch-push-state)
+ (isearch-update)))))
+
;; isearch-mode only sets up incremental search for the minor mode.
;; All the work is done by the isearch-mode commands.