all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: John Mastro <john.b.mastro@gmail.com>
To: emacs-list <help-gnu-emacs@gnu.org>
Subject: Re: Function-Problem
Date: Wed, 17 Aug 2016 10:33:19 -0700	[thread overview]
Message-ID: <CAOj2CQTT-zRW18PVFUqS42OmZ54K2q5VvS5x5_FtC38SteOZow@mail.gmail.com> (raw)
In-Reply-To: <b0bd2430-ae4a-5c76-0b6a-bd0bb8afc5e2@mailbox.org>

Klaus Jantzen <k.d.jantzen@mailbox.org> 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 *.

I used the [:blank:] class because it seems to match what you're trying
to express, but of course you could replace [[:blank:]] with [ ] if you
only want to match spaces (i.e. do not want to match tabs).

The complete function would be:

(defun blank-line-p ()
  (save-excursion
    (beginning-of-line)
    (looking-at-p "^[[:blank:]]*$")))

Hope that helps

        John



  reply	other threads:[~2016-08-17 17:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-17 10:49 Function-Problem Klaus Jantzen
2016-08-17 13:27 ` Function-Problem tomas
2016-08-17 14:38   ` Function-Problem Drew Adams
2016-08-17 14:49     ` Function-Problem tomas
2016-08-17 13:59 ` Function-Problem Óscar Fuentes
2016-08-17 17:06 ` Function-Problem Klaus Jantzen
2016-08-17 17:33   ` John Mastro [this message]
2016-08-17 18:07     ` Function-Problem tomas

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=CAOj2CQTT-zRW18PVFUqS42OmZ54K2q5VvS5x5_FtC38SteOZow@mail.gmail.com \
    --to=john.b.mastro@gmail.com \
    --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.