【问题标题】:Grab current line in buffer as a string in elisp在 elisp 中将缓冲区中的当前行作为字符串抓取
【发布时间】:2015-01-17 02:13:41
【问题描述】:

如何在 elisp 中将缓冲区的当前行作为字符串值收集?我能做到,

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

但是有没有我可以在一行中做到这一点,

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

【问题讨论】:

  • 我不确定我是否理解。您只是想在没有 p1p2 的情况下执行此操作,即全部内联,还是您正在寻找特别的东西?
  • let 不只是声明一个变量,它还给它一个值。所以你的代码创建了变量,给它们赋值nil,只是为了立即将它们设置为其他值。最好跳过中间步骤并执行:(let* ((p1 (line-beginning-position)) (p2 (line-end-position)) (myLine (buffer-substring-no-properties p1 p2))) ...)

标签: emacs elisp


【解决方案1】:

使用thing-at-point:

(thing-at-point 'line t)

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

【讨论】:

  • 另一个警告:当 point 位于缓冲区的末尾时,此调用返回相同的字符串,就好像 point 位于 aboce 行一样。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-05-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-04
  • 1970-01-01
相关资源
最近更新 更多