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: 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



reply via email to

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