all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Lorenzo Isella <lorenzo.isella@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Search for selected tex
Date: Sat, 14 Jun 2008 18:30:03 +0200	[thread overview]
Message-ID: <4853F20B.5030802@gmail.com> (raw)

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




             reply	other threads:[~2008-06-14 16:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-14 16:30 Lorenzo Isella [this message]
2008-06-14 16:45 ` Search for selected tex Lennart Borgman (gmail)
2008-06-14 17:00   ` Thierry Volpiatto
2008-06-15  0:15     ` Juanma
2008-06-14 17:03   ` Lorenzo Isella

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4853F20B.5030802@gmail.com \
    --to=lorenzo.isella@gmail.com \
    --cc=help-gnu-emacs@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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.