如何让 Windows 下的 emacs 使用“\”而不是“/”在 shell 缓冲区中自动完成路径?

650*_*502 6 windows shell emacs tab-completion

我正在使用 emacs 在 linux、windows、osx 上工作,除了 windows 下 shell 缓冲区的一个烦人的问题外,一切都很好。

自动完成文件名会很好用(比标准窗口更好)但完全没用,因为它为目录生成带有正斜杠分隔符的路径。这在 Windows 上不起作用,所以我必须强迫自己避免使用 Tab 键并在命令提示符下键入所有内容,否则我必须放弃 emacs 并使用 Windows 损坏的命令窗口(例如,甚至很难复制) n 由于分割线问题合理粘贴)。

有没有办法告诉 emacs 使用“\”而不是“/”来完成 Windows 的路径名?

Lar*_*olm 4

简短回答:使用变量comint-completion-addsuffix

更长的答案:谷歌搜索“emacs shell 完成窗口”让我找到了http://www.gnu.org/software/emacs/windows/Sub_002dprocesses.html,它说变量comint-completion-addsuffix控制完成字符。将其设置为 cons\SPACE执行您想要的操作。你可以这样做

  1. Mx 自定义变量 RET comint-completion-addsuffix RET
  2. 选择值菜单
  3. 选择后缀对
  4. \在目录后缀后输入:
  5. 在文件后缀后输入空格字符:
  6. 选择“保存用于未来会话”(或“保存用于当前会话”)

这样做会添加一行

'(comint-completion-addsuffix (quote ("\\" . " ")))
Run Code Online (Sandbox Code Playgroud)

到 ~/.emacs 文件中的正确位置。

(使用 Emacs 22.3 进行测试。)

更新:

我明白您在评论中的意思,即在 Emacs 23.3 中,前导反斜杠已更改为斜杠。 comint-dynamic-complete-filename已被破坏,因此描述的部分except that it won't change parts of the filename already entered in the buffer不再正确。

用 22.3 替换 23.3 的 lisp/comint.el 似乎可行。替换该文件中从第 3062 行开始的三行也是如此:

     (delete-region filename-beg filename-end)
     (if filedir (insert (comint-quote-filename filedir)))
     (insert (comint-quote-filename (directory-file-name completion)))
Run Code Online (Sandbox Code Playgroud)

这些行(来自 22.3):

     (insert (comint-quote-filename
          (substring (directory-file-name completion)
             (length filenondir))))
Run Code Online (Sandbox Code Playgroud)

和做M-x byte-recompile-directory