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


我想要一个 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模式的依赖性较小)是一个更好的解决方案吗?


899
2018-02-02 21:28


起源



答案:


我在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)))

10
2018-02-02 21:57





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

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

这样,你只需要在任何目录中启动shell,Emacs会自动计算出来并获得tab-completion等。


1
2018-03-07 22:50



奇迹般有效! - dfri


答案:


我在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)))

10
2018-02-02 21:57





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

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

这样,你只需要在任何目录中启动shell,Emacs会自动计算出来并获得tab-completion等。


1
2018-03-07 22:50



奇迹般有效! - dfri