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

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

Re: empty-line-p


From: Andreas Roehler
Subject: Re: empty-line-p
Date: Sat, 31 Mar 2007 07:49:11 +0200
User-agent: Thunderbird 1.5.0.4 (X11/20060516)

David Hansen schrieb:
On 29 Mar 2007 14:32:05 GMT Joost Kremers wrote:

Andreas Roehler wrote:
needed a check at several occassions, if the current line
contains printable characters.

What about the following to solve this?

(defun empty-line-p ()
  "Returns t if cursor is at an empty line "
  (interactive)
  (save-excursion
    (beginning-of-line)
  (if
      (looking-at "^[ \t\f\r]*$")
      t
    nil)))
you don't need the if-statement here:

(defun empty-line-p ()
  "Returns t if cursor is at an empty line "
  (interactive)
  (save-excursion
    (beginning-of-line)
    (looking-at "^[ \t\f\r]*$")))

looking-at already returns t or nil.

And to avoid some painful bug hunting (happened to me with nearly
the same code)
What about to collect minor tools like this somewhere?

 wrap it in a `save-match-data'.

David

OK, thanks. So I got this now:

(defcustom empty-line-p-chars "^[ \t\f\r]*$"
 "empty-line-p-chars"
:type 'regexp
:group 'convenience)

(defun empty-line-p (&optional ispec)
 "Returns t if cursor is at an empty line, nil otherwise.
Displays result in minibuffer when called interactive."
 (interactive "p")
 (save-excursion
   (beginning-of-line)
   (save-match-data
     (when ispec
   (message "%s" (looking-at empty-line-p-chars)))
     (looking-at empty-line-p-chars))))


;;;;;

Andreas




reply via email to

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