Chain Tool by Florian
If you have some function, say some custom refactoring operation, you can call it from a dired buffer, and have it run on each marked file, using the code below.
Go into a dired buffer, mark some files, and then do M-x and run your command. In this case it would be test-for-each-dired-marked-file
;;; iterating over files in dired
;;; usage example - for-each-dired-marked-file returns a filename and path
;;; for each marked file, so this is what a function using it looks like
"opens up the file and gets the length of it, then messages the result"
(let (fpath fname mybuffer len)
(setq fpath filename)
(setq fname (file-name-nondirectory fpath))
(setq mybuffer (find-file fpath))
(setq len (buffer-size))
(message "Buffer length %d %s" len (buffer-file-name mybuffer))))
; Usage example
"Do stuff for each marked file, only works in dired window"
(if (eq major-mode 'dired-mode)
(let ((filenames (dired-get-marked-files)))
(mapcar fn filenames))
(error (format "Not a Dired buffer \(%s\)" major-mode))))
Tags: emacs mark files dired elisp