Simple question, I think: How can I calculate the length of a line in emacs lisp? It seems like there should be a function for this, but I can't find it. What I'm using right now is something like this:
(-
(progn
(end-of-line)
(current-column))
(progn
(beginning-of-line)
(current-column)))
But this feels clumsy.
So is there a standard way to do this? And are there any subtleties I should be aware of (i.e. regarding encoding, tabs, or anything like that)?
Actually for my purposes, it would be just as handy to simply calculate if a line is empty. Is there a function for that?
Whatever method I use, it needs to be pretty fast. I need to calculate this for every line in a buffer on a pretty regular basis without interrupting flow.
line-end-position
andline-beginning-position
take an optional argument which makes it unnecessary to move the point and callsave-excursion
(which is quite expensive). – sds Nov 04 '15 at 14:33