使用给定的工作目录在emacs中打开shell
我希望在emacs中有一个使用给定的工作目录在emacs中打开shell,emacs,elisp,cedet,Emacs,Elisp,Cedet,我希望在emacs中有一个makeshell命令,该命令将打开许多emacs shell缓冲区,每个缓冲区都有自己的工作目录。我的想法是,对于我正在处理的每个项目,我都有一个shell,它从该项目的目录开始,因此我可以轻松地在它们之间切换 目前我有以下代码: (defun shell-dir (name dir) (interactive "sShell name: \nDDirectory: ") (shell name) (switch-to-buffer name) (co
makeshell
命令,该命令将打开许多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的当前工作目录?或者类似的东西(再加上较少依赖shell和emacs模式)能更好地解决这个问题吗?我在emacs提供的当前目录跟踪中遇到了类似的问题,所以我写了一篇文章,一次又一次地解决了这个问题
看看吧
它的简短版本是修改shell提示符以包含当前目录的完整路径(仅在Emacs内部运行时),Emacs shell缓冲区将使用该路径
这意味着你再也不用做M-x dirs了
还有一个包(与Emacs一起提供)也做同样的事情
我更喜欢我的版本,因为它从提示符中删除了路径。我不想在提示符中看到整个路径,因为我的当前目录通常很长
使用上述两种解决方案之一后,您可以将shell dir
例程简化为:
(defun shell-dir (name dir)
(interactive "sShell name: \nDDirectory: ")
(let ((default-directory dir))
(shell name)))
还有一个答案。。。我发现有一种方法(在Linux上)可以让Emacs通过使用/proc文件系统正确地计算当前目录
这样,您只需在任何目录下启动shell,Emacs就会自动找到它,并正确地完成选项卡等操作。效果非常好!