I want to get contents of the current line(the line with cursor) for my function. What command allows me to achieve this?

  • "the line with the cursor" depends on the selected window, since different windows can have different values for point. (It should never be a problem, but who knows...)
    – YoungFrog
    Aug 28, 2015 at 15:48

2 Answers 2


Use buffer-substring:

(buffer-substring (line-beginning-position) (line-end-position))

As Tobias noted, this also copies properties of text. If you want to avoid that, you might want to go with buffer-substring-no-properties instead:

(buffer-substring-no-properties (line-beginning-position) (line-end-position))
  • 4
    Often it is better to use buffer-substring-no-properties.
    – Tobias
    Aug 28, 2015 at 14:05
  • 1
    @Tobias Included your insight in answer. Aug 28, 2015 at 14:32

Alternative to buffer-substring:

(thing-at-point 'line)
  • 4
    Be aware that this includes the final newline character if there is one (i.e. always, except maybe for the last line of the buffer) as well as the text properties.
    – YoungFrog
    Aug 28, 2015 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.