From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: tomas@tuxteam.de Newsgroups: gmane.emacs.help Subject: Re: a question about regular expression Date: Wed, 30 Sep 2009 14:43:09 +0200 Message-ID: <20090930124309.GA15061@tomas> References: <83ske8zwkz.fsf@ymail.invalid> <4ac087d5$0$12628$ba4acef3@news.orange.fr> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; x-action=pgp-signed Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1254324455 29278 80.91.229.12 (30 Sep 2009 15:27:35 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 30 Sep 2009 15:27:35 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Bruno Barbier Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Sep 30 17:27:28 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Mt15U-0007oC-C7 for geh-help-gnu-emacs@m.gmane.org; Wed, 30 Sep 2009 17:27:28 +0200 Original-Received: from localhost ([127.0.0.1]:53820 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mt15T-000633-Pc for geh-help-gnu-emacs@m.gmane.org; Wed, 30 Sep 2009 11:27:27 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MsyVp-0005E4-5Y for help-gnu-emacs@gnu.org; Wed, 30 Sep 2009 08:42:29 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MsyVi-0005BR-DG for help-gnu-emacs@gnu.org; Wed, 30 Sep 2009 08:42:27 -0400 Original-Received: from [199.232.76.173] (port=37228 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MsyVf-0005B9-TP for help-gnu-emacs@gnu.org; Wed, 30 Sep 2009 08:42:20 -0400 Original-Received: from alextrapp1.equinoxe.de ([217.22.192.104]:41238 helo=www.elogos.de) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MsyVf-0002zr-ES for help-gnu-emacs@gnu.org; Wed, 30 Sep 2009 08:42:19 -0400 Original-Received: by www.elogos.de (Postfix, from userid 1000) id 0705D90008; Wed, 30 Sep 2009 14:43:10 +0200 (CEST) Content-Disposition: inline In-Reply-To: <4ac087d5$0$12628$ba4acef3@news.orange.fr> User-Agent: Mutt/1.5.15+20070412 (2007-04-11) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:68564 Archived-At: -----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 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)))=20 > > (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=C3=A1s -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFKw1JdBcgs9XrR2kYRAp6XAJ9fnTgUmezc/Vw4EQgz2GQrIaj7UwCfYY+i psYiZ5/ozRq+DCE7GNqXv0g=3D =3DuCzc -----END PGP SIGNATURE-----