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

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

Re: Execute lisp function on marked files


From: Barney Dalton
Subject: Re: Execute lisp function on marked files
Date: 11 Nov 2004 04:49:51 -0800

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


reply via email to

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