Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

emacs ff-find-other-file does not find my header

Tags:

emacs

Somehow I can't make emacs' ff-find-other-file to get my header file. Here is what I have (minimal example):

cd ~/tmp
mkdir test
cd test
mkdir -p src/a/b inc/a/b
echo "aaaa" > src/a/b/a.cpp
echo "bbbb" > inc/a/b/a.hpp
tree

gives:

.
├── inc
│   └── a
│       └── b
│           └── a.hpp
└── src
    └── a
        └── b
            └── a.cpp

This is similar to my project structure.


emacs -Q src/a/b/a.cpp

Then copying this in *scratch* and executing it with C-x C-e:

(setq cc-search-directories '("." "../inc" "../inc/*" "../../inc/*" "../../../inc/*" "/usr/include"))

and running ff-find-other-file in buffer a.cpp, only results in a prompt in the minibuffer:

Find or create a.hpp in: ~/tmp/test/src/a/b/

C-h v on ff-search-directories returns cc-search-directories, and on cc-search-directories I get the list above.

I expect ff-find-other-file to look in ../../../inc/*, and find a.hpp. Why doesn't it?


Edit: it seems to be the recursive part that doesn't work here.

After:

cp inc/a/b/a.hpp inc/

a.hpp is found from a.cpp.

The help about ff-search-directories says:

The stars are not wildcards: they are searched for together with the preceding slash. The star represents all the subdirectories except `..', and each of these subdirectories will be searched in turn.

Note that this quote if from the help for ff-search-directories, while the list I modified is cc-search-directories. I can't see why that would make a difference though.

This and other threads on SO made me believe * would recursively search the directory tree. Wrong?

like image 233
Gauthier Avatar asked Dec 15 '25 15:12

Gauthier


1 Answers

* represents every immediate sub-directory of its parent; nothing more.

The commentary has it worded slightly more clearly:

The star is not a general wildcard character: it just indicates that the subdirectories of this directory must each be searched in turn.

i.e. For this specific example I would expect "../../../inc/*/b" to work. Or indeed "../../../inc/*/*" (as you've ended up using).

See also https://stackoverflow.com/a/23662870/324105 and note in particular that you can define functions to dynamically generate the target file path(s).

I suspect you want the a/b to be determined based on the original path, so a function to return the appropriate path to the other file would be your best solution here.

like image 74
phils Avatar answered Dec 18 '25 20:12

phils



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!