[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Wed, 17 Aug 2016 10:33:19 -0700
Klaus Jantzen <address@hidden> wrote:
> (defun blank-line-p ()
> "Returns t if line contains only blanks or empty"
> ; (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")
> (progn ; (goto-char cpp) ; line is not blank/empty
> (message "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
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 ()
Hope that helps