【问题标题】:Expand absolute filenames with Tramp host info使用 Tramp 主机信息扩展绝对文件名
【发布时间】:2014-11-29 03:36:24
【问题描述】:

(file-remote-p default-directory) 不为零时,我最终希望调用elisp (find-file "/abs/olute/file.name"),并将远程主机应用于查找文件调用中的绝对文件名。

实际用例:我在远程主机上有一个 shell 模式会话,其中default-directory 的形式为"/meth:user@host:/abs/path/"。我在 shell 模式下添加了一个命令,可以在新缓冲区中打开文件。如果我发送一个相对文件名,远程文件会正确打开;如果我发送一个绝对文件路径(以“/”或“~”开头),它将相对于我的本地上下文而不是远程进行评估。

我可以包装函数,以便在打开之前将远程信息添加到绝对文件路径的前面,但我想知道是否有 TRAMP 函数或变量可以用来强制使用远程主机绝对文件路径。请再次注意,通过正确应用默认目录中的远程主机和路径,可以适当地处理相对路径。

【问题讨论】:

    标签: emacs absolute-path tramp


    【解决方案1】:

    没有这样的 Tramp 功能。 (find-file "/abs/olute/file.name") 知道,文件名是本地的,不会调用 Tramp。

    所以你必须自己实现这个,确实。

    【讨论】:

      【解决方案2】:

      这是我使用的:

      (defun expand-file-name-remote (file)
        "A tramp-friendly version of expand-file-name.  Expand file
      relative to the remote part of default-directory."
        (let ((file (expand-file-name file))
              (dir-remote (file-remote-p default-directory)))
          (if (file-remote-p file)
              ;; if file is already remote, return it
              file
            ;; otherwise prepend the remote part (if any) of default-directory
            (concat dir-remote file)
            )))
      

      【讨论】:

        猜你喜欢
        • 2013-07-21
        • 1970-01-01
        • 1970-01-01
        • 2017-10-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多