From: Xah Lee <xahlee@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: search forward at point question
Date: Fri, 6 Mar 2009 09:21:34 -0800 (PST) [thread overview]
Message-ID: <e07cf4b6-3293-4cde-95b4-b8609aae2e28@z6g2000pre.googlegroups.com> (raw)
In-Reply-To: mailman.2410.1236235328.31690.help-gnu-emacs@gnu.org
On Mar 4, 10:42 pm, Maindoor <sanjeevfi...@yahoo.com> wrote:
> Hi,
> I have the following code to search forward from point.
> But If I have a string like SOMETHING_HERE=$(HI)
>
> then this code yanks the whole "SOMETHING_HERE=$"
> and searches for it forward. How do I limit it to
> "SOMETHING_HERE". I want it to stop if it encounters
> any special characters except "_" and "-".
>
> Here is the code:
>
> (defun my-viper-search-yank-word (arg forward)
> "Search forward for ARG occurance of word under point.
> If FORWARD is nil, searches backward instead."
> (let ((viper-re-search t))
> (viper-search
> (concat "\\<" (regexp-quote (current-word)) "\\>") forward arg)))
>
> (defun my-viper-search-forward-yank-word (arg)
> "Search forward for ARG occurance of word under point.
> Like the Vim command \"*\" (but not exactly)."
> (interactive "P")
> (my-viper-search-yank-word arg t))
As Barry Margolin suggested, you might try to use the optional
paramter in the function current-word.
However, as Barry also suggested, current-word relies on emacs's
syntax table. Which means, whether “_” or “-” or any other such as “=”
is considered part of the word depends on the current major mode.
You could, write your own so that your function always works on
alphanumerics plus “_” and “-” regardless what syntax table there is.
(This problem also bugged me a few times. Emacs's concept syntax table
seems to me questionable. It is not really powerful enough to model
most coding problems dealing with syntax, yet it does gets in the way
sometimes, and is quite complex to use.)
To code your own current-word, just use search-backward-regexp with a
regex something like [-_A-Za-z], then get the cursor position. Do same
by search forward. Then, use buffer-substring-no-properties to grab
the string.
Xah
∑ http://xahlee.org/
☄
next prev parent reply other threads:[~2009-03-06 17:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.2410.1236235328.31690.help-gnu-emacs@gnu.org>
2009-03-06 2:01 ` search forward at point question Barry Margolin
2009-03-06 17:21 ` Xah Lee [this message]
2009-03-04 16:01 change bash for emacs lehe
2009-03-05 6:42 ` search forward at point question Maindoor
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=e07cf4b6-3293-4cde-95b4-b8609aae2e28@z6g2000pre.googlegroups.com \
--to=xahlee@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.
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).