help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Function-Problem


From: tomas
Subject: Re: Function-Problem
Date: Wed, 17 Aug 2016 15:27:56 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

-----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 via email to

[Prev in Thread] Current Thread [Next in Thread]