【问题标题】:Custom shells started automatically from .emacs自定义 shell 从 .emacs 自动启动
【发布时间】:2010-02-18 12:36:31
【问题描述】:

我想启动一些 shell,并从我的 .emacs 中设置它们的目录。打开它们很容易:

;; run a few shells.
(shell "*shell5*")
(shell "*shell6*")
(shell "*shell7*")

但我也想指定他们的目录。

【问题讨论】:

  • 只是一个想法,有点hacky,但是shell目录是否来自当前打开的缓冲区目录?如果是这样,您可以在每个目录中打开一个临时文件,并在打开文件后启动 shell。

标签: shell emacs elisp


【解决方案1】:

以下对我有用

(let ((default-directory "/path/to/whereever/"))
  (shell "*shell1*"))

【讨论】:

  • 对我不起作用,例如,如果我使用 /usr/src,shell 仅在 /usr 上启动,/home/guest 也是如此,从 /home 开始
  • 尝试添加尾部斜杠,即“/path/to/wherever/”。
  • 有效,即使在 Windows 上使用 "\\" 作为反斜杠。谢谢!
【解决方案2】:
(shell "*shell5*")
(with-current-buffer "*shell5*"
(goto-char (point-max))
(insert "cd dir")) ;;for example
(comint-send-input nil t) ;; enter

现在我有了这个,我认为它需要一些改进。当我在我的 emacs 中使用它时,它会导致错误,但会做你想要的。我会试着找出原因。

【讨论】:

  • 那太棒了。现在没时间玩这个,也许今晚晚些时候。
  • 我认为我接受的解决方案可能更好,但如果我想在 shell 中做任何其他事情,这个想法仍然很有趣!
  • 是的,伊万的回答是一个简单的解决方案:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多