From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Kevin Rodgers Newsgroups: gmane.emacs.help Subject: Re: Execute lisp function on marked files Date: Thu, 11 Nov 2004 11:38:42 -0700 Message-ID: <2vhpttF2lvli5U1@uni-berlin.de> References: <1c6c2df9.0411100735.58bda372@posting.google.com> <2vf6tjF2kgtvoU1@uni-berlin.de> <1c6c2df9.0411110449.510132ee@posting.google.com> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1100198521 16983 80.91.229.6 (11 Nov 2004 18:42:01 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 11 Nov 2004 18:42:01 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Nov 11 19:41:58 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1CSJtN-0008Lv-00 for ; Thu, 11 Nov 2004 19:41:57 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CSK1s-00053u-OW for geh-help-gnu-emacs@m.gmane.org; Thu, 11 Nov 2004 13:50:44 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!newsmi-us.news.garr.it!newsmi-eu.news.garr.it!NewsITBone-GARR!fu-berlin.de!uni-berlin.de!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 56 Original-X-Trace: news.uni-berlin.de ezIE9JMfeVCciHhU1RAXcAs851ZNGQEPT4ur6sekwQ2+jyMH0= User-Agent: Mozilla Thunderbird 0.9 (X11/20041105) X-Accept-Language: en-us, en In-Reply-To: <1c6c2df9.0411110449.510132ee@posting.google.com> Original-Xref: shelby.stanford.edu gnu.emacs.help:126510 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:21902 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:21902 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