我可以更改Emacs查找文件历史记录吗?

mmc*_*coo 8 emacs

当我调用find-file打开一个新文件时,通常会发生我正在寻找的文件位于我已经加载的目录之一.

理想情况下,我想使用向上/向下箭头滚动历史记录.

这样做的问题是,如果我已经从目录中加载了10个文件,我首先必须通过这10个文件,所有文件都在同一个目录中,然后才能看到我的文件所在的新目录.

最后,我经常再次输入目录或从xterm剪切/粘贴它.

在find-file命令中,我可以更改向上/向下箭头的行为来迭代目录而不是文件.

或者,我可以更改文件顺序以匹配最近访问的缓冲区的顺序,而不是我加载文件时的顺序吗?

Tre*_*son 4

我的第一个答案是由于 TAB 补全不再按“查找文件”中的预期工作的行为而受到影响。但该技术似乎仍然有用(如果您喜欢它,最好)。

但是,此解决方案具有相同的历史记录行为,但在“find-file”内保持了预期的 TAB 补全。

我很想知道是否有一种方法可以避免建议 find-file,但我找不到任何内省来让我知道“find-file”被调用了。

(defadvice find-file (around find-file-set-trigger-variable protect activate)
  "bind a variable so that history command can do special behavior for find-file"
  (interactive (let (inside-find-file-command) (find-file-read-args "Find file: " nil)))
  ad-do-it)

(defadvice next-history-element (around next-history-element-special-behavior-for-find-file protect activate)
  "when doing history for find-file, use the buffer-list as history"
  (if (boundp 'inside-find-file-command)
      (let ((find-file-history (delq nil (mapcar 'buffer-file-name (buffer-list))))
            (minibuffer-history-variable 'find-file-history))
        ad-do-it)
    ad-do-it))
Run Code Online (Sandbox Code Playgroud)