0
-(require 'project-local-variables)
0
- (concat ".*\\.\\(" (mapconcat (lambda (x) x) '("rb" "rhtml" "el") "\\|") "\\)")
0
- "Regexp of things to look for when using find-file-in-project.")
0
-(defvar ffip-find-options
0
- "Extra options to pass to `find' when using find-file-in-project.
0
-Use this to exclude portions of your project: \"-not -regex \\\".*vendor.*\\\"\"")
0
-(defvar ffip-project-root nil
0
- "If non-nil, overrides the project root directory location.")
0
-(defun ffip-project-files ()
0
- "Return an alist of all filenames in the project and their path.
0
-Files with duplicate filenames are suffixed with the name of the
0
-directory they are found in so that they are unique."
0
- (let ((file-alist nil))
0
- (mapcar (lambda (file)
0
- (let ((file-cons (cons (file-name-nondirectory file)
0
- (expand-file-name file))))
0
- (when (assoc (car file-cons) file-alist)
0
- (ffip-uniqueify (assoc (car file-cons) file-alist))
0
- (ffip-uniqueify file-cons))
0
- (add-to-list 'file-alist file-cons)
0
- (split-string (shell-command-to-string (concat "find " (or ffip-project-root
0
- "\" " ffip-find-options))))))
0
-(defun ffip-uniqueify (file-cons)
0
- "Set the car of the argument to include the directory name plus the file name."
0
- (concat (car file-cons) ": "
0
- (cadr (reverse (split-string (cdr file-cons) "/"))))))
0
-(defun find-file-in-project ()
0
- "Prompt with a completing list of all files in the project to find one.
0
-The project's scope is defined as the first directory containing
0
-an `.emacs-project' file. You can override this by locally
0
-setting the `ffip-project-root' variable."
0
- (let* ((project-files (ffip-project-files))
0
- (file (if (functionp 'ido-completing-read)
0
- (ido-completing-read "Find file in project: "
0
- (mapcar 'car project-files))
0
- (completing-read "Find file in project: "
0
- (mapcar 'car project-files)))))
0
- (find-file (cdr (assoc file project-files)))))
0
-(defun ffip-project-root (&optional dir)
0
- "Find the root of the project defined by presence of `.emacs-project'."
0
- (file-name-directory (plv-find-project-file default-directory "")))
0
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
0
+;;; find-file-in-project
0
+(defvar rinari-project-files-table ())
0
+(defvar ffip-subdirectories
0
+ '("app" "config" "db" "lib" "public/javascripts" "public/stylesheets"))
0
+(defun populate-project-files-table (file)
0
+ (if (file-directory-p file)
0
+ (mapc 'populate-project-files-table (directory-files file t "^[^\.]"))
0
+ (let* ((file-name (file-name-nondirectory file))
0
+ (existing-record (assoc file-name project-files-table))
0
+ (unique-parts (get-unique-directory-names file (cdr existing-record))))
0
+ (let ((new-key (concat file-name " - " (car unique-parts)))
0
+ (old-key (concat (car existing-record) " - " (cadr unique-parts))))
0
+ (setf (car existing-record) old-key)
0
+ (setq project-files-table (acons new-key file project-files-table)))
0
+ (setq project-files-table (acons file-name file project-files-table))))))
0
+(defun get-unique-directory-names (path1 path2)
0
+ (let* ((parts1 (and path1 (split-string path1 "/" t)))
0
+ (parts2 (and path2 (split-string path2 "/" t)))
0
+ (while (and part1 part2 looping)
0
+ (if (equal part1 part2)
0
+ (setq part1 (pop parts1) part2 (pop parts2))
0
+(defun find-file-in-project (file)
0
+ (interactive (list (if (or (equalp ido-mode 'file)
0
+ (equalp ido-mode 'both))
0
+ (ido-completing-read "Find file in project: "
0
+ (mapcar 'car (project-files)))
0
+ (completing-read "Find file in project: "
0
+ (mapcar 'car (project-files))))))
0
+ (find-file (cdr (assoc file project-files-table))))
0
+;; TODO: revert to the .emacs-project version with a defadvice wrapper
0
+(defun project-files (&optional file)
0
+; uncomment these lines if it's too slow to load the whole project-files-table
0
+; (when (or (not project-files-table) ; initial load
0
+; (not (string-match (rails-root) (cdar project-files-table)))) ; switched projects
0
+ (setq project-files-table nil)
0
+ (populate-project-files-table file)
0
+ (let ((root (rails-root)))
0
+ (populate-project-files-table (concat root "/" dir)))
0
+ ffip-subdirectories)))
0
(provide 'find-file-in-project)
0
;;; find-file-in-project.el ends here
Comments
No one has commented yet.