本文介绍了Emacs:将shell命令应用于kill ring和yank中的顶级项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
说我在Emacs中的剪贴板(kill ring)中有一些文本。我想设置一个键盘快捷方式:在此文本上应用了一个特定的shell命令后,该文本将被翻译:例如:
printf $ 1 | sed's @ ^ \\ @ / samba / @; s @ \\ @ / @ g'
(在这种情况下 $ 1
将是剪贴板中的文本)
我该怎么做这在Emacs?
解决方案
这是一个通用的 shell-command-on-string
(defun shell-command-on-str(cmd&可选str)
插入使用STR作为输入调用CMD的结果
如果未指定,STR是当前杀死
(interactive(list(read-shell-command shell命令on region:)))
(setq str(或str
(current-kill 0)))
(insert(with-temp-buffer
str)
(shell-command-on-region(point-min)(point-max)cmd nil'replace)
(buffer-string))))
您可以定义自己的使用它的功能:
(defun my-sed-on-kill()
(interactive)
(shell-command-on-strsed'@ @ \\ @ / samba / @; s @ \\ @ / @ g'))
Say I have some text in the clipboard (kill ring) in Emacs. I would like to set up a keyboard shortcut that:
yanks the text after applying a certain shell command on this text: e.g.:
printf $1 | sed 's@^\\@/samba/@;s@\\@/@g'
(in this case $1
would be the text in the clipboard)
How can I do this in Emacs?
解决方案
Here is a generic shell-command-on-string
(defun shell-command-on-str (cmd &optional str)
"Insert result of calling CMD with STR as input.
STR is current-kill if unspecified.
"
(interactive (list (read-shell-command "Shell command on region: ")))
(setq str (or str
(current-kill 0)))
(insert (with-temp-buffer
(insert str)
(shell-command-on-region (point-min) (point-max) cmd nil 'replace)
(buffer-string))))
You can define your own function that uses it:
(defun my-sed-on-kill ()
(interactive)
(shell-command-on-str "sed 's@^\\@/samba/@;s@\\@/@g'"))
这篇关于Emacs:将shell命令应用于kill ring和yank中的顶级项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!