[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 8c83231: * lisp/isearch.el (isearch-forward-thing-at-point): New
From: |
Juri Linkov |
Subject: |
master 8c83231: * lisp/isearch.el (isearch-forward-thing-at-point): New command (bug#39512). |
Date: |
Wed, 21 Apr 2021 16:39:48 -0400 (EDT) |
branch: master
commit 8c83231dae0f4701c2a6ddf140df13fe028b3612
Author: Juri Linkov <juri@linkov.net>
Commit: Juri Linkov <juri@linkov.net>
* 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.
---
etc/NEWS | 7 +++++++
lisp/isearch.el | 47 ++++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 49 insertions(+), 5 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index 1fe49bb..559ffd6d 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -958,6 +958,13 @@ authentication mechanism by setting a value for the key
'smtp-auth'.
** 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
diff --git a/lisp/isearch.el b/lisp/isearch.el
index fb2633d..f1c61fc 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.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 8c83231: * lisp/isearch.el (isearch-forward-thing-at-point): New command (bug#39512).,
Juri Linkov <=