emacs / elisp选择带有dired / file对话框的文件,然后执行操作?

时间:2015-05-24 19:22:07

标签: emacs dired

我想编写代码,以便使用可以使用dired或其他文件对话框为操作选择文件,而不是迷你缓冲区。例如,他调用了一个"获取文件统计信息"命令,dired出现,他选择,并显示统计数据。 (这变得更有趣找到了。)

但是我可以看到这样做的两种方式 - 启动一个带有改变的键映射的dired,以便选择一个文件调用fn来完成命令,并提供给dired-find-file的建议 - 对于我来说似乎很奇怪认为这将是一项共同的任务。我错过了什么吗?

1 个答案:

答案 0 :(得分:2)

Why not leave popping-up Dired out of it, and let users do that themselves?

Just bind a key in dired-mode-map that acts on the marked files (or the current file if none marked), performing whatever action you like (e.g., show stats).

That's the typical Dired approach to this kind of thing, and the Dired code offers you all of the building blocks you need to do this easily -- in particular, dired-get-marked-files. See the code for the many dired-do-* commands defined in dired-aux.el, for examples.

For example:

(defun my-dired-do-stats (&optional arg)
  "Do stats for the marked files."
  (interactive "P")
  (dolist (file  (dired-get-marked-files nil arg))
    (my-stats-function file))))