如何快速浏览Emacs中的大量文件?

use*_*331 8 emacs dired

有没有办法快速浏览Emacs(24.3)中的大量文件?进一步来说:

我们假设Emacs帧被分成两个窗口.假设焦点位于左侧窗口中,该窗口具有打开的"dired"缓冲区,其中包含大量文本文件(或代码).我想在文件列表中上下移动(例如使用光标键),同时当前文件显示在右侧窗口中.更好的是,只有当我将dired缓冲区移动到下一个文件时,文件才会被查看和关闭.这将非常有用,特别是与一些"省略"模式一起使用.

这可以在'dired'中完成吗?我也无法在dired-x或者日出指挥官中找到这个功能.可能吗?

我试过的最好的候选人(以及为什么他们没有解决问题):

'v'显示当前文件,但也引起注意

'Co'显示当前文件,但在向上或向下移动之后,我必须再次按Co,它也会生成大量缓冲区

非常感谢你的帮助!

use*_*331 4

非常感谢所有这些答案。总结一下,我创建了以下解决方案(扩展“abo-abo”的答案):

;; little modification to dired-mode that let's you browse through lots of files
(add-hook 'dired-mode-hook
  (lambda()
    (define-key dired-mode-map (kbd "C-o") 'dired-view-current)     ; was dired-display-file
    (define-key dired-mode-map (kbd "n")   'dired-view-next)           ; was dired-next-line
    (define-key dired-mode-map (kbd "p")   'dired-view-previous))) ; was dired-previous-line

(defun dired-view-next ()
  "Move down one line and view the current file in another window."
  (interactive)
  (dired-next-line)
  (dired-view-current))

(defun dired-view-previous ()
  "Move up one line and view the current file in another window."
  (interactive)
  (dired-previous-line)
  (dired-view-current))

(defun dired-view-current ()
  "View the current file in another window (possibly newly created)."
  (interactive)
  (if (not (window-parent))
      (split-window))                                   ; create a new window if necessary
  (let ((file (dired-get-file-for-visit))
        (dbuffer (current-buffer)))
    (other-window 1)                                          ; switch to the other window
    (unless (equal dbuffer (current-buffer))                 ; don't kill the dired buffer
      (if (or view-mode (equal major-mode 'dired-mode))   ; only if in view- or dired-mode
          (kill-buffer)))                                                    ; ... kill it
    (let ((filebuffer (get-file-buffer file)))
      (if filebuffer                              ; does a buffer already look at the file
          (switch-to-buffer filebuffer)                                    ; simply switch 
        (view-file file))                                                    ; ... view it
      (other-window -1))))                   ; give the attention back to the dired buffer
Run Code Online (Sandbox Code Playgroud)

更改了三个键:

  1. C-o在另一个窗口中查看当前项目(可能创建一个)。
  2. n在另一个窗口中查看下一个项目。
  3. p在另一个窗口中查看上一个项目。

这可以在直接缓冲区中使用。请注意,只有 Dired 模式缓冲区和视图模式缓冲区在上下移动时会被杀死。如果一个文件显示另一个缓冲区已经在访问(不在查看模式下),则该缓冲区也会显示,但在移动到下一个缓冲区时不会被杀死。另一个微妙之处是当被动显示的缓冲区是用于遍历列表的直接缓冲区时的情况(当使用 进入文件夹时,这种情况很容易发生RET)。为了处理这种情况,我们首先检查是否试图杀死初始的 dired 缓冲区。

  • 非常好的事情!刚刚发现了一个小错误,至少在 emacs 24 中你需要将数字 1 传递给 dired-next/previous-line 。 (4认同)