emacs - 在 Emacs 中,如何维护最近目录的列表?

标签 emacs elisp dired recent-file-list

在 Emacs 中,我使用 recentf广泛地。而不是调用find-files ,我一般调用自定义函数xsteve-ido-choose-from-recentf相反,它允许我从我的 recentf 中进行选择文件。

如何创建和维护一个单独的最近目录列表,与最近文件列表分开?因此,而不是调用 dired , 我可以调用 ido-choose-from-recent-directories ?

最佳答案

您在回复@Stefan 的回答的评论中问:我如何从上面查看最近的目录列表? -

答案是你使用了一个鲜为人知的事实,如果 DIRNAME dired 的参数是 (a) 新的 Dired 缓冲区名称后跟 (b) 文件(或目录)名称的列表,然后仅针对这些文件/目录打开 Dired。爱荷华州:

M-: (dired (cons DIRED-BUFNAME YOUR-LIST-OF-RECENT-DIRECTORIES))

例如:
M-: (dired '("My Dired Buffer" "/a/recent/dir/" "/another/recent1/" "/another/"))

如果您使用库 Dired+那么您可以通过使用带有 dired 的非正前缀 arg 以交互方式提供这样的列表.

但是在这种情况下,您要编写一个命令,该命令首先收集最近目录的列表,然后为它们打开 Dired。这应该这样做:
(defun dired-recent (buffer)
  "Open Dired in BUFFER, showing the recently used directories."
  (interactive "BDired buffer name: ")
  (let ((dirs  (delete-dups
                (mapcar (lambda (f/d)
                          (if (file-directory-p f/d)
                              f/d
                            (file-name-directory f/d)))
                        recentf-list))))
    (dired (cons (generate-new-buffer-name buffer) dirs))))

这对我行得通。但是,普通 Emacs 不允许您使用 i插入与 default-directory 不在同一目录树中的任何目录的列表Dired 缓冲区。这意味着上面的代码可以正常工作,但您将无法插入任何列出的目录。

为此,请加载库 dired+.el . Dired+还修复了将 cons arg 处理为 dired 的其他一些不足之处。 .

上面的代码,连同迪瑞德+ 应该给你你想要的。

更新

我刚刚添加到 Dired+ .这些是添加的命令:diredp-dired-recent-dirsdiredp-dired-recent-dirs-other-window .

更新 2

我使选择包含或排除哪些最近使用的目录变得简单。使用前缀 arg 来启动此类选择。没有前缀 arg 你会得到所有最近的目录。我还可以使用前缀 arg 来提示 ls开关。这是 diredp-dired-recent-dirs 的文档字符串:
Open Dired in BUFFER, showing recently used directories.
You are prompted for BUFFER.

No prefix arg or a plain prefix arg (`C-u', `C-u C-u', etc.) means
list all of the recently used directories.

With a prefix arg:
* If 0, `-', or plain (`C-u') then you are prompted for the `ls'
  switches to use.
* If not plain (`C-u') then:
  * If >= 0 then the directories to include are read, one by one.
  * If  < 0 then the directories to exclude are read, one by one.

When entering directories to include or exclude, use `C-g' to end.

最后,我为命令添加了绑定(bind):C-x R (同一窗口)和 C-x 4 R (其他窗口),其中 R是 Shift + r .

关于emacs - 在 Emacs 中,如何维护最近目录的列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23328037/

相关文章:

emacs - 在emacs的指定窗口中打开文件

Emacs:轻松导航图像?

emacs - 如何以交互方式读取两个输入并在函数调用中使用它们

javascript - js2-mode.el编译错误

emacs - 在 Emacs 中添加几个函数作为钩子(Hook)

emacs - 如何为 Lisp 模式配置 smartparens?

Emacs 按模式自定义背景颜色

Emacs:将 dired-do-compress 扩展到目录

linux - emacs 格式化问题

shell - 如何加速异步 shell 命令的 emacs 输出?