在elisp中将缓冲区中的当前行作为字符串抓取

21 emacs elisp

如何在elisp中将缓冲区的当前行收集为字符串值?我可以做这个,

(let (p1 p2 myLine)
 (setq p1 (line-beginning-position) )
  (setq p2 (line-end-position) )
  (setq myLine (buffer-substring-no-properties p1 p2))
)
Run Code Online (Sandbox Code Playgroud)

但无论如何我可以在一行中做到,

(with-current-buffer get-current-line)
Run Code Online (Sandbox Code Playgroud)

Ste*_*ski 33

用途thing-at-point:

(thing-at-point 'line t)
Run Code Online (Sandbox Code Playgroud)

但请注意,这也会返回行尾的任何换行符.

  • 另一个警告:当 point 位于缓冲区末尾时,此调用返回相同的字符串,就好像 point 位于行 aboce 处一样。 (3认同)