From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Newsgroups: gmane.emacs.help Subject: Re: Function-Problem Date: Wed, 17 Aug 2016 20:07:27 +0200 Message-ID: <20160817180727.GA27584@tuxteam.de> References: <5715d4d8-fe9c-851f-8a2c-308a9da10e37@mailbox.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; x-action=pgp-signed X-Trace: blaine.gmane.org 1471457307 24672 195.159.176.226 (17 Aug 2016 18:08:27 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 17 Aug 2016 18:08:27 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) Cc: emacs-list To: John Mastro Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Aug 17 20:08:23 2016 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ba5GI-0006GF-ND for geh-help-gnu-emacs@m.gmane.org; Wed, 17 Aug 2016 20:08:22 +0200 Original-Received: from localhost ([::1]:49044 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ba5GI-0002Tg-KT for geh-help-gnu-emacs@m.gmane.org; Wed, 17 Aug 2016 14:08:22 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34311) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ba5FX-0002Qb-Kz for help-gnu-emacs@gnu.org; Wed, 17 Aug 2016 14:07:36 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ba5FT-0004fK-Ba for help-gnu-emacs@gnu.org; Wed, 17 Aug 2016 14:07:34 -0400 Original-Received: from mail.tuxteam.de ([5.199.139.25]:52364 helo=tomasium.tuxteam.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ba5FT-0004fC-5j for help-gnu-emacs@gnu.org; Wed, 17 Aug 2016 14:07:31 -0400 Original-Received: from tomas by tomasium.tuxteam.de with local (Exim 4.80) (envelope-from ) id 1ba5FP-0007Lt-L5; Wed, 17 Aug 2016 20:07:27 +0200 In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 5.199.139.25 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:111167 Archived-At: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Wed, Aug 17, 2016 at 10:33:19AM -0700, John Mastro wrote: > Klaus Jantzen wrote: > > (defun blank-line-p () > > "Returns t if line contains only blanks or empty" > > (save-excursion > > (beginning-of-line) > > ; (if (looking-at-p "^[ ]+$\|^$") ; (1) > > ; (if (looking-at-p "^[ ]+$") ; (2) > > ; (if (looking-at-p "^$") ; (3) > > (if (looking-at-p "^$\|^[ ]+$") ; (1a) > > (progn ; (goto-char cpp) ; line is blank/empty > > (message "t") > > t) > > (progn ; (goto-char cpp) ; line is not blank/empty > > (message "nil") > > nil) > > ) > > ) > > ) ; end of 'blank-line-p' > > > > ===== > > > > This leads to a problem with the regular expression; > > > > if-(3) works, if-(2) works, but the combined regular expression in > > if-(1) or if-(1a) does not work. > > > > Where is my error in the RE? Is the combination not allowed in > > 'lookig-at-p'? > > This should do the trick: (looking-at-p "^[[:blank:]]*$") > > The problem is that the + metacharacter means "one or more", whereas you > want to express "zero or more" spaces. The metacharacter for that is *. [rest elided] I concur. The regular expression "^[ ]+$\|^$" is just a roundabout way to spell "^[ ]*$" (i.e. say "zero or more" instead of "one or more OR zero"). And a POSIX class makes it more general (or just leave out the [] if you really mean only the space char). But... the expression at (1) still should work. Why it doesn't? Well, the escape char before the \ is seen by the string reader and disappears! To pass one escape to the regexp you have to double it. The correct spelling for (1) would be: (looking-at-p "^[ ]+$\\|^$") Note the double backslassh: one for the string syntax, one for the regexp. This is a very common trap. Especially because you don't need this doubling in interactive input. Regards - -- t -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAle0p98ACgkQBcgs9XrR2kZvLQCfZelDtIAOx/0AWiGDvKuklrQ+ GJUAmwQFnHcEmlllr+ROR9uT+EEhlG50 =ur24 -----END PGP SIGNATURE-----