[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: |
Fri, 06 Apr 2007 16:44:53 +0200 |
User-agent: |
Thunderbird 1.5.0.4 (X11/20060516) |
Xavier Maillard schrieb:
> wrap it in a `save-match-data'.
>
> David
>
OK, thanks. So I got this now:
Here is what I would do instead:
(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
(let ((res (looking-at empty-line-p-chars)))
(or (and ispec
(message "%s" res))
res)))))
Xavier
That would probably work, however, as far as the form
is conceived as a subroutine, it doesn't seem the best
solution.
Assume you introduced `let', because in
(when ispec
(message "%s" (looking-at empty-line-p-chars)))
(looking-at empty-line-p-chars))))
`looking-at' is performed two times.
Thought that repeat won't matter, because when called
interactively, time isn't at stake.
Otherwise `let' would maybe called again and
again from inside a program, whereas `let' isn't really
needed here.
Meanwhile thought to reconcile
`save-match-data' proposed by David Hansen with Stefan
Monnier's objections concerning speed.
The form below should `save-match-data', when called as
(empty-line-p t)
and without arg not.
(defun empty-line-p (&optional arg ispec)
"Returns t if cursor is at an empty line, nil otherwise.
Displays result in minibuffer when called interactive."
(interactive "P\np")
(save-excursion
(beginning-of-line)
(if arg
(save-match-data
(if ispec
(message "%s" (looking-at empty-line-p-chars))
(looking-at empty-line-p-chars)))
(if ispec
(message "%s" (looking-at empty-line-p-chars))
(looking-at empty-line-p-chars)))))
(defcustom empty-line-p-chars "^[ \t\f\r]*$"
"empty-line-p-chars"
:type 'regexp
:group 'convenience)
Thanks all
Andreas Roehler