;;; dir-iterate-files --- iterate directory files ;;; Commentary: ;; ;; .-----------------------------------------------. ;; \ dir-iterate-files - iterate directory files \ ;; \ by Emanuel Berg \ ;; / embe8573 AT&T student DOS uu DOS se / ;; / updated: Thu Jan 8 02:47:47 CET 2015 / ;; '-----------------------------------------------' ;; ;; Iterate the contents of the directory of the ;; current buffer file. ;; ;; This can be used for many things, but the one ;; primarily in mind is when there are many files in ;; the same directory, and those files must be sorted ;; as a function of their contents, and thus be viewed ;; before it can be determined where they should go. ;; ;; This package, in combination with a function that ;; sends files in different directions, would speed up ;; such work considerably, and make it more enjoyable ;; and fun. ;; ;; Note that it is all but compulsory to bind ;; `dir-next-file' to a key or key sequence, as ;; otherwise selecting the next file most other ways ;; would be just as fast (or slow). ;;; Code: (require 'cl-lib) (defun drop-sublist (l drop-l) "Every element that is in L, but isn't in DROP-L." (cl-remove-if #'(lambda (e) (member e drop-l)) l) ) (defun dir-common-files () "Get a list of all files in the directory of the current buffer file, except for '.' and '..'." (let*((dir (file-name-directory (buffer-file-name))) (all-files (directory-files dir)) (files (drop-sublist all-files '("." ".."))) ) files)) (defun dir-next-file () "Go to the next file in the list returned by `dir-common-files'. If the current buffer file is the last file already, start over. If the current buffer file isn't in `dir-common-files', start with the first one." (interactive) (let*((files (dir-common-files)) (this-file-forward (member (buffer-name) files)) ) (if this-file-forward (find-file (if (eq (length this-file-forward) 1) (car files) (cadr this-file-forward) )) (find-file (car files)) ))) (provide 'iterate-files) ;;; iterate-files.el ends here