[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: a question about regular expression
From: |
tomas |
Subject: |
Re: a question about regular expression |
Date: |
Wed, 30 Sep 2009 14:43:09 +0200 |
User-agent: |
Mutt/1.5.15+20070412 (2007-04-11) |
-----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-----