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

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

Re: Function-Problem


From: Klaus Jantzen
Subject: Re: Function-Problem
Date: Wed, 17 Aug 2016 19:06:51 +0200

On 08/17/2016 12:49 PM, 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))
>         )
>     ) ; end of let
>   ) ; end of 'blank-line-p'
> ====
> Thanks for any hint.

Based on your suggestions, I rewrote the function as follows:

=====

(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'?

-- 

K.D.J.




reply via email to

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