arorem hacks

«

»

software patents - because extortionists are people
		too.

I've been improving arorem a bit these past few days, and this little snippet has come in very handy:

(defvar project-files-table ())

(defun populate-project-files-table (file)
  (if (file-directory-p file)
      (mapc 'populate-project-files-table (directory-files file t "^[^\.]"))
    (setq project-files-table (acons (file-name-nondirectory file) file project-files-table))))

(defun find-file-in-project (file)
  (interactive (list (completing-read "Find file in project:  " (mapcar 'car (project-files)))))
  (find-file (cdr (assoc file project-files-table))))

(defun project-files ()
  (when (or (not project-files-table) ; initial load
            (not (string-match (rails-root) (cdar project-files-table)))) ; switched projects
    (setq project-files-table nil)
    (populate-project-files-table (concat (rails-root) "/app")))
  project-files-table)


(defun rails-root (&optional dir)
  (or dir (setq dir default-directory))
  (if (file-exists-p (concat dir "config/environment.rb"))
      dir
    (if (equal dir  "/")
        nil
      (rails-root (expand-file-name (concat dir "../"))))))

« older | 2006-07-26T13:15:10Z | newer »