如何在Emacs中浏览最近的文件(而不仅仅是文件名)?

时间:2013-02-15 03:13:13

标签: emacs org-mode ido recent-file-list

我使用名为buffer-stack的Emacs库来浏览我当前打开的缓冲区。它很棒,因为它允许我排除不感兴趣的缓冲区,如 Messages ,并浏览我创建的内容的缓冲区。我用一个按键A-right浏览这些缓冲区。

我也使用Ido-mode来browse through the names of recently opened files

但是,我希望不仅可以浏览文件名,还可以浏览实际文件,最好只需一次按键。

如何浏览最近打开的文件?

2 个答案:

答案 0 :(得分:3)

您可以将helm-recentf及其persistent-action用于此目的。

您可以使用helm-recentf选择最近的文件,如下所示。

enter image description here

您可以按Ctrl-z(持久操作)查看文件内容。 按Ctrl-z,然后将内容显示到另一个窗口(在本例中为上窗口)临时。

如果您了解掌舵

,请参阅official document

答案 1 :(得分:0)

以下是两种可能的解决方案(具体取决于您想要的用例)。

(defun zin/open-recent-file ()
  "Open the most recent currently closed file.

This will omit currently open files, instead it will retrieve the
next oldest file in recentf-list."
  (interactive)
  (let* ((count    0)
         (recent   recentf-list)
         (r-length (length recent))
         (buffers  (mapcar 'buffer-file-name (buffer-list))))
    ;; Compare next file on the list to open buffers, if open skip it.
    (while (member (nth count recent)
                   buffers)
      (setq count (1+ count))
      (if (= r-length count)
          (error "All recent buffers already open")))
    (find-file (nth count recent))))
(lexical-let ((recent-count 0))
  (defun zin/visit-recent-file ()
    "Visit files on the recentf-list in descending order.

This will work backwards through recentf-list visiting each file
in turn."
    (interactive)
    ;; If last command was not to cycle through the files, then start
    ;; back at the first in the list.
    (unless (eq last-command 'zin/visit-recent-file)
      (setq recent-count 0))
    ;; If current buffer is the current entry on the list, increment.
    (if (equal (buffer-file-name) (nth 0 recentf-list))
        (setq recent-count (1+ recent-count)))
    ;; Error if all entries have been processed
    (if (= recent-count (length recentf-list))
        (error "At oldest recent buffer"))
    ;; Open appropriate file.
    (find-file (nth recent-count recentf-list))))

第一个将浏览最近文件列表(recentf-list)并打开下一个未打开的文件。第二个将使用recentf-list循环到列表中的下一个缓冲区,直到所有访问者都被访问然后错误输出(因为列表顺序将随着文件重新打开而改变)。

要让它在到达结束时重新开始循环,只需将(error ...)更改为

即可
(setq recent-count 0)