Say I have a project directory called "project". In the directory there are two directories "mini1" and "mini2". Suppose my active buffer is deep within a subdirectory in "mini1". Is there a way to make a C-f like binding where the pre-existing directory text is /project/mini2/ and not the deeply nested directory under mini1 that I'm in?
1 Answer
Use find-directory-in-project-by-selected
from https://github.com/technomancy/find-file-in-project
I also wrote a prototype in pure Lisp. It does not use any third party command line program or package,
(require 'find-lisp)
(require 'dired)
(require 'ido)
(defun my-open-dir-in-project ()
"Open directory in project."
(interactive)
(let* ((root (locate-dominating-file default-directory ".git"))
(input-regex (read-string "Input regex (or press ENTER): "))
(ignored-regex ".*/\\.git\\|.*/\\.svn\\|.*/\\.bzr")
(find-lisp-regexp (if (string= input-regex "") ".*" input-regex))
(cands (find-lisp-find-files-internal
root
'find-lisp-file-predicate-is-directory
'find-lisp-default-directory-predicate))
selected)
(when cands
(setq cands
(delq nil
(mapcar `(lambda (c)
(unless (string-match-p ,ignored-regex c) c))
cands)))
(setq selected (and cands
;; `ido-completing-read' could be replaced with `ivy-read'
(ido-completing-read (format "directories %s: " root)
cands))))
(when selected
(switch-to-buffer (dired selected)))))
C-x f
and then if you hitDEL 2 /
you should havemini2/
selected just how the autocomplete works.