【问题标题】:emacs shell-mode follows its default-directory to current-fileemacs shell-mode 遵循其默认目录到当前文件
【发布时间】:2013-01-31 23:55:59
【问题描述】:

当我在 shell 模式下输入 cd c:/dir/to/path 时,shell 模式会跟随它的 default-directoryc:/dir/to/path,这很好。但是在访问某个文件(c:/another/dir/file.ext)时,如何不输入cd c:/antoher/dir/file.ext就让现有的shell目录到那个文件?

emacs 中是否有任何预先存在的功能?找了很多次,可惜没找到。

我在 Win7 中使用 Emacs 24.2.1。

编辑:

我写了一个不好看的函数,如下所示。任何建议/建议将不胜感激(我是 elisp 的新手)。 (带有前缀的交互式调用,它将显示带有当前目录的 shell 缓冲区。我反复思考可能已经发明了比这更好的东西。

  (defun my-shell-with-current-directory (&optional arg)
  (interactive "P")
  (let* ((sp (get-process "shell"))
         (spbuf (and sp (process-buffer sp)))
         (dir (if buffer-file-name (file-name-directory buffer-file-name) default-directory)))
    (if (and arg sp spbuf dir)
        (progn 
          (comint-simple-send sp (concat "cd /d " dir))
          (display-buffer spbuf)
          (save-excursion
            (set-buffer spbuf)
            (cd dir)
            )
          )
      (progn
        (shell)
        (comint-simple-send sp "setlocal enableextensions")
        )
      )
    )
  )

【问题讨论】:

    标签: emacs


    【解决方案1】:

    您可以随时使用 setq 设置默认目录。 您可以将该代码作为挂钩添加到 find-file-hooks 上。 您也可以建议使用所需设置的 find-file 命令。 到目前为止只是我的想法......

    【讨论】:

    • 感谢您的评论。在阅读您的想法后,我添加了一个大致编写的交互功能。请看一下,任何建议将不胜感激。
    猜你喜欢
    • 2010-10-06
    • 1970-01-01
    • 1970-01-01
    • 2012-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-29
    相关资源
    最近更新 更多