From: Austin Bingham Date: Sun, 29 May 2011 19:06:24 +0000 (+0200) Subject: initial attempt at eproject-populate X-Git-Url: https://repo.or.cz/w/eproject.git/commitdiff_plain/1e1104bcde14628ae93e505cf17e61f08fb45f87 initial attempt at eproject-populate --- diff --git a/eproject.el b/eproject.el index 1a9f52c..3af8313 100644 --- a/eproject.el +++ b/eproject.el @@ -1243,5 +1243,54 @@ for all project files (nil/t)." (provide 'eproject) (eproject-startup) +;;; eproject-populate + +; TODO: Add support for skipping common "untracked" directories, +; e.g. .hg, .svn, etc. + +; TODO: Some sort of auto-populate? Picks up everything that matches +; common source-file extensions + +(defun prj-walk-path (dir action) + "walk DIR executing ACTION with (dir file)" + (cond ((file-directory-p dir) + (or (char-equal ?/ (aref dir(1- (length dir)))) + (setq dir (file-name-as-directory dir))) + (let ((lst (directory-files dir nil nil t)) + fullname file) + (while lst + (setq file (car lst)) + (setq lst (cdr lst)) + (cond ((member file '("." ".."))) + (t + (and (funcall action dir file) + (setq fullname (concat dir file)) + (file-directory-p fullname) + (prj-walk-path fullname action))))))) + (t + (funcall action + (file-name-directory dir) + (file-name-nondirectory dir))))) + +(defun prj-add-if (p dir file) + "If `file` matches the regex `p`, dir+file is added to the project." + (if (string-match p file) + (prj-insert-file (concat dir file) (prj-config-get-result 'f)) + 't)) + +(defun eproject-populate (dir p) + "Add all files under DIR which match regex P to the project." + (interactive + (list + (read-directory-name "Directory: " prj-directory) + (read-string "Pattern: " "*"))) + (unless prj-current (error "No project open")) + + ; TODO: Verify that `dir` is under prj-directory? Is this required? + + (when p + (prj-walk-path dir + (lambda (dir file) (prj-add-if p dir file))))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; eproject.el ends here