我可以更改Emacs的查找文件历史吗? [英] Can I change Emacs find-file history?

查看:139
本文介绍了我可以更改Emacs的查找文件历史吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When I call find-file to open a new file, it generally happens that the file I'm looking for is in one of the directories I've already loaded from.

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

Ideally, I'd like to scroll through the history using the up/down arrows.

这个问题是如果我已经加载10从目录中的文件,我首先必须通过这10个文件,全部在同一目录中,然后才能看到我的文件可能是一个新目录。

The problem with this is that if I've already loaded 10 files from a directory, I first have to pass through those ten files, all in the same directory, before I see a new directory where my file might be.

在结束,我经常只需再次输入目录或从xterm中剪切/粘贴。

In the end, I often just type in the directory again or cut/paste it from an xterm.

在find-file命令中,可以更改up /向下箭头来遍历目录,而不是文件。

in the find-file command, can I change the behavior of the up/down arrows to iterate over directories instead of files.

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

Alternatively, can I change the file order to match the order of buffers most recently visited instead of when I loaded the file?

推荐答案

我的第一个答案遭受了TAB完成的行为不再像以前那样工作在查找文件中查找。但是,这种技术仍然是有用的(如果你喜欢,最好)。

My first answer suffered from the behavior that TAB completion no longer worked as expected in 'find-file. But the technique still seems useful (and if you like it, preferable).

但是,这个解决方案具有相同的历史记录行为, find-file。

However, this solution has the same history behavior, but maintains the TAB completion as expected inside 'find-file.

我有兴趣知道是否有办法避免建议find-file,但是找不到任何反馈给我的知道'find-file被调用。

I'd be interested to know if there were a way to avoid advising find-file, but I couldn't find any introspection that gave me the knowledge that 'find-file was called.

(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))

这篇关于我可以更改Emacs的查找文件历史吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆