* Search for selected tex
@ 2008-06-14 16:30 Lorenzo Isella
2008-06-14 16:45 ` Lennart Borgman (gmail)
0 siblings, 1 reply; 5+ messages in thread
From: Lorenzo Isella @ 2008-06-14 16:30 UTC (permalink / raw)
To: help-gnu-emacs
Dear All,
I would like to be able to select some text with C-space and then look
for it inside the buffer.
I found some functions online which I modified to get:
;; a function to search the selected text
(defun my-search-forward (begin end)
(interactive (list (point) (mark)))
(let ((text (filter-buffer-substring begin end nil t)))
(goto-char (max begin end))
(let ((found-pos (search-forward text nil t)))
(if (not found-pos)
(progn
(goto-char begin)
(error "not found"))
(progn
(goto-char found-pos)
(set-mark (- found-pos (length text))))))))
(define-key global-map [(control q )] 'my-search-forward)
It is almost there but not yet...
If I highlight some text, I can look for it with C-q, but once at the
end of the buffer, it stops searching (whereas I would like it to search
from the beginning of the buffer).
If then I move to the beginning of the buffer, not everything above my
last position is selected, but also the function loses memory of what I
was looking for...
Anybody can give me some help? Apologies if there is already and emacs
command for that, but my online search was not fruitful.
Cheers
Lorenzo
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Search for selected tex
2008-06-14 16:30 Search for selected tex Lorenzo Isella
@ 2008-06-14 16:45 ` Lennart Borgman (gmail)
2008-06-14 17:00 ` Thierry Volpiatto
2008-06-14 17:03 ` Lorenzo Isella
0 siblings, 2 replies; 5+ messages in thread
From: Lennart Borgman (gmail) @ 2008-06-14 16:45 UTC (permalink / raw)
To: Lorenzo Isella; +Cc: help-gnu-emacs
Lorenzo Isella wrote:
> Dear All,
> I would like to be able to select some text with C-space and then look
> for it inside the buffer.
> I found some functions online which I modified to get:
>
> ;; a function to search the selected text
>
> (defun my-search-forward (begin end)
> (interactive (list (point) (mark)))
> (let ((text (filter-buffer-substring begin end nil t)))
> (goto-char (max begin end))
> (let ((found-pos (search-forward text nil t)))
> (if (not found-pos)
> (progn
> (goto-char begin)
> (error "not found"))
> (progn
> (goto-char found-pos)
> (set-mark (- found-pos (length text))))))))
>
>
> (define-key global-map [(control q )] 'my-search-forward)
>
>
> It is almost there but not yet...
> If I highlight some text, I can look for it with C-q, but once at the
> end of the buffer, it stops searching (whereas I would like it to search
> from the beginning of the buffer).
> If then I move to the beginning of the buffer, not everything above my
> last position is selected, but also the function loses memory of what I
> was looking for...
> Anybody can give me some help? Apologies if there is already and emacs
> command for that, but my online search was not fruitful.
> Cheers
There is some code for similar wishes in
http://www.emacswiki.org/cgi-bin/wiki/SearchAtPoint
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Search for selected tex
2008-06-14 16:45 ` Lennart Borgman (gmail)
@ 2008-06-14 17:00 ` Thierry Volpiatto
2008-06-15 0:15 ` Juanma
2008-06-14 17:03 ` Lorenzo Isella
1 sibling, 1 reply; 5+ messages in thread
From: Thierry Volpiatto @ 2008-06-14 17:00 UTC (permalink / raw)
To: Lennart Borgman (gmail); +Cc: Lorenzo Isella, help-gnu-emacs
"Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
> Lorenzo Isella wrote:
>> Dear All,
>> I would like to be able to select some text with C-space and then
>> look for it inside the buffer.
>> I found some functions online which I modified to get:
>>
>> ;; a function to search the selected text
>>
>> (defun my-search-forward (begin end)
>> (interactive (list (point) (mark)))
>> (let ((text (filter-buffer-substring begin end nil t)))
>> (goto-char (max begin end))
>> (let ((found-pos (search-forward text nil t)))
>> (if (not found-pos)
>> (progn
>> (goto-char begin)
>> (error "not found"))
>> (progn
>> (goto-char found-pos)
>> (set-mark (- found-pos (length text))))))))
>>
>>
>> (define-key global-map [(control q )] 'my-search-forward)
>>
>>
>> It is almost there but not yet...
>> If I highlight some text, I can look for it with C-q, but once at
>> the end of the buffer, it stops searching (whereas I would like it
>> to search from the beginning of the buffer).
>> If then I move to the beginning of the buffer, not everything above
>> my last position is selected, but also the function loses memory of
>> what I was looking for...
>> Anybody can give me some help? Apologies if there is already and
>> emacs command for that, but my online search was not fruitful.
>> Cheers
>
>
> There is some code for similar wishes in
>
> http://www.emacswiki.org/cgi-bin/wiki/SearchAtPoint
>
>
You can also use isearch-forward like that:
put the point at begining of text and then hit C-s C-w C-w C-w ....
until you are at the end of text and then C-s C-s ...etc...
--
A + Thierry
Pub key: http://pgp.mit.edu
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Search for selected tex
2008-06-14 16:45 ` Lennart Borgman (gmail)
2008-06-14 17:00 ` Thierry Volpiatto
@ 2008-06-14 17:03 ` Lorenzo Isella
1 sibling, 0 replies; 5+ messages in thread
From: Lorenzo Isella @ 2008-06-14 17:03 UTC (permalink / raw)
To: Lennart Borgman (gmail); +Cc: Lorenzo Isella, help-gnu-emacs
Many thanks, I cut and pasted a few lines and noticed the improvement (I
selected the snippet by Jury Linkow in the site you suggested). But it
seems to me this mainly deals with finding a single long word in the
text by placing the cursor on it.
What if instead I want to find e.g. two words on the spot?
Cheers
Lorenzo
Lennart Borgman (gmail) wrote:
>
>
> There is some code for similar wishes in
>
> http://www.emacswiki.org/cgi-bin/wiki/SearchAtPoint
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Search for selected tex
2008-06-14 17:00 ` Thierry Volpiatto
@ 2008-06-15 0:15 ` Juanma
0 siblings, 0 replies; 5+ messages in thread
From: Juanma @ 2008-06-15 0:15 UTC (permalink / raw)
To: help-gnu-emacs
On Saturday 14 June 2008, Thierry Volpiatto wrote:
> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
>
> > Lorenzo Isella wrote:
> >> Dear All,
> >> I would like to be able to select some text with C-space and then
> >> look for it inside the buffer.
<snip>
> >
> > There is some code for similar wishes in
> >
> > http://www.emacswiki.org/cgi-bin/wiki/SearchAtPoint
> >
> >
>
> You can also use isearch-forward like that:
> put the point at begining of text and then hit C-s C-w C-w C-w ....
> until you are at the end of text and then C-s C-s ...etc...
Or C-y to search for text between point and end of line, instead of taking
words one by one. Repeating C-y takes one more line at a time.
Or, kill or save the text to the kill ring and yank it for search with M-y
(i.e., after having pressed C-s).
Once you defined some text to search for, you can edit it, moving point to the
minibuffer with M-e.
See here: *info* (emacs)Isearch Yank (chapter 20.1.6)
Even more if you see the documentation of `isearch-forward'.
--
Juanma
"Having a smoking section in a restaurant is like
having a peeing section in a swimming pool."
-- Edward Burr
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-06-15 0:15 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-14 16:30 Search for selected tex Lorenzo Isella
2008-06-14 16:45 ` Lennart Borgman (gmail)
2008-06-14 17:00 ` Thierry Volpiatto
2008-06-15 0:15 ` Juanma
2008-06-14 17:03 ` Lorenzo Isella
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).