[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: |
Sun, 15 Nov 2015 14:29:04 +0100 |
User-agent: |
mu4e 0.9.15; emacs 25.0.50.1 |
On 2015-11-14, at 19:42, Barry Margolin <barmar@alum.mit.edu> wrote:
> In article <87r3js7e8l.fsf@linux-qg7d.fritz.box>,
> Rolf Ade <rolf@pointsman.de> wrote:
>
>> For some random minor elisp code I need to know, if the current line
>> contains only white-space characters[1].
>>
>> I came up with this somewhat convoluted code:
>>
>> (beginning-of-line)
>> (skip-chars-forward " \t")
>> (let ((text-start (current-column)))
>> (end-of-line)
>> (if (= text-start (current-column))
>> t
>> nil)
>>
>> (and that is, obviously, without saving point position and wrapping
>> into and a defun and maybe other bells and whistles).
>>
>> I wonder, what much simpler and more elegant solution I'm missing.
>
> (save-excursion
> (beginning-of-line)
> (looking-at "[ \t]*$"))
You might also (depending on your use-case) want to use looking-at-p,
which is marginally slower than looking-at, but does not modify match
data.
Best,
--
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University
- How to test if the current line contains only white-spache?, Rolf Ade, 2015/11/15
- Re: How to test if the current line contains only white-spache?, Barry Margolin, 2015/11/15
- Re: How to test if the current line contains only white-spache?,
Marcin Borkowski <=
- Re: How to test if the current line contains only white-spache?, Philipp Stephani, 2015/11/16
- looking-at-p slower than looking-at, Nicolas Richard, 2015/11/25
- Re: looking-at-p slower than looking-at, Marcin Borkowski, 2015/11/25
- Re: looking-at-p slower than looking-at, Michael Heerdegen, 2015/11/25
- Re: looking-at-p slower than looking-at, Marcin Borkowski, 2015/11/25
- 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