Thursday, February 11, 2010

Emacs Tip #34: line-beginning-position, line-end-position

Such a simple thing - finding the position of the beginning or end of the current line. I've been completely oblivious to the existence of the functions line-beginning-position and line-end-position.

They return the position of the beginning or end of the current line.
They both accept an optional argument, which has the same
meaning as the argument to beginning-of-line or end-of-line.

They were first introduced in Emacs 20, in the middle of 2006. Which means I've been unnecessarily typing this for 4 years:
(save-excursion
(beginning-of-line)
(point))

2 comments:

aap said...

How did I miss that? I have some code which occasionally beeps if I hit a certain key when the cursor is at the beginning of the buffer... I'm tempted to go fix it right now. Thanks.

Paul Hobbs said...

I always forget about these, but I've started using "apropos" to find things recently, and that pretty much gets rid of the problem.