2011-02-02 37 views
11

我希望在emacs中有一个make-shells命令,它将打开许多emacs-shell缓冲区,每个缓冲区都有自己的工作目录。我的想法是,对于我正在开发的每个项目,我都有一个从该项目目录开始的shell,因此我可以轻松地在它们之间切换。使用给定的工作目录在emacs中打开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模式的依赖较少)是一个更好的解决方案吗?

回答

10

我遇到了与Emacs提供的当前目录跟踪相似的问题,所以我写了一个可以永久解决问题的问题。

看看here

它的功能的简短版本是修改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))) 
1

还有一个答案......我发现有一种方法(在Linux上),使Emacs的身影通过使用/ proc文件系统,正确地取出当前目录。

http://www.emacswiki.org/emacs/ShellDirtrackByProcfs

这样的话,你只需要启动的任何目录壳和Emacs会自动计算出来,并得到了制表完成等权利。

+0

工程就像一个魅力! – dfri 2017-01-16 16:08:29

相关问题