From: Ergus <spacibba@aol.com>
To: "Basil L. Contovounesios" <contovob@tcd.ie>
Cc: Juri Linkov <juri@linkov.net>, emacs-devel@gnu.org
Subject: Re: isearch region or thing at point.
Date: Wed, 1 May 2019 13:20:25 +0200 [thread overview]
Message-ID: <20190501112025.fnsynkbmkvllapyv@Ergus> (raw)
In-Reply-To: <874l6f132f.fsf@tcd.ie>
[-- Attachment #1: Type: text/plain, Size: 2472 bytes --]
Hi all:
Here is attached a patch with all my proposed changes to isearch. I
added documentation in the manual for one of the two functions, but for
the other I don't find the right place.
There is still a pending agreement about the questions I made in the
last email, but, meanwhile you can check the rest of the patch and make
all the corrections you think are needed.
Thanks in advance for your comments,
Ergus
On Wed, May 01, 2019 at 12:33:12AM +0100, Basil L. Contovounesios wrote:
>Ergus <spacibba@aol.com> writes:
>
>> On Tue, Apr 30, 2019 at 11:39:11PM +0100, Basil L. Contovounesios wrote:
>>>Ergus <spacibba@aol.com> writes:
>>>
>>>> (region-bounds)))
>>>> (contiguous (= (length bounds) 1)) ;; Region is contiguous
>>>
>>>Better to use the function region-noncontiguous-p.
>>>
>> I already had the bounds.. I didn't want to do the funcall again... but
>> I know it is probably not important.. I am just an obsessed.
>
>The higher-level and more flexible region-extract-function will handle
>this for you in any case.
>
>>>> (region-string (and (= (count-lines region-beg region-end) 1)
>>>> (buffer-substring-no-properties
>>>> region-beg region-end)))
>>>
>>>Why can't the region span multiple lines? Better to use
>>>region-extract-function for this, as it is more flexible.
>>>
>> I don't thing that searching multiple lines will be very useful in
>> practice and could potentially produce some corner cases. But I
>> will think about that a bit more.
>
>AFAIK, isearch is designed to work perfectly fine with multiple lines,
>and I use this feature a lot, especially in the context of lax
>whitespace matches in Info manuals, for example.
>
>Providing a dedicated region isearch command which is limited to a
>single line sounds hardly better than using isearch-yank-word-or-char or
>similar.
>
>>>> (isearch-yank-string region-string)
>>>>
>>>> (when-let (count (and arg (prefix-numeric-value arg)))
>>>> (isearch-repeat-forward count)))
>>>
>>>This can be simplified as per Noam's suggestion.
>> Yes, sorry, I was concerned if somehow the prefix could be non-nil, but
>> (prefix-numeric-value arg) could return nil... I don't really know the
>> fancy valued that prefix could potentially have. But probably there is
>> not any danger there.
>
>All potential prefix values are listed under (info "(elisp) Prefix
>Command Arguments"), and prefix-numeric-value is guaranteed to return an
>integer.
>
>Thanks,
>
>--
>Basil
>
[-- Attachment #2: isearch_yank_region.patch --]
[-- Type: text/plain, Size: 5342 bytes --]
diff --git a/doc/emacs/search.texi b/doc/emacs/search.texi
index a1c987c125..93c26f5c97 100644
--- a/doc/emacs/search.texi
+++ b/doc/emacs/search.texi
@@ -267,6 +267,14 @@ of the current line to the search string. If point is already at the
end of a line, it appends the next line. With a prefix argument
@var{n}, it appends the next @var{n} lines.
+@kindex M-w @r{(Incremental search)}
+@findex isearch-yank-region
+ @kbd{M-w} (@code{isearch-yank-region}) appends the text in the
+active region if @code{transient-mark-mode} is @code{non-nil}. This is
+an easy way to insert the text in the region without needing to exit
+@code{isearch-mode}. The region is deactivated during the search, but
+it is reactivated if the @code{isearch-cancel} is called.
+
@kindex C-y @r{(Incremental search)}
@kindex M-y @r{(Incremental search)}
@kindex mouse-2 @r{in the minibuffer (Incremental search)}
diff --git a/lisp/isearch.el b/lisp/isearch.el
index 6280afebdc..78414dbfcd 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -53,7 +53,9 @@
;;; Code:
-(eval-when-compile (require 'cl-lib))
+(eval-when-compile
+ (require 'cl-lib)
+ (require 'subr-x))
(declare-function tmm-menubar-keymap "tmm.el")
\f
;; Some additional options and constants.
@@ -701,6 +703,7 @@ This is like `describe-bindings', but displays only Isearch keys."
(define-key map "\M-\C-y" 'isearch-yank-char)
(define-key map "\C-y" 'isearch-yank-kill)
(define-key map "\M-s\C-e" 'isearch-yank-line)
+ (define-key map "\M-w" 'isearch-yank-region)
(define-key map "\M-s\M-<" 'isearch-beginning-of-buffer)
(define-key map "\M-s\M->" 'isearch-end-of-buffer)
@@ -937,6 +940,8 @@ Each element is an `isearch--state' struct where the slots are
(defvar isearch--saved-overriding-local-map nil)
+(defvar isearch--deactivated-mark nil)
+
;; Minor-mode-alist changes - kind of redundant with the
;; echo area, but if isearching in multiple windows, it can be useful.
;; Also, clicking the mode-line indicator pops up
@@ -961,6 +966,8 @@ Each element is an `isearch--state' struct where the slots are
(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-w" 'isearch-forward-region)
+
;; Entry points to isearch-mode.
@@ -1133,6 +1140,22 @@ positive, or search for ARGth symbol backward if ARG is negative."
(isearch-push-state)
(isearch-update)))))
+(defun isearch-forward-region (&optional arg)
+ "Do incremental search forward for text in active region.
+Like ordinary incremental search except that the text in the
+active region is added to the search string initially
+if`transient-mark-mode' is enabled. See the command
+`isearch-forward' for more information.
+With a prefix argument, search for ARGth occurrence forward if
+ARG is positive, or ARGth occurrence backward if ARG is
+negative."
+ (interactive "P")
+ (isearch-forward nil 1)
+ (isearch-yank-region)
+ (when (and isearch--deactivated-mark
+ arg)
+ (isearch-repeat-forward (prefix-numeric-value arg))))
+
\f
;; isearch-mode only sets up incremental search for the minor mode.
;; All the work is done by the isearch-mode commands.
@@ -1203,9 +1226,10 @@ used to set the value of `isearch-regexp-function'."
isearch-pre-move-point nil
;; Save the original value of `minibuffer-message-timeout', and
- ;; set it to nil so that isearch's messages don't get timed out.
- isearch-original-minibuffer-message-timeout minibuffer-message-timeout
- minibuffer-message-timeout nil)
+ ;; set it to nil so that isearch's messages don't get timed out.
+ isearch-original-minibuffer-message-timeout minibuffer-message-timeout
+ minibuffer-message-timeout nil
+ isearch--deactivated-mark nil)
(if (local-variable-p 'tool-bar-map)
(setq isearch-tool-bar-old-map tool-bar-map))
@@ -1783,6 +1807,9 @@ The following additional command keys are active while editing.
(goto-char isearch-opoint))
(isearch-done t) ; Exit isearch..
(isearch-clean-overlays)
+ (when isearch--deactivated-mark
+ (setq isearch--deactivated-mark nil
+ mark-active t))
(signal 'quit nil)) ; ..and pass on quit signal.
(defun isearch-abort ()
@@ -2446,6 +2473,27 @@ If search string is empty, just beep."
;; then it "used" the mark which we should hence deactivate.
(when select-active-regions (deactivate-mark)))
+(defun isearch-yank-region ()
+ "Pull current active region text into search string.
+The text in the active region is added to the search string if
+variable `transient-mark-mode' is non nil."
+ (interactive)
+ (let ((region (and (use-region-p)
+ (funcall region-extract-function nil))))
+ (if (and (stringp region)
+ (not (string-empty-p region)))
+ (progn
+ (when (string-empty-p isearch-string)
+ (goto-char (region-beginning)))
+
+ (setq isearch--deactivated-mark t)
+ (deactivate-mark)
+ (isearch-yank-string region))
+
+ (setq isearch-error "Invalid region")
+ (isearch-push-state)
+ (isearch-update))))
+
(defun isearch-mouse-2 (click)
"Handle mouse-2 in Isearch mode.
next prev parent reply other threads:[~2019-05-01 11:20 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-27 0:14 isearch region or thing at point Ergus
2019-04-27 2:15 ` Basil L. Contovounesios
2019-04-29 0:41 ` Ergus
2019-04-29 1:30 ` Ergus
2019-04-29 1:31 ` Ergus
2019-04-29 19:41 ` Juri Linkov
2019-04-29 20:50 ` Ergus
2019-04-30 15:39 ` Drew Adams
2019-04-30 16:57 ` Ergus
2019-04-30 19:58 ` Juri Linkov
2019-04-30 16:25 ` Ergus
2019-04-30 18:49 ` Noam Postavsky
2019-04-30 19:03 ` Ergus
2019-04-30 19:24 ` Noam Postavsky
2019-04-30 20:05 ` Ergus
2019-04-30 20:38 ` Noam Postavsky
2019-04-30 22:39 ` Basil L. Contovounesios
2019-04-30 23:16 ` Ergus
2019-04-30 23:33 ` Basil L. Contovounesios
2019-05-01 0:13 ` Ergus
2019-05-01 20:57 ` Juri Linkov
2019-05-03 16:27 ` Basil L. Contovounesios
2019-05-01 11:20 ` Ergus [this message]
2019-05-01 14:33 ` Drew Adams
2019-05-01 16:03 ` Ergus
2019-05-01 16:25 ` Drew Adams
2019-05-03 16:28 ` Basil L. Contovounesios
2019-05-04 9:29 ` Eli Zaretskii
2019-05-03 16:28 ` Basil L. Contovounesios
2019-05-04 9:26 ` Eli Zaretskii
2019-05-04 12:15 ` Ergus
2019-05-04 14:17 ` Drew Adams
2019-05-04 14:56 ` Ergus
2019-05-04 15:24 ` Drew Adams
2019-05-04 21:06 ` Juri Linkov
2019-05-04 22:40 ` Drew Adams
2019-05-06 19:41 ` Juri Linkov
2019-05-07 2:56 ` Drew Adams
2019-05-07 19:56 ` Ergus
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190501112025.fnsynkbmkvllapyv@Ergus \
--to=spacibba@aol.com \
--cc=contovob@tcd.ie \
--cc=emacs-devel@gnu.org \
--cc=juri@linkov.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).