[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: |
Philipp Stephani |
Subject: |
Re: How to test if the current line contains only white-spache? |
Date: |
Mon, 16 Nov 2015 21:15:12 +0000 |
Marcin Borkowski <mbork@mbork.pl> schrieb am Mo., 16. Nov. 2015 um
08:10 Uhr:
>
> 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.
>
Another small improvement: Use the regex "[[:space:]]*$" or (rx (* space)
eol) to respect the definition of whitespace in the current syntax table.
Re: How to test if the current line contains only white-spache?, Rolf Ade, 2015/11/16