What's the simplest way to check whether a given point value p
is at the beginning of some line or not? Is there anything simpler than (save-excursion (goto-char p) (= p (point-at-bol)))
or (member (char-before p) '(nil \n))
?
1 Answer
You can also use the function bolp
:
bolp
is a built-in function in `../editfns.c'.
(bolp)
Return
t
if point is at the beginning of a line.This function does not change global state, including the match data.
Usually you get a buffer position via (point)
, thus simply issuing (bolp)
will be enough. If the point has been moved, use goto-char
in advance.
-
This only slightly simpler than
point-at-bol
since you still have to usesave-excursion
if you don't want to move point.char-before
still seems simplest.– LassiCommented Aug 29, 2018 at 11:50