[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Execute lisp function on marked files
From: |
Kevin Rodgers |
Subject: |
Re: Execute lisp function on marked files |
Date: |
Thu, 11 Nov 2004 11:38:42 -0700 |
User-agent: |
Mozilla Thunderbird 0.9 (X11/20041105) |
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