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

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

Re: empty-line-p


From: David Hansen
Subject: Re: empty-line-p
Date: Fri, 30 Mar 2007 10:56:28 +0200
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.95 (gnu/linux)

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) wrap it in a `save-match-data'.

David





reply via email to

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