bbatsov/projectile — pull request #135 by rejeep (2013-07-05 09:34:24+00:00)
Title: Custom hashifying

Hi,

I read about the decision to remove hashifying in https://github.com/bbatsov/projectile/issues/108. It has been bugging me for quite some time that it was removed from projectile. Without hashifying, projectile's find file functionality is almost useless to me.

This pull request contains two commits:

* https://github.com/rejeep/projectile/commit/92de619c38f8a783c1f47947fe7b190c72f61251 - Caching bug
* https://github.com/rejeep/projectile/commit/99d9e6e89563a86aee54ffb41f785367a3e3c9da - Allow to specify custom completion function

The second commit allows you to specify whatever completion function you want. Since I really don't want files relative to the root, but rather just the file name, I created this function. I'm not sure if you want this function as a part of projectile, if you do, tell me and I'll add it. Otherwise people that find it useful can simply add it to their Emacs config.

(defun rejeep-projectile-completion-fn (prompt choises)
"Projectile completion function that only shows file name.

If two files have same name, new completion appears to select
between them. These include the path relative to the project
root."
(interactive)
(let* ((choises
(-uniq (--map (file-name-nondirectory it) choises)))
(choise
(ido-completing-read prompt choises)))
(let ((matching-files
(-filter
(lambda (file)
(equal (file-name-nondirectory file) choise))
(gethash (projectile-project-root) projectile-projects-cache))))
(if (> (length matching-files) 1)
(ido-completing-read
prompt
(-map
(lambda (matching-file)
(s-chop-prefix (projectile-project-root) matching-file))
matching-files))
(car matching-files)))))

(setq projectile-completion-system 'rejeep-projectile-completion-fn)

Note that I just created this hence has not been tested that well.