emacs ff-find-other-file and ff-search-directories

2019-04-12 12:56发布

问题:

Can we make ff-find-other-file to search recursively in directories which are listed in ff-search-directories.

Instead of searching only in /usr/include, it would also search in /usr/include/llvm. Or likewise.

回答1:

I've added this function to my .emacs file:

(defun get-all-subdirectories(dir-list)
  "Returns a list of all recursive subdirectories of dir-list, 
   ignoring directories with names that start with . (dot)"
  (split-string 
   (shell-command-to-string 
     (concat "find " 
             (mapconcat 'identity dir-list " ")
             " -type d -not -regex \".*/\\\..*\""))))

And, in my c-mode-common-hook, I have this:

(setq ff-search-directories (get-all-subdirectories (list "dirA" "dirB")))

This assumes you have a standard Unix find command in your PATH. If you're on Windows, you can get a copy of find here: http://unxutils.sourceforge.net/

It takes a little while to run if you have many directories for it to recurse through.



回答2:

Add a /* after the directories where you want subdirectories searched. So set ff-search-directories so that it contains "/usr/include/*".