2

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?

  • 2
    I'm a fan of projectile for working with projects. Might be worth a look. – Ryan Jan 9 at 1:01
  • You can check out Ivy—you hit C-x f and then if you hit DEL 2 / you should have mini2/ selected just how the autocomplete works. – Ashton Wiersdorf Jan 9 at 2:55
  • And, of course, you can always make a macro/function to do that for a specific directory. – Ashton Wiersdorf Jan 9 at 2:55
  • The question is too vague. How do you expect to communicate the desired target directory to your command? – Drew Jan 9 at 17:14
1

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)))))
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.