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

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

Re: Function-Problem


From: Óscar Fuentes
Subject: Re: Function-Problem
Date: Wed, 17 Aug 2016 15:59:41 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

Klaus Jantzen <k.d.jantzen@mailbox.org> writes:

> 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

Look into `save-excursion'.

>         (res 0)
>        )
>     (beginning-of-line)
>     (if (re-search-forward "^[ ]+$\|^$" lep t)

You need to escape the `\' above: "^[ ]+$\\|^$". Also, instead of using
`+' you could use `*' which matches zero or more instances and just use
"^[ ]*$".

>         (progn (goto-char cpp) ; line is blank/empty
>                (message "t")
>                t)
>         (progn (goto-char cpp) ; line is not blank/empty
>                (message "nil")
>                (return nil))

`return' does not belong here. It is a Common Lisp extension. Just say
`nil' the same way you say `t' at the end of the previous `progn'.

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

HTH.




reply via email to

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