(defun dired-repeat-over-lines (arg function) ;; This version skips non-file lines. (let ((pos (make-marker))) (beginning-of-line) (cond ((> arg 0) (while (and (> arg 0) (not (eobp))) (setq arg (1- arg)) (beginning-of-line) (while (and (not (eobp)) (dired-between-files)) (forward-line 1)) (save-excursion (forward-line 1) (move-marker pos (1+ (point)))) (unless (eobp) (save-excursion (funcall function)) ;; Advance to the next line--actually, to the line that *was* next. ;; (If FUNCTION inserted some new lines in between, skip them.) (goto-char pos))) (when (eobp) (forward-line -1) (dired-move-to-filename))) ((< arg 0) (while (and (< arg 0) (not (bobp))) (setq arg (1+ arg)) (forward-line -1) (while (and (not (bobp)) (dired-between-files)) (forward-line -1)) (beginning-of-line) (when (condition-case nil (dired-get-filename) (error nil)) (save-excursion (funcall function)))) (move-marker pos nil) (dired-move-to-filename))))) (defun dired-between-files () ;; This used to be a regexp match of the `total ...' line output by ;; ls, which is slightly faster, but that is not very robust; notably, ;; it fails for non-english locales. (not (condition-case nil (dired-get-filename) (error nil))))