Smarter `ff-find-other-file`

我是研究僧i 提交于 2019-12-11 12:14:31

问题


I'm working on a project where the source is organised in the following directory structe:

./source/include
./source/include/analysis
./source/include/tools
./source/include/utils
./source/include/utils/stream
./source/include/utils/string
[...]
./source/src
./source/src/analysis
./source/src/tools
./source/src/utils
./source/src/utils/stream
./source/src/utils/string
[...]

Where each subdirectory of ./source/include/ (including ./source/include/) contains header files. Similarly every subdir of ./source/src/ (including ./source/src/) contains implementation files.

When using ff-find-other-file on files which reside at the "top-level" (i.e. in ./source/include/ or ./source/src/) everything works fine. However I can't figure out how one can configure ff-search-directories to search deeper up and back into the directory tree.

There's already a question on SO (emacs ff-find-other-file and ff-search-directories isn't recursive) but it does not solve my problem since this works only with a static setup.

An ideal solution would be something like this (pseudo-regexp solution, where DIR_REGEXP matches all possible directory names):

"../\(DIR_REGEXP\)/include/\1/"
"../\(DIR_REGEXP\)/\(DIR_REGEXP\)/include/\1/\2/"

Is there any elisp snippet/package out there which can provide a solution?


回答1:


The commentary is pretty comprehensive, I think:

M-x find-library RET find-file RET

The example given for ff-search-directories is:

;; SEARCHING is carried out in a set of directories specified by the
;; ff-search-directories variable:
;;
;;     ("." "../../src" "../include/*" "/usr/local/*/src/*" "$PROJECT/src")
;;
;; This means that the corresponding file will be searched for first in
;; the current directory, then in ../../src, then in one of the directories
;; under ../include, and so on. The star is _not_ a general wildcard
;; character: it just indicates that the subdirectories of this directory
;; must each be searched in turn. Environment variables will be expanded in
;; the ff-search-directories variable.

If that's insufficient, ff-other-file-alist can contain function symbols which can act dynamically to "return a list consisting of the possible names of the corresponding file". See the usage of ff-cc-hh-converter (which is defined in the library as a reference).



来源:https://stackoverflow.com/questions/23660637/smarter-ff-find-other-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!