(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)) (while (and (not (eobp)) (condition-case nil (not (dired-get-filename)) (error t))) (forward-line 1)) (save-excursion (forward-line 1) (move-marker pos (1+ (point)))) (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)) (while (and (not (bobp)) (condition-case nil (not (dired-get-filename)) (error t))) (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)))))