emacs - 使用给定的工作目录在 emacs 中打开 shell

标签 emacs elisp cedet

我想要一个 make-shells emacs 中的命令将打开许多 emacs-shell 缓冲区,每个缓冲区都有自己的工作目录。这个想法是,对于我正在处理的每个项目,我都有一个在该项目目录中启动的 shell,因此我可以轻松地在它们之间切换。

目前我有这个代码:

(defun shell-dir (name dir)
  (interactive "sShell name: \nDDirectory: ")
  (shell name)
  (switch-to-buffer name)
  (comint-send-string (current-buffer) (concat "cd " dir "\r"))
  (sleep-for 0 10)
  (dirs))

(defun make-shells ()
  (interactive)
  (shell-dir "project1" "~/proj/project1")
  (shell-dir "project2" "~/proj/project2")
  (shell-dir "project3" "~/proj/project3")
  (delete-window))

不过,这很丑陋,而且有一半的时间 (dirs)没有选择正确的路径,所以选项卡完成中断,直到我手动重新运行它。是否有内置的方法来设置 emacs shell 的当前工作目录?或者像 CEDET (加上对 shell 与 emacs 模式的较少依赖)是一个更好的解决方案吗?

最佳答案

我在 Emacs 提供的当前目录跟踪方面遇到了类似的问题,所以我写了一个,一劳永逸地解决了这个问题。

看看 here .

它所做的简短版本是您修改 shell 提示符以包含当前目录的完整路径(仅当在 Emacs 内运行时),并且 Emacs shell 缓冲区将使用它。

这意味着您永远不必再次执行 M-x 目录。

还有包 dirtrack (与 Emacs 一起提供)它做同样的事情。

我更喜欢我的版本,因为它从提示中删除了路径。我不想在我的提示中看到整个路径,因为我的当前目录通常很长。

一旦您使用上述两种解决方案之一,您就可以简化您的 shell-dir例行公事:

(defun shell-dir (name dir)
  (interactive "sShell name: \nDDirectory: ")
  (let ((default-directory dir))
    (shell name)))

关于emacs - 使用给定的工作目录在 emacs 中打开 shell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4880058/

相关文章:

emacs - 在 Emacs 21.3.1 中以 C/C++ 模式更改 #if 0 ... #endif block 中代码的颜色

c++ - C++ 头文件的 emacs 公共(public)/ protected /私有(private)标签缩进不适用于零偏移

用于不同编码风格的 Emacs Yasnippet

emacs - 在 mu4e 中使用 org-capture-templates

c++ - 为什么在 Emacs 中使用 CEDET 完成代码如此缓慢?

parsing - 用 Wisent 编写解析器

c++ - 在 emacs 中寻求自动完成功能

macos - Emacs 24 : Unable to find theme file for `solarized-dark.

emacs - 组织模式在不同日期和不同时间重复发生的事件

emacs - 优化 key-chord.el 触发