Permalink
Browse files

Add ffip-full-paths.

  • Loading branch information...
1 parent 7a4b21f commit 2a983dff4f5c724b8f00a1d80930517585696974 @technomancy committed Jul 15, 2012
Showing with 18 additions and 15 deletions.
  1. +18 −15 find-file-in-project.el
View
33 find-file-in-project.el
@@ -86,6 +86,9 @@ This overrides variable `ffip-project-root' when set.")
(defvar ffip-limit 512
"Limit results to this many files.")
+(defvar ffip-full-paths nil
+ "If non-nil, show fully project-relative paths.")
+
(defun ffip-project-root ()
"Return the root of the project."
(let ((project-root (or ffip-project-root
@@ -99,7 +102,6 @@ This overrides variable `ffip-project-root' when set.")
(defun ffip-uniqueify (file-cons)
"Set the car of FILE-CONS to include the directory name plus the file name."
- ;; TODO: see if we can use uniquify.el
(setcar file-cons
(concat (cadr (reverse (split-string (cdr file-cons) "/"))) "/"
(car file-cons))))
@@ -114,23 +116,24 @@ This overrides variable `ffip-project-root' when set.")
Files with duplicate filenames are suffixed with the name of the
directory they are found in so that they are unique."
- (let ((file-alist nil))
+ (let ((file-alist nil)
+ (root (expand-file-name (or ffip-project-root (ffip-project-root)
+ (error "No project root found")))))
(mapcar (lambda (file)
- (let ((file-cons (cons (file-name-nondirectory file)
- (expand-file-name file))))
- (when (assoc (car file-cons) file-alist)
- (ffip-uniqueify (assoc (car file-cons) file-alist))
- (ffip-uniqueify file-cons))
- (add-to-list 'file-alist file-cons)
- file-cons))
+ (if ffip-full-paths
+ (cons (substring (expand-file-name file) (length root))
+ (expand-file-name file))
+ (let ((file-cons (cons (file-name-nondirectory file)
+ (expand-file-name file))))
+ (when (assoc (car file-cons) file-alist)
+ (ffip-uniqueify (assoc (car file-cons) file-alist))
+ (ffip-uniqueify file-cons))
+ (add-to-list 'file-alist file-cons)
+ file-cons)))
(split-string (shell-command-to-string
(format "find %s -type f \\( %s \\) %s | head -n %s"
- (or ffip-project-root
- (ffip-project-root)
- (error "No project root found"))
- (ffip-join-patterns)
- ffip-find-options
- ffip-limit))))))
+ root (ffip-join-patterns)
+ ffip-find-options ffip-limit))))))
;;;###autoload
(defun find-file-in-project ()

0 comments on commit 2a983df

Please sign in to comment.