emacs - 我如何定义一个 Emacs Lisp 函数来生成一个在 shell 中执行的特定命令的 shell 缓冲区?

标签 emacs

我正在做 Rails 开发,发现我需要生成一个 shell,重命名缓冲区(例如 webrick),然后启动命令(rails s),然后如果我想要一个 rails 控制台或 rails dbconsole,然后重新做整个事情, rspec、spork 等每次启动 emacs 时。

我希望有这样的事情:

(defun spawn-shell ()
   "Invoke shell test"
    (with-temp-buffer
      (shell (current-buffer))
      (process-send-string nil "echo 'test1'")
      (process-send-string nil "echo 'test2'")))

我不希望 shell 在退出时消失,因为 shell 缓冲区中的输出很重要,有时我需要杀死它并重新启动它,但我不想丢失那个历史。
本质上,我想采用手动过程并使其可调用。

任何帮助深表感谢

汤姆

最佳答案

也许这个版本的spawn-shell会做你想做的:

(defun spawn-shell (name)
  "Invoke shell test"
  (interactive "MName of shell buffer to create: ")
  (pop-to-buffer (get-buffer-create (generate-new-buffer-name name)))
  (shell (current-buffer))
  (process-send-string nil "echo 'test1'\n")
  (process-send-string nil "echo 'test2'\n"))

当您以交互方式运行它时,它会提示您输入一个名称(M-x spawn-shell)。它使用 generate-new-buffer-name 根据输入名称创建一个新缓冲区。 ,并且您错过了发送到进程的字符串末尾的换行符。

关于emacs - 我如何定义一个 Emacs Lisp 函数来生成一个在 shell 中执行的特定命令的 shell 缓冲区?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4114577/

相关文章:

emacs 控制台模式 Org-mode 删除线未按预期显示

Emacs Helm : Adding new sources to helm-mini

Emacs org-agenda 导出议程 - 如何?

linux - 如何在 Emacs 中获取 Linux 版本

emacs - 更改组织模式开始新一天的时间

emacs - 需要帮助关闭端口列表中信号后的重新对齐注释。 (Verilog 模式)

emacs - 如何让 Emacs 启动更快?

emacs - 防止 Emacs 询问 "modified buffers exist; exit anyway?"

emacs - 如何为特定目录下的所有文件设置 ispell 字典

emacs - 使用 org-babel 捕获 "diff"的输出