[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: isearch region or thing at point.

From: Ergus
Subject: Re: isearch region or thing at point.
Date: Mon, 29 Apr 2019 03:30:11 +0200
User-agent: NeoMutt/20180716

Patch update:

Sorry, the last one was a wrong one.
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 <address@hidden> 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.



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,


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 
  :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.")
;; 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)

+  (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))

  (add-hook 'pre-command-hook 'isearch-pre-command-hook)
@@ -1782,6 +1803,9 @@ The following additional command keys are active while 
        (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)
  (signal 'quit nil))                   ; ..and pass on quit signal.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]