emacs - 使用 EmacsClient 创建一个带有文本的新缓冲区

标签 emacs elisp

我有一个程序可以将文本发送到任何其他程序以进行进一步分析(例如 sed、grep 等)。我希望它将数据发送到 Emacs 并在那里进行分析。我该怎么做? EmacsClient 默认采用文件名,这是一个数据字符串而不是文件,我真的不想创建和删除文件只是为了将数据发送到 Emacs。

EmacsClient 有一个“eval”命令行选项,让你执行 lisp 代码而不是打开文件。是否有一个简单的 lisp 函数可以用给定的文本打开一个新的缓冲区?

编辑:我正在寻找类似的东西:
emacsclientw.exe -eval (open-new-buffer 'hello world')
并且会自动出现一个带有“hello world”一词的新缓冲区。我不确定如何设置缓冲区的名称。希望有自动编号的东西。

最佳答案

这可以满足您的要求:

emacsclient -e '(open-buffer-with "some\nstuff\nhere")'

(defun open-buffer-with (txt)
  "create a new buffer, insert txt"
  (pop-to-buffer (get-buffer-create (generate-new-buffer-name "something")))
  (insert txt))

显然你可以自定义open-buffer-with做你想做的事。

您可能想查看一个类似的问题:How do I get basic App<->Emacs integration? .

关于emacs - 使用 EmacsClient 创建一个带有文本的新缓冲区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2465006/

相关文章:

Emacs 在 rst-mode 中复制 org-mode 的 M-RET 功能

emacs - 如何在 perl 模式下指定字符串引用而不会使 Emacs 头晕?

regex - emacs 贪婪搜索向后正则表达式

Emacs 浮点型小数点缩进

emacs - 在 Emacs 中正确缩进 Clojure 的 `match`

Emacs:在 magit-status 缓冲区中暂存或取消暂存更改时更新 git-gutter 注释

Emacs Lisp : difference between (function (lambda . ..))和(lambda ...)?

file - Emacs 口齿不清 : Concise way to get `directory-files` without "." and ".."?

browser - Emacs 和 eww,在新窗口中打开链接吗?

emacs - 我可以在任何地方使用 ido-completing-read 而不是 completion-read 吗?