I want to get contents of the current line(the line with cursor) for my function. What command allows me to achieve this?
Asked
Active
Viewed 2,307 times
8
2 Answers
17
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))

MatthewRock
- 1,483
- 13
- 28
14
Alternative to buffer-substring
:
(thing-at-point 'line)

Dan
- 32,980
- 7
- 102
- 169
-
4Be 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 '15 at 15:45
point
. (It should never be a problem, but who knows...) – YoungFrog Aug 28 '15 at 15:48