简体   繁体   English

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

[英]emacs/elisp select file with dired/file dialog, then perform an operation?

I want to write code so that the use can select a file for an operation using dired or some other file dialog, NOT the minibuffer. 我想编写代码,以便使用可以使用dired或其他文件对话框为操作选择文件,而不是迷你缓冲区。 Eg he invokes a "Get files statistics" command, dired comes up, he chooses, and the stats appear. 例如,他调用了“获取文件统计信息”命令,他选择了dired,并显示统计信息。 (This becomes much more interesting find-dired.) (这变得更有趣找到了。)

But the two ways I can see of doing this - launching a dired with an altered keymap so that selecting a file invokes a fn to finish the command, and supplying after advice to dired-find-file - seem odd for what I thought would be a common task. 但是我可以看到这样做的两种方式 - 启动一个带有改变的键映射的dired,以便选择一个文件调用fn来完成命令,然后提供对dired-find-file的建议 - 看起来很奇怪,我认为是一项共同的任务。 Am I missing something? 我错过了什么吗?

Why not leave popping-up Dired out of it, and let users do that themselves? 为什么不离开弹出Dired,并让用户自己做?

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 (eg, show stats). 只需绑定dired-mode-map中的一个键,该键作用于标记的文件(如果没有标记,则为当前文件),执行您喜欢的任何操作(例如,显示统计信息)。

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 . 这是典型的Dired方法,而Dired代码为您提供了轻松完成此操作所需的所有构建块 - 特别是dired-get-marked-files See the code for the many dired-do-* commands defined in dired-aux.el , for examples. 请参阅许多代码dired-do-*在定义的命令dired-aux.el ,为例子。

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))))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM