From: tomas@tuxteam.de
To: Bruno Barbier <bruno.barbier.cs@begin_dom.orange.fr.end_dom>
Cc: help-gnu-emacs@gnu.org
Subject: Re: a question about regular expression
Date: Wed, 30 Sep 2009 14:43:09 +0200 [thread overview]
Message-ID: <20090930124309.GA15061@tomas> (raw)
In-Reply-To: <4ac087d5$0$12628$ba4acef3@news.orange.fr>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Mon, Sep 28, 2009 at 09:54:29AM +0000, Bruno Barbier wrote:
> On 2009-09-27, Water Lin <WaterLin@ymail.invalid> wrote:
> >
> > Here is my code:
> > ---------------
> > (defun copy-word (&optional arg)
> > "Copy words at point"
> > (interactive "P")
> > (let ((beg (progn (if (looking-back "[_a-zA-Z0-9]" 1)
> > (backward-word 1)) (point)))
> > (end (progn (forward-word arg) (point))))
> > (copy-region-as-kill beg end))
> > )
> > ---------------
> >
> > I want use M-x copy-word to copy a word even the word is combined by _
> > . But I don't know why my regular expression doesn't work.
I think the regexp is working fine (but my notion of "works" might
differ from yours). At least, for me, (looking-back...) yields t when
point is not at the beginning of the word (like so: " e^nter") and f when
at the beginning (say: " ^enter"). One weakness might be when the word
is preceded by several non-word chars (like "^ enter"). Then all of
those will be included in your copy.
Besides, forward_word has a different idea about what a word is. It will
stop at the first "_", giving you a short copy.
Regards
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFKw1JdBcgs9XrR2kYRAp6XAJ9fnTgUmezc/Vw4EQgz2GQrIaj7UwCfYY+i
psYiZ5/ozRq+DCE7GNqXv0g=
=uCzc
-----END PGP SIGNATURE-----
prev parent reply other threads:[~2009-09-30 12:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <83ske8zwkz.fsf@ymail.invalid>
2009-09-28 9:54 ` a question about regular expression Bruno Barbier
2009-09-30 12:43 ` tomas [this message]
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=20090930124309.GA15061@tomas \
--to=tomas@tuxteam.de \
--cc=bruno.barbier.cs@begin_dom.orange.fr.end_dom \
--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.