help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Extend Dired to Call a Function on a File?


From: John Mastro
Subject: Re: Extend Dired to Call a Function on a File?
Date: Wed, 12 Oct 2016 14:12:33 -0700

Brendan Leber <address@hidden> wrote:
> Greetings!
>
> I have a function I've used to work on files that right now I call
> manually with M-x my-shiny-function RET my-shiny.file.  This works
> great for the one off file.  Yet I usually have to process batches of
> files in a given directory.  Being able to add a key binding to dired
> would be awesome as I'm already using dired on the directory to rename
> files and such.
>
> I know enough elisp to add the key binding and write the function, I
> think.  The place I'm stuck is getting the file name as the first
> argument to the function when the binding is pressed.  Can anyone
> share some pointers to make this happen?

If I understand your question correctly, I think you want something like
this:

(defun my-shiny-dired-command (file)
  (interactive (list (dired-filename-at-point)))
  (my-shiny-function file))

Or alternatively this, which will work on the files you've marked or, if
there are none, the file at point:

(defun my-shiny-dired-command (files)
  (interactive (list (dired-get-marked-files)))
  (dolist (file files)
    (my-shiny-function file)))

Hope that helps

        John



reply via email to

[Prev in Thread] Current Thread [Next in Thread]