* Extend Dired to Call a Function on a File?
@ 2016-10-12 17:46 Brendan Leber
2016-10-12 20:12 ` Drew Adams
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Brendan Leber @ 2016-10-12 17:46 UTC (permalink / raw)
To: help-gnu-emacs
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?
Thanks!
B
--
C++ tries to guard against Murphy, not Machiavelli. - Damian Conway
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: Extend Dired to Call a Function on a File?
2016-10-12 17:46 Extend Dired to Call a Function on a File? Brendan Leber
@ 2016-10-12 20:12 ` Drew Adams
2016-10-12 20:36 ` Brendan Leber
2016-10-12 20:18 ` Stephen Berman
2016-10-12 21:12 ` John Mastro
2 siblings, 1 reply; 7+ messages in thread
From: Drew Adams @ 2016-10-12 20:12 UTC (permalink / raw)
To: Brendan Leber, help-gnu-emacs
> 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?
Not quite sure what you are asking. You can of course use `M-!' to
act on the marked files using a shell command.
But I guess you are asking about mapping a Lisp function over files.
If you are asking about Dired then presumably you are talking about
acting on the marked files (else, why Dired?). If so, and if you
use Dired+, then you can use `@', which is bound to command
`diredp-do-apply-function', to apply a Lisp function to each of the
marked files.
And you can, similarly, use `M-+ @', which is bound to
`diredp-do-apply-function-recursive', to do the same thing for the
marked files and the files in marked subdirs, for any number of
Dired buffers for descendent directories.
https://www.emacswiki.org/emacs/DiredPlus
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Extend Dired to Call a Function on a File?
2016-10-12 20:12 ` Drew Adams
@ 2016-10-12 20:36 ` Brendan Leber
2016-10-13 0:34 ` Drew Adams
0 siblings, 1 reply; 7+ messages in thread
From: Brendan Leber @ 2016-10-12 20:36 UTC (permalink / raw)
To: Drew Adams; +Cc: help-gnu-emacs
On Wed, Oct 12, 2016 at 1:12 PM, Drew Adams <drew.adams@oracle.com> wrote:
> But I guess you are asking about mapping a Lisp function over files.
That is what I meant.
> If you are asking about Dired then presumably you are talking about
> acting on the marked files (else, why Dired?). If so, and if you
> use Dired+, then you can use `@', which is bound to command
> `diredp-do-apply-function', to apply a Lisp function to each of the
> marked files.
I haven't used Dired+ but it sounds like the `@' key will do exactly
what I want. Thanks!
B
--
C++ tries to guard against Murphy, not Machiavelli. - Damian Conway
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: Extend Dired to Call a Function on a File?
2016-10-12 20:36 ` Brendan Leber
@ 2016-10-13 0:34 ` Drew Adams
2016-10-13 16:59 ` Brendan Leber
0 siblings, 1 reply; 7+ messages in thread
From: Drew Adams @ 2016-10-13 0:34 UTC (permalink / raw)
To: Brendan Leber; +Cc: help-gnu-emacs
> > But I guess you are asking about mapping a Lisp function over files.
>
> That is what I meant.
>
> > If you are asking about Dired then presumably you are talking about
> > acting on the marked files (else, why Dired?). If so, and if you
> > use Dired+, then you can use `@', which is bound to command
> > `diredp-do-apply-function', to apply a Lisp function to each of the
> > marked files.
>
> I haven't used Dired+ but it sounds like the `@' key will do exactly
> what I want. Thanks!
Also, if you don't care about using Dired, and you just want to act
on all of the files in a directory that match a regexp, you can just
map your function over the result of calling `directory-files'.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Extend Dired to Call a Function on a File?
2016-10-13 0:34 ` Drew Adams
@ 2016-10-13 16:59 ` Brendan Leber
0 siblings, 0 replies; 7+ messages in thread
From: Brendan Leber @ 2016-10-13 16:59 UTC (permalink / raw)
To: Drew Adams; +Cc: help-gnu-emacs
On Wed, Oct 12, 2016 at 5:34 PM, Drew Adams <drew.adams@oracle.com> wrote:
> Also, if you don't care about using Dired, and you just want to act
> on all of the files in a directory that match a regexp, you can just
> map your function over the result of calling `directory-files'.
That is good information. Thanks!
B
--
C++ tries to guard against Murphy, not Machiavelli. - Damian Conway
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Extend Dired to Call a Function on a File?
2016-10-12 17:46 Extend Dired to Call a Function on a File? Brendan Leber
2016-10-12 20:12 ` Drew Adams
@ 2016-10-12 20:18 ` Stephen Berman
2016-10-12 21:12 ` John Mastro
2 siblings, 0 replies; 7+ messages in thread
From: Stephen Berman @ 2016-10-12 20:18 UTC (permalink / raw)
To: Brendan Leber; +Cc: help-gnu-emacs
On Wed, 12 Oct 2016 10:46:07 -0700 Brendan Leber <brendan@brendanleber.com> 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?
Perhaps the function dired-get-filename does what you want.
Steve Berman
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Extend Dired to Call a Function on a File?
2016-10-12 17:46 Extend Dired to Call a Function on a File? Brendan Leber
2016-10-12 20:12 ` Drew Adams
2016-10-12 20:18 ` Stephen Berman
@ 2016-10-12 21:12 ` John Mastro
2 siblings, 0 replies; 7+ messages in thread
From: John Mastro @ 2016-10-12 21:12 UTC (permalink / raw)
To: help-gnu-emacs@gnu.org; +Cc: Brendan Leber
Brendan Leber <brendan@brendanleber.com> 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
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-10-13 16:59 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-12 17:46 Extend Dired to Call a Function on a File? Brendan Leber
2016-10-12 20:12 ` Drew Adams
2016-10-12 20:36 ` Brendan Leber
2016-10-13 0:34 ` Drew Adams
2016-10-13 16:59 ` Brendan Leber
2016-10-12 20:18 ` Stephen Berman
2016-10-12 21:12 ` John Mastro
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).