** Search and Replace
+*** New key 'M-s M-.' starts isearch with the thing found at point.
+This key is bound to the new command 'isearch-forward-thing-at-point'.
+The new user option 'isearch-forward-thing-at-point' defines
+a list of symbols to try to get the "thing" at point. By default,
+the first element of the list is 'region' that tries to yank
+the currently active region to the search string.
+
*** New user option 'isearch-wrap-pause' defines how to wrap the search.
There are choices to disable wrapping completely and to wrap immediately.
When wrapping immediately, it consistently handles the numeric arguments
(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.
(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)))))
+
\f
;; isearch-mode only sets up incremental search for the minor mode.
;; All the work is done by the isearch-mode commands.