all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Re: a question about regular expression
       [not found] <83ske8zwkz.fsf@ymail.invalid>
@ 2009-09-28  9:54 ` Bruno Barbier
  2009-09-30 12:43   ` tomas
  0 siblings, 1 reply; 2+ messages in thread
From: Bruno Barbier @ 2009-09-28  9:54 UTC (permalink / raw
  To: help-gnu-emacs

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.
>
> Not every familiar with elisp, sorry for this stupid question.
>

I use:
 
    M-x re-builder

to build interactively my regular expressions and see what they match.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: a question about regular expression
  2009-09-28  9:54 ` a question about regular expression Bruno Barbier
@ 2009-09-30 12:43   ` tomas
  0 siblings, 0 replies; 2+ messages in thread
From: tomas @ 2009-09-30 12:43 UTC (permalink / raw
  To: Bruno Barbier; +Cc: help-gnu-emacs

-----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-----




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-09-30 12:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <83ske8zwkz.fsf@ymail.invalid>
2009-09-28  9:54 ` a question about regular expression Bruno Barbier
2009-09-30 12:43   ` tomas

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.