如何定义Emacs Lisp函数来生成shell缓冲区,并在shell中执行特定的命令? [英] How do I define an Emacs Lisp function to spawn a shell buffer with a particular command executed in the shell?

查看:103
本文介绍了如何定义Emacs Lisp函数来生成shell缓冲区,并在shell中执行特定的命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做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 nilecho'test1')
(process-send-string nilecho'test2')))

我不希望shell退出时,因为shell缓冲区中的输出很重要,有时候我需要杀死它并重新启动它,但我不想失去这个历史。

本质上,我想采取手动过程并使其可调用。



任何帮助非常感谢



Tom

解方案

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

(defun spawn-shell(name)
Invoke shell test
(interactiveMName of shell buffer to create:)
(pop-to- buffer(get-buffer-create(generate-new-buffer-name name)))
(shell(current-buffer))
(process-send-string nilecho'test1'\\\

(process-send-string nilecho'test2'\\\
))

当它以交互方式运行( Mx spawn-shell )时,它会提示使用一个名称。它使用 生成基于输入名称创建一个新的缓冲区-new-buffer-name ,您在发送到该过程的字符串末尾缺少换行符。


I am doing Rails development and find that I need to spawn a shell, rename the buffer (e.g. webrick), then kick off the command (rails s) and then do the whole thing over again if I want a rails console or rails dbconsole, rspec, spork, etc. every time I start up emacs.

I am hoping for something like this:

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

I don't want the shell to go away when it exits because the output in the shell buffer is important and some times I need to kill it and restart it but I don't want to lose that history.
Essentially, I want to take the manual process and make it invokable.

Any help is much appreciated

Tom

解决方案

Perhaps this version of spawn-shell will do what you want:

(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"))

It prompts for a name to use when you run it interactively (M-x spawn-shell). It creates a new buffer based on the input name using generate-new-buffer-name, and you were missing the newlines on the end of the strings you were sending to the process.

这篇关于如何定义Emacs Lisp函数来生成shell缓冲区,并在shell中执行特定的命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆