如何快速浏览Emacs中的大量文件?
在Emacs(24.3)中有没有快速浏览大量文件的方法?更具体地说: 让我们假设一个Emacs框架被分成两个窗口。假设焦点位于左侧窗口中,该窗口有一个打开的“dired”缓冲区,其中包含大量文本文件(或代码)。我想上下浏览文件列表(例如,使用光标键),同时在右侧窗口中显示当前文件。更好的是,只有当我在dired缓冲区中移动到下一个文件时,文件才会被查看和关闭。这将非常有用,尤其是与某些“省略”模式结合使用时 这可以在“dired”中完成吗?我在dired-x或sunrise commander中也找不到这个功能。可能吗 我已经尝试过的最好的候选人(以及为什么他们没有解决问题): “v”显示当前文件,但也会引起注意 “C-o”显示当前文件,但在向上或向下移动后,我必须再次按C-o,它也会生成大量缓冲区 非常感谢你的帮助 试试看如何快速浏览Emacs中的大量文件?,emacs,dired,Emacs,Dired,在Emacs(24.3)中有没有快速浏览大量文件的方法?更具体地说: 让我们假设一个Emacs框架被分成两个窗口。假设焦点位于左侧窗口中,该窗口有一个打开的“dired”缓冲区,其中包含大量文本文件(或代码)。我想上下浏览文件列表(例如,使用光标键),同时在右侧窗口中显示当前文件。更好的是,只有当我在dired缓冲区中移动到下一个文件时,文件才会被查看和关闭。这将非常有用,尤其是与某些“省略”模式结合使用时 这可以在“dired”中完成吗?我在dired-x或sunrise commander中
M-x speedbar
这可能会吸引您以下是我如何使用查看模式实现这一点:
(add-hook 'view-mode-hook
(lambda()
(define-key view-mode-map (kbd "n") 'dired-view-next)
(define-key view-mode-map (kbd "p") 'dired-view-prev)))
(defun dired-view-next ()
"Move to next dired line and view ."
(interactive)
(quit-window)
(dired-next-line 1)
(dired-view-file))
(defun dired-view-prev ()
"Move to next dired line and view ."
(interactive)
(quit-window)
(dired-next-line -1)
(dired-view-file))
UPD:
这个有两个窗格:
(defun dired-view-next-pane ()
(interactive)
(other-window 1)
(if view-mode
(kill-buffer))
(other-window -1)
(dired-next-line 1)
(view-file-other-window
(dired-get-file-for-visit))
(other-window -1))
M-x我的查找文件
(或将其绑定到一个键,例如C-x C-f
)down
或up
在文件名之间循环C-S-down
按顺序访问下一个文件RET
结束以选择要访问的文件,或以C-g
结束以取消C-S-down
访问的每个文件缓冲区在
看了下一个。您还可以将C-down
或C-RET
混合到
还要访问您不想杀死其缓冲区的文件
自动地(如果没有,请将查看文件
更改为查找文件
)
要在只读的查看模式下访问。)
[默认情况下,冰柱查找文件的替代操作是
icicle alt act fn for type
,提示您输入文件-
对选定的特定候选人采取的适当行动
action.Commandmy find file
只是替换了一个不同的
备选行动功能(适用于您选择的所有候选人)。]
另请参见帮助gnu-emacs@gnu.org. 我想这和你的问题差不多。这里的回复与我的回复基本相同,但也有其他人的回复可能对您有所帮助。一个简单而通用(但不是最佳)的解决方案可以通过C-x()机制实现
首先在Emacs中打开两个窗格,比如说,上面的一个窗格是dired
- 按o键打开第二窗格中的第一个文件
然后可以启动重复机制:
- 执行C-x(开始录制宏
- 执行C-x k并返回以关闭缓冲区
- 再做一次,回到迪雷德
- 按向下键转到下一个文件
- 在底部窗格中打开下一个文件
- 执行C-x)以结束宏
从那时起(在底部窗格中,在顶部窗格中拖动),只需
- C-x e(如果其间没有其他操作,则只有e)
将自动
- 关闭底部窗格文件,转到顶部窗格,向下转到下一个文件,在底部窗格中打开它
也许有一种更具体的方法可以做到这一点,但了解宏机制对Emacs非常有帮助。非常感谢所有这些答案。总结我创建了以下解决方案(扩展了“abo abo”的答案):
更改了三个键:
C-o
在另一个窗口中查看当前项目(可能创建一个)
n
在另一个窗口中查看下一项
p
在另一个窗口中查看上一项
这可以在dired缓冲区中使用。请注意,只有dired模式缓冲区和view模式缓冲区在上下移动时被杀死。如果文件显示另一个缓冲区已经在访问(不在视图模式下),则该缓冲区也会显示,但在移动到下一个缓冲区时不会被终止。另一个微妙之处是,被动显示的缓冲区是用于浏览列表的dired缓冲区(这在使用RET
进入文件夹时很容易发生)。为了处理这种情况,我们首先检查是否试图终止初始dired缓冲区。ag模式列表顶部的另一个视图模式解决方案。我找不到ag模式的问题,也许这有助于某人概括任何模式的ffap预览
(defun directory-ag-results ()
(save-excursion
(goto-char (point-min))
(search-forward "\"")
(setq a (point))
(search-forward "\"")
(setq b (- (point) 1))
(buffer-substring-no-properties a b)))
(defun search-item-path ()
(let ((dir (directory-ag-results))
(file-parts (split-string (substring-no-properties (thing-at-point 'filename)) ":")))
(concat dir (nth 0 file-parts))))
(defun search-item-line ()
(let ((file-parts (split-string (substring-no-properties (thing-at-point 'filename)) ":")))
(- (string-to-number (nth 1 file-parts)) 1)))
(defun view-current ()
"Quickly view the current file in another window."
(if (not (window-parent))
(split-window)) ; create a new window if necessary
(let ((file (search-item-path))
(line (search-item-line))
(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
(progn
(view-file file) ; ... view it
(goto-char (point-min))
(next-line line)))
(other-window -1))))
(defun next-view-current ()
(interactive)
(next-line)
(view-current))
(defun previous-view-current ()
(interactive)
(previous-line)
(view-current))
(define-key ag-mode-map (kbd "M-p") 'previous-view-current)
(define-key ag-mode-map (kbd "M-n") 'next-view-current)
这是我认为Sublime比Emacs做得更好的一件事。亵渎神明,我知道!我喜欢视图模式的“q-to-exit”感觉,而不是基于计时器的解决方案,并且喜欢在预览文件周围滚动。此代码段导航到搜索结果中找到的行号,以优化浏览速度
;; 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
(defun directory-ag-results ()
(save-excursion
(goto-char (point-min))
(search-forward "\"")
(setq a (point))
(search-forward "\"")
(setq b (- (point) 1))
(buffer-substring-no-properties a b)))
(defun search-item-path ()
(let ((dir (directory-ag-results))
(file-parts (split-string (substring-no-properties (thing-at-point 'filename)) ":")))
(concat dir (nth 0 file-parts))))
(defun search-item-line ()
(let ((file-parts (split-string (substring-no-properties (thing-at-point 'filename)) ":")))
(- (string-to-number (nth 1 file-parts)) 1)))
(defun view-current ()
"Quickly view the current file in another window."
(if (not (window-parent))
(split-window)) ; create a new window if necessary
(let ((file (search-item-path))
(line (search-item-line))
(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
(progn
(view-file file) ; ... view it
(goto-char (point-min))
(next-line line)))
(other-window -1))))
(defun next-view-current ()
(interactive)
(next-line)
(view-current))
(defun previous-view-current ()
(interactive)
(previous-line)
(view-current))
(define-key ag-mode-map (kbd "M-p") 'previous-view-current)
(define-key ag-mode-map (kbd "M-n") 'next-view-current)