在具有给定工作目录的emacs中打开shell

我想在emacs中有一个
make-shells
命令,它将打开一些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提供的当前目录跟踪方面遇到了类似的问题,所以我写了一个解决问题的问题。 在这里查看。 它的简短版本是你修改shell提示符以包含当前目录的完整路径(仅当在Emacs中运行时),并且Emacs shell缓冲区将使用它。 这意味着你永远不必再做M-x dirs。 还有包
dirtrack
(与Emacs一起提供)也可以做同样的事情。 我更喜欢我的版本,因为它从提示中删除了路径。我不希望在我的提示中看到整个路径,因为我当前的目录通常很长。 使用上述两种解决方案之一后,您可以将
shell-dir
例程简化为:
(defun shell-dir (name dir)
  (interactive "sShell name: nDDirectory: ")
  (let ((default-directory dir))
    (shell name)))
    
还有一个答案......我发现有一种方法(在Linux上)通过使用/ proc文件系统使Emacs正确地找出当前目录。 http://www.emacswiki.org/emacs/ShellDirtrackByProcfs 这样,你只需要在任何目录中启动shell,Emacs会自动识别出来并获得tab-completion等。     

要回复问题请先登录注册