From: Ergus <spacibba@aol.com>
To: Juri Linkov <juri@linkov.net>
Cc: "Basil L. Contovounesios" <contovob@tcd.ie>, emacs-devel@gnu.org
Subject: Re: isearch region or thing at point.
Date: Tue, 30 Apr 2019 18:25:01 +0200 [thread overview]
Message-ID: <20190430162501.xmqh5r5h57sjjlq5@Ergus> (raw)
In-Reply-To: <87h8agy4yf.fsf@mail.linkov.net>
Hi:
I wrote this code today to do a search auto-insert text from region like
behavior.
===============================================
(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 variable
`transient-mark-mode' is non nil. See the command
`isearch-forward-symbol' for more information. With a prefix
argument, search for ARGth symbol forward if ARG is positive, or
search for ARGth symbol backward if ARG is negative."
(interactive "P")
(isearch-forward nil 1)
(if-let* ((bounds (and (use-region-p) ;; Region and transient non-nil
(string-empty-p isearch-string)
(region-bounds)))
(contiguous (= (length bounds) 1)) ;; Region is contiguous
(region-beg (car (car bounds)))
(region-end (cdr (car bounds)))
(region-string (and (= (count-lines region-beg region-end) 1)
(buffer-substring-no-properties
region-beg region-end)))
(noempty (not (string-blank-p region-string))))
(progn
(goto-char region-beg)
(setq mark-active nil
isearch--deactivated-mark t)
(isearch-yank-string region-string)
(when-let (count (and arg (prefix-numeric-value arg)))
(isearch-repeat-forward count)))
(setq isearch-error "Invalid region for isearch")
(isearch-push-state)
(isearch-update)))
================================================
The problem is that when I C-x C-e, it works fine, but when
I compile it I get an error with message:
```
funcall-interactively: Symbol???s value as variable is void: bounds
```
I am pretty new using lisp, but I don't understand this behavior, Any
help, please.
The backtrace only says:
==================================================
Debugger entered--Lisp error: (void-variable bounds)
isearch-forward-region(nil)
funcall-interactively(isearch-forward-region nil)
call-interactively(isearch-forward-region nil nil)
command-execute(isearch-forward-region)
==================================================
Do I am using wrong the if-let* statement?
Thanks in advance,
Ergus.
On Mon, Apr 29, 2019 at 10:41:28PM +0300, Juri Linkov wrote:
>>>The closest to this that I'm aware of is
>>>isearch-forward-symbol-at-point, bound to 'M-s .' by default.
>>>
>> 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, such addition is welcome. Currently searching the
>active region requires invocation of several commands: M-w C-s M-y
>with a bad side-effect of leaving the region in the kill-ring.
>
>However, adding a new option is not a satisfactory solution
>because often isearch is used to extend the boundaries of the
>active region, e.g. by setting the region's beginning with C-SPC,
>then searching the region's end and exiting isearch there.
>
>Fortunately, like Basil mentioned the command isearch-forward-symbol-at-point
>bound to 'M-s .' you could create a similar command bound to e.g. 'M-s r'
>that would start isearch with the text from the active region.
>
next prev parent reply other threads:[~2019-04-30 16:25 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 [this message]
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=20190430162501.xmqh5r5h57sjjlq5@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).