我试图将抽取的文本存储到Emacs中的变量.
似乎以下工作:
(let ((str nil))
(with-temp-buffer
(yank)
(setq str (buffer-string)))
Run Code Online (Sandbox Code Playgroud)
我想知道,有没有更简单的方法来实现这一目标?看起来像是打开一个临时缓冲区只是为了获得猛烈的文本是过度的.
您在函数中寻找的值可用
(car kill-ring)
Run Code Online (Sandbox Code Playgroud)
这应该工作:
(defun was-yanked ()
"When called after a yank, store last yanked value in let-bound yanked. "
(interactive)
(let (yanked)
(and (eq last-command 'yank)
(setq yanked (car kill-ring))))
Run Code Online (Sandbox Code Playgroud)
也许消息并返回它:
(defun was-yanked ()
"When called after a yank, store last yanked value in let-bound yanked. "
(interactive)
(let (yanked)
(and (eq last-command 'yank)
(setq yanked (car kill-ring))))
(when (interactive-p) (message "%s" yanked))
yanked)
Run Code Online (Sandbox Code Playgroud)
您可能要使用(current-kill 0)而不是(car kill-ring)。
请参阅的文档字符串kill-ring:
,----
| List of killed text sequences.
| Since the kill ring is supposed to interact nicely with cut-and-paste
| facilities offered by window systems, use of this variable should
| interact nicely with `interprogram-cut-function' and
| `interprogram-paste-function'. The functions `kill-new',
| `kill-append', and `current-kill' are supposed to implement this
| interaction; you may want to use them instead of manipulating the kill
| ring directly.
,----
Run Code Online (Sandbox Code Playgroud)
这也会根据您的评论回答您的第二个问题。有关此文档字符串等中提到的功能,请参见文档。
| 归档时间: |
|
| 查看次数: |
616 次 |
| 最近记录: |