emacs find file in project on a big project

前端 未结 5 1707
夕颜
夕颜 2020-12-16 20:13

In vim, there is this amazing plugin called command-t, that lets you fuzzy-search through all the files in your project. We have a fairly large rails app with a ton of files

相关标签:
5条回答
  • 2020-12-16 20:30

    You can try gpicker. If you pass -t guess, it will try to figure out relevant files though scm backend such as git.

    I use following snippet to find file in project, where the project root is determined by eproject.

    (require 'iy-dep)
    
    (defcustom iy-gpicker-cmd (executable-find "gpicker")
      "Default font"
      :type 'file
      :group 'iy-config)
    
    (defun iy-gpicker-find-file (dir)
      (interactive
       (list
        (or (and current-prefix-arg (ido-read-directory-name "gpicker: " nil nil t))
            (and (boundp 'eproject-root) eproject-root)
            (and (not current-prefix-arg) (ido-read-directory-name "gpicker: " nil nil t))
            (if dired-directory (expand-file-name dired-directory) default-directory))))
      (when dir
        (with-temp-buffer
          (call-process iy-gpicker-cmd nil (list (current-buffer) nil) nil
                        "-t" "guess" "-m" dir)
          (cd dir)
          (dolist (file (split-string (buffer-string) "\0"))
            (unless (string-equal file "")
              (find-file file))))))
    
    (provide 'iy-gpicker)
    
    0 讨论(0)
  • 2020-12-16 20:33

    Depends what you mean by fuzzy matching. Most fuzzy matching is inherently slow, but some lightweight, pseudo-fuzzy algorithms are pretty fast. Generally speaking, you're probably better off with a regexp search, not a fuzzy-match search.

    Anyway, there are two parts to the question:

    • Defining a project as a given set of files and directories.
    • Searching through the project files & directories -- all or some

    Icicles can help with both:

    • Project definition, management, etc.

    • Searching a project or parts of it:

      • Searching file content (and search-and-replace)

      • Locating files

    0 讨论(0)
  • 2020-12-16 20:38

    A github rep for my concoction is here: https://github.com/lewang/anything-project-files

    I added a few more anything sources so that anything-project-find can be a drop-in replacement for "C-x b". So the idea is when you hit "C-x b" you are completing against existing buffers, recent files through recentf (personally I hack it to use "session.el" instead, but it's a small diff), files in current dir, files in current project. I find it pretty handy.

    I've used this for a while, but it's not well tested, so please report any bugs you find.

    0 讨论(0)
  • 2020-12-16 20:40

    Try https://github.com/technomancy/find-file-in-project which use GNU Find or BSD Find to find files. Nothing can beat the speed of C!

    M-x find-file-in-project-by-selected is the only command you need use.

    I tested with 50000+ files at some stone-aged netbook without any issue.

    By default it uses efficient ivy-mode to filter the candidate and ido-mode as fallback. I tested ivy-mode with three million candidates. Now you get the idea that Emacs Lisp itself is quick enough.

    At *nix, the kernel provides cache for find, so if you search the files with same input, the response is instant.

    Besides, the ivy-mode automatically cache the last search results in Emacs lisp variable ivy-last, so you can M-x ivy-resume to get the previous candidates without bothering Find.

    You can (setq my-cached-result ivy-last) to store ivy-last into another variable. Then you can M-x my-ivy-resume:

    (defun my-ivy-resume ()
      (interactive)
      (let* ((ivy-last (if my-cached-result my-cached-result ivy-last))
             (default-directory (ffip-get-project-root-directory)))
        (ivy-resume)))
    

    In this way you can store last 1000 results and re-use them ;)

    0 讨论(0)
  • 2020-12-16 20:48

    You probably want IdUtils, but not being familiar with all those other technologies you mention I can't be sure.

    0 讨论(0)
提交回复
热议问题