如果我有多个标记文件,那么在Emacs中如何找到/访问所有这些标记文件,而不是在每个文件上运行
是否有内置命令,还是需要一些额外的Lisp代码?
dired-find-file
?是否有内置命令,还是需要一些额外的Lisp代码?
在 Emacs 23.2 及以上版本中,有一个名为 dired-x.el
的模块可供使用,它可以让你使用一个命令来实现你想要的功能。加载它之后(通常只需要用(load "dired-x")
),你就可以调用函数 dired-do-find-marked-files
来实现了。下面是它的内置文档:
(dired-do-find-marked-files &optional NOSELECT)
Find all marked files displaying all of them simultaneously.
With optional NOSELECT just find files but do not select them.
The current window is split across all files marked, as evenly as possible.
Remaining lines go to bottom-most window. The number of files that can be
displayed this way is restricted by the height of the current window and
`window-min-height'.
To keep dired buffer displayed, type C-x 2 first.
To display just marked files, type C-x 1 first.
因此,在加载 dired-x
后,您可以使用 M-x dired-do-find-marked-files
RET,然后您将获得与您的问题完全相同的结果:所有标记的文件都将被访问,就像您对所有这些文件运行了 dired-find-file
。
如果你将以下代码添加到你的.emacs文件中,你就可以通过按键“F”打开文件。
(eval-after-load "dired"
'(progn
(define-key dired-mode-map "F" 'my-dired-find-file)
(defun my-dired-find-file (&optional arg)
"Open each of the marked files, or the file under the point, or when prefix arg, the next N files "
(interactive "P")
(let* ((fn-list (dired-get-marked-files nil arg)))
(mapc 'find-file fn-list)))))
如果需要的话,显然可以覆盖内置的 'f'。
let*
(let
就足够了)。而且,我们可能只需简化最后一个形式为(mapc 'find-file (dired-get-marked-files nil arg))
。 - camdez
(add-hook 'dired-load-hook (function (lambda () (load "dired-x"))))
。 - AdobeC-u M-x dired-do-find-marked-files
,或者使用默认的按键绑定C-u C-F
。 - dpritch