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

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

Re: How to test if the current line contains only white-spache?


From: Marcin Borkowski
Subject: Re: How to test if the current line contains only white-spache?
Date: Tue, 17 Nov 2015 21:38:32 +0100
User-agent: mu4e 0.9.15; emacs 25.0.50.1

On 2015-11-17, at 01:26, Emanuel Berg <embe8573@student.uu.se> wrote:

> Rolf Ade <rolf@pointsman.de> writes:
>
>> Works fine and is much simpler. Thanks.
>
> Here is another solution that is all C, and doesn't
> move point. Is that an advantage? ... (Open question.)
>
> (defun blank-line ()
>   (interactive)
>   (message (if
>                (string-match "^[[:space:]]*$"
>                              (buffer-substring-no-properties
>                               (line-beginning-position)
>                               (line-end-position) )) "blank" "not so") ))
>
> Non-interactive use could be:
>
> (defun blank-line-p ()
>   (string-match "^[[:space:]]*$"
>                 (buffer-substring-no-properties
>                  (line-beginning-position)
>                  (line-end-position) )))
>
> (blank-line-p) ; nil
>
> (progn (previous-line 2)
>        (blank-line-p) ) ; 0, i.e. non-nil - (when 0   t) => t
>                         ;                   (when nil t) => nil
>
> Keep it up!

I would be a bit afraid about performance if using this idea many
times.  Using strings /might/ cause GC to run more often.

Some time ago I wrote a small template mechanism for Emacs, and
benchmarked two versions of it: a buffer-based one and a string-based
one.  Admittedly, there was /changing/ strings (or: creating new ones)
involved, but the string-based one was terribly slow on larger data.
I will be writing about this with more details in a future blog post
(which is largely written and waits for its time).

Best,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University



reply via email to

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