unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: <tomas@tuxteam.de>
To: Klaus Jantzen <k.d.jantzen@mailbox.org>
Cc: emacs-list <help-gnu-emacs@gnu.org>
Subject: Re: Function-Problem
Date: Wed, 17 Aug 2016 15:27:56 +0200	[thread overview]
Message-ID: <20160817132756.GB19005@tuxteam.de> (raw)
In-Reply-To: <5715d4d8-fe9c-851f-8a2c-308a9da10e37@mailbox.org>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wed, Aug 17, 2016 at 12:49:11PM +0200, Klaus Jantzen wrote:
> Hello,
> 
> the attached function should return true if a line contains all blanks
> or is empty.
> 
> Currently the function returns a quick 'nil' and then the message 
> 
> "No catch for tag: --cl-block-nil--, nil"
> 
> What is my problem?
> 
> =====
> (defun blank-line-p ()
>   "Returns t if line contains all blanks or is empty"
>   (let ((lep (line-end-position))
>         (cpp (point)) ; the current position
>         (res 0)
>        )
>     (beginning-of-line)
>     (if (re-search-forward "^[ ]+$\|^$" lep t)
>         (progn (goto-char cpp) ; line is blank/empty
>                (message "t")
>                t)
>         (progn (goto-char cpp) ; line is not blank/empty
>                (message "nil")
>                (return nil))
                  ^^^^^^

I guess you just want to say `nil' there instead of `(return nil)'
(return is a wrapper around a CL exception which you haven't caught
"upstairs", thus the funny message).

>         )
>     ) ; end of let
>   ) ; end of 'blank-line-p'
> ====
> Thanks for any hint.

Note that you can have it much easier. Cf `looking-at', e.g.

  (beginning-of-line)
  (looking-at "^[ ]*$")

might be roughly equivalent to your code snippet above.

Perhaps you want to use "save-excursion" if you don't want your
function to leave point at a different position it started:

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

You might also want to refine the regexp to include other
whitespace characters besides of " " (e.g. the POSIX  class
[:space:] or some such).

Regards
- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAle0ZlwACgkQBcgs9XrR2kZ8bwCfbUcZrZtjghtR38bOsGZi/8v1
JQcAn3kanTGRUvVCriIJz+RBYqhByEN0
=nw7B
-----END PGP SIGNATURE-----



  reply	other threads:[~2016-08-17 13:27 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 ` tomas [this message]
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   ` Function-Problem John Mastro
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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160817132756.GB19005@tuxteam.de \
    --to=tomas@tuxteam.de \
    --cc=help-gnu-emacs@gnu.org \
    --cc=k.d.jantzen@mailbox.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).