From: Ergus <spacibba@aol.com>
To: "Basil L. Contovounesios" <contovob@tcd.ie>
Cc: emacs-devel@gnu.org
Subject: Re: isearch region or thing at point.
Date: Mon, 29 Apr 2019 03:31:14 +0200 [thread overview]
Message-ID: <20190429013114.l2igb3wk27qfew2d@Ergus> (raw)
In-Reply-To: <20190429004135.rn5tp2gnmbjovrxj@Ergus>
[-- Attachment #1: Type: text/plain, Size: 4128 bytes --]
On Mon, Apr 29, 2019 at 02:41:35AM +0200, Ergus wrote:
>On Sat, Apr 27, 2019 at 03:15:21AM +0100, Basil L. Contovounesios wrote:
>>Ergus <spacibba@aol.com> writes:
>>
>>>I am looking in the manual for two isearch functionalities that maybe
>>>are already implemented, but I don't find them. Else maybe it is not
>>>so complex to do in elisp (at least for my config) And you could suggest
>>>a right way to implement it.
>>>
>>>1) isearch-yank-thing-at-point, this should be similar to
>>>isearch-yank-word, but if the cursor is in the middle of a word
>>>it may insert the whole word not just the rest of the current word.
>>>
>>>(swiper provides this with M-n)
>>
>>The closest to this that I'm aware of is
>>isearch-forward-symbol-at-point, bound to 'M-s .' by default.
>>
>>>2) In "transient-mark-mode" if the region is active before C-s, the
>>>initial input could be the text in the region. Is it there a way to
>>>enable that behavior?
>>>
>>>An alternative for this is a command that yanks the region's text in the
>>>minibuffer when isearch is active so we could bind it in the isearch-map
>>>(for example to M-f).
>>>
>>>Are some of these already implemented?
>>
>>I'm not familiar with any built-in versions of the rest of the
>>functionality you describe, but I'm no expert. If it is indeed not
>>currently present, I for one would welcome such additions.
>>
>>Thanks,
>>
>>--
>>Basil
>>
>Hi Basil:
>
>I just made a small change in isearch.el to enable region text auto
>insertion in transient-mark-mode. (patch attached)
>
>I did it as simple as I could. So please if you (or any anyone) could
>give a look and correct/improve/expose corner cases, or suggest a better
>implementation will be very nice.
>
>I don't have corner cases right now, but I just started testing it.
>
>So any correction/suggestion/recommendation is very appreciated.
>
>Thanks in advance,
>
>Ergus
>
>diff --git a/lisp/isearch.el b/lisp/isearch.el
>index 6280afebdc..3de0493c8a 100644
>--- a/lisp/isearch.el
>+++ b/lisp/isearch.el
>@@ -413,6 +413,17 @@ and doesn't remove full-buffer highlighting after a search."
> :group 'lazy-count
> :version "27.1")
>
>+(defcustom isearch-autoinsert-region nil
>+ "If non-nil, the text in the region will be auto-inserted for searching.
>+This works only if the variable `transient-mark-mode' is enabled
>+and the region is active."
>+ :type 'boolean
>+ :group 'isearch
>+ :version "27.1")
>+
>+(defvar isearch-deactivated-mark nil
>+ "If for some reason isearch removed the mark on start.")
>+
> \f
> ;; Define isearch help map.
>
>@@ -1205,7 +1216,8 @@ used to set the value of `isearch-regexp-function'."
> ;; 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)
>+ minibuffer-message-timeout nil
>+ isearch-deactivated-mark nil)
>
> (if (local-variable-p 'tool-bar-map)
> (setq isearch-tool-bar-old-map tool-bar-map))
>@@ -1244,6 +1256,15 @@ used to set the value of `isearch-regexp-function'."
> ;; `isearch-push-state' to save mode-specific initial state. (Bug#4994)
> (isearch-push-state)
>
>+ (when (and isearch-autoinsert-region ;; Check option
>+ (use-region-p)
>+ (not (region-noncontiguous-p))
>+ (= (count-lines (region-beginning) (region-end)) 1))
>+ (isearch-yank-string
>+ (buffer-substring-no-properties (region-beginning) (region-end)))
>+ (setq mark-active nil
>+ isearch-deactivated-mark t))
>+
> (isearch-update)
>
> (add-hook 'pre-command-hook 'isearch-pre-command-hook)
>@@ -1782,6 +1803,9 @@ The following additional command keys are active while editing.
> (isearch--set-state (car isearch-cmds)))
> (goto-char isearch-opoint))
> (isearch-done t) ; Exit isearch..
>+ (when isearch-deactivated-mark
>+ (setq isearch-deactivated-mark nil
>+ activate-mark t)
> (isearch-clean-overlays)
> (signal 'quit nil)) ; ..and pass on quit signal.
>
[-- Attachment #2: isearch-autoinsert.patch --]
[-- Type: text/plain, Size: 2407 bytes --]
diff --git a/lisp/isearch.el b/lisp/isearch.el
index 6280afebdc..d5cfceb57c 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -413,6 +413,17 @@ and doesn't remove full-buffer highlighting after a search."
:group 'lazy-count
:version "27.1")
+(defcustom isearch-autoinsert-region nil
+ "If non-nil, the text in the region will be auto-inserted for searching.
+This works only if the variable `transient-mark-mode' is enabled
+and the region is active."
+ :type 'boolean
+ :group 'isearch
+ :version "27.1")
+
+(defvar isearch-deactivated-mark nil
+ "If for some reason isearch removed the mark on start.")
+
\f
;; Define isearch help map.
@@ -1205,7 +1216,8 @@ used to set the value of `isearch-regexp-function'."
;; 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)
+ minibuffer-message-timeout nil
+ isearch-deactivated-mark nil)
(if (local-variable-p 'tool-bar-map)
(setq isearch-tool-bar-old-map tool-bar-map))
@@ -1244,6 +1256,22 @@ used to set the value of `isearch-regexp-function'."
;; `isearch-push-state' to save mode-specific initial state. (Bug#4994)
(isearch-push-state)
+ (when (and isearch-autoinsert-region ;; Check option
+ (use-region-p)
+ (not (region-noncontiguous-p))
+ (= (count-lines (region-beginning) (region-end)) 1)
+ (string-empty-p isearch-string))
+
+ (let ((region-string (buffer-substring-no-properties
+ (region-beginning) (region-end))))
+ (if isearch-forward
+ (goto-char (region-beginning))
+ (goto-char (region-end)))
+ (isearch-yank-string region-string)
+
+ (setq mark-active nil
+ isearch-deactivated-mark t)))
+
(isearch-update)
(add-hook 'pre-command-hook 'isearch-pre-command-hook)
@@ -1782,6 +1810,9 @@ The following additional command keys are active while editing.
(isearch--set-state (car isearch-cmds)))
(goto-char isearch-opoint))
(isearch-done t) ; Exit isearch..
+ (when isearch-deactivated-mark
+ (setq isearch-deactivated-mark nil
+ mark-active t))
(isearch-clean-overlays)
(signal 'quit nil)) ; ..and pass on quit signal.
next prev parent reply other threads:[~2019-04-29 1:31 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 [this message]
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
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=20190429013114.l2igb3wk27qfew2d@Ergus \
--to=spacibba@aol.com \
--cc=contovob@tcd.ie \
--cc=emacs-devel@gnu.org \
/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).