[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
- Re: looking-at-p slower than looking-at, (continued)
- Re: looking-at-p slower than looking-at, Nicolas Richard, 2015/11/26
- Re: looking-at-p slower than looking-at, Emanuel Berg, 2015/11/25
- Re: looking-at-p slower than looking-at, Nicolas Richard, 2015/11/26
- Message not available
- Re: looking-at-p slower than looking-at, Barry Margolin, 2015/11/25
- Re: looking-at-p slower than looking-at, Marcin Borkowski, 2015/11/25
Re: How to test if the current line contains only white-spache?, Rolf Ade, 2015/11/16
Message not availableRe: How to test if the current line contains only white-spache?, Rolf Ade, 2015/11/18
Re: How to test if the current line contains only white-spache?, Stefan Monnier, 2015/11/18
Re: How to test if the current line contains only white-spache?, Emanuel Berg, 2015/11/18
Re: How to test if the current line contains only white-spache?, Emanuel Berg, 2015/11/18
Message not availableRe: How to test if the current line contains only white-spache?, Rolf Ade, 2015/11/19
Re: How to test if the current line contains only white-spache?, Marcin Borkowski, 2015/11/19
Re: How to test if the current line contains only white-spache?, Emanuel Berg, 2015/11/19
Re: How to test if the current line contains only white-spache?, Marcin Borkowski, 2015/11/20
Re: How to test if the current line contains only white-spache?, Emanuel Berg, 2015/11/20
Message not availableRe: How to test if the current line contains only white-space?, Rolf Ade, 2015/11/19