Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grab current line in buffer as a string in elisp

Tags:

emacs

elisp

How can i collect the buffer's current line as a string value in elisp? i can do this,

(let (p1 p2 myLine)
 (setq p1 (line-beginning-position) )
  (setq p2 (line-end-position) )
  (setq myLine (buffer-substring-no-properties p1 p2))
)

but is there anyway i can do it in one line as,

(with-current-buffer get-current-line)

1 Answers

Use thing-at-point:

(thing-at-point 'line t)

but note that this also returns any newline at the end of the line.

like image 88
Steve Vinoski Avatar answered Sep 10 '25 08:09

Steve Vinoski