unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Execute lisp function on marked files
@ 2004-11-10 15:35 Barney Dalton
  2004-11-10 19:02 ` Kevin Rodgers
  0 siblings, 1 reply; 4+ messages in thread
From: Barney Dalton @ 2004-11-10 15:35 UTC (permalink / raw)


Is it possible to execute on each marked file in a dired or buffer
list buffer? I see that you can execute a shell command from dired but
how about a lisp command?

Thanks
Barney

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Execute lisp function on marked files
  2004-11-10 15:35 Execute lisp function on marked files Barney Dalton
@ 2004-11-10 19:02 ` Kevin Rodgers
  2004-11-11 12:49   ` Barney Dalton
  0 siblings, 1 reply; 4+ messages in thread
From: Kevin Rodgers @ 2004-11-10 19:02 UTC (permalink / raw)


Barney Dalton wrote:
 > Is it possible to execute on each marked file in a dired or buffer
 > list buffer? I see that you can execute a shell command from dired but
 > how about a lisp command?

See the definitions of dired-do-byte-compile and dired-do-load for
examples.

-- 
Kevin Rodgers

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Execute lisp function on marked files
  2004-11-10 19:02 ` Kevin Rodgers
@ 2004-11-11 12:49   ` Barney Dalton
  2004-11-11 18:38     ` Kevin Rodgers
  0 siblings, 1 reply; 4+ messages in thread
From: Barney Dalton @ 2004-11-11 12:49 UTC (permalink / raw)


Kevin Rodgers <ihs_4664@yahoo.com> wrote in message news:<2vf6tjF2kgtvoU1@uni-berlin.de>...
> Barney Dalton wrote:
>  > Is it possible to execute on each marked file in a dired or buffer
>  > list buffer? I see that you can execute a shell command from dired but
>  > how about a lisp command?
> 
> See the definitions of dired-do-byte-compile and dired-do-load for
> examples.

This seems to do the trick, but I can't believe it doesn't already
exist. Comments on how to improve it would be welcomed.

(defun dired-lisp-function (the-function)
  ;; Return nil for success, offending file name else.
  (let ((file (dired-get-filename)) failure)
    (condition-case err
        (funcall the-function file)
      (error (setq failure err)))
    (if (not failure)
        nil
      (dired-log "%s error for %s:\n%s\n" (symbol-name 'the-function)
file failure)
      (dired-make-relative file))))


(defun dired-do-lisp-function (the-function &optional arg)
  "Call THE-FUNCTION on each marked (or next ARG)
  files. THE-FUNCTION should take one argument (the filename)"
  (interactive "aFunction to apply to marked files : \nP")
  (dired-map-over-marks-check 
   (function (lambda () (dired-lisp-function the-function))) 
   arg 
   (symbol-value 'the-function) t))


Barney

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Execute lisp function on marked files
  2004-11-11 12:49   ` Barney Dalton
@ 2004-11-11 18:38     ` Kevin Rodgers
  0 siblings, 0 replies; 4+ messages in thread
From: Kevin Rodgers @ 2004-11-11 18:38 UTC (permalink / raw)


Barney Dalton wrote:
 > This seems to do the trick, but I can't believe it doesn't already
 > exist. Comments on how to improve it would be welcomed.
 >
 > (defun dired-lisp-function (the-function)
 >   ;; Return nil for success, offending file name else.
 >   (let ((file (dired-get-filename)) failure)
 >     (condition-case err
 >         (funcall the-function file)
 >       (error (setq failure err)))
 >     (if (not failure)
 >         nil
 >       (dired-log "%s error for %s:\n%s\n" (symbol-name 'the-function)
 > file failure)
 >       (dired-make-relative file))))
 >
 >
 > (defun dired-do-lisp-function (the-function &optional arg)
 >   "Call THE-FUNCTION on each marked (or next ARG)
 >   files. THE-FUNCTION should take one argument (the filename)"
 >   (interactive "aFunction to apply to marked files : \nP")
 >   (dired-map-over-marks-check
 >    (function (lambda () (dired-lisp-function the-function)))
 >    arg
 >    (symbol-value 'the-function) t))

I think I would call them dired-funcall and dired-do-funcall, just name
the argument FUNCTION, make the doc string adhere to convention, and 
simplify
the call to dired-map-over-marks-check:

(defun dired-funcall (function)
   ;; Return nil for success, offending file name else.
   (let ((file (dired-get-filename)) failure)
     (condition-case err
         (funcall function file)
       (error (setq failure err)))
     (if (not failure)
         nil
       (dired-log "%s error for %s:\n%s\n" function file failure)
       (dired-make-relative file))))

(defun dired-do-funcall (function &optional arg)
   "Call FUNCTION on each marked (or next ARG) files.
FUNCTION should take one argument (the filename)."
   (interactive "aFunction to call on each marked file: \nP")
   (dired-map-over-marks-check (function dired-funcall) arg function t))

You might also consider restricting it to commands, which are a much
smaller set of functions that the user is more likely to be familiar
with:

   (interactive "CCommand ...")

-- 
Kevin Rodgers

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-11-11 18:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-11-10 15:35 Execute lisp function on marked files Barney Dalton
2004-11-10 19:02 ` Kevin Rodgers
2004-11-11 12:49   ` Barney Dalton
2004-11-11 18:38     ` Kevin Rodgers

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