Mac – How to toggle between .cpp and .hpp that are not in the same directory

emacslisp

Is there an Emacs function that toggles between .cpp and .hpp files that are not in the same directories?

I know there is toggle-source.el, but it apparently does not handle the case where .cpp and .hpp are in different directories. But my directory structure is like this:

project1/src/foo.cpp
project1/include/foo.hpp
project2/src/bar.cpp
project2/include/bar.hpp

It shouldn't be hard to toggle between src/foo.cpp and include/foo.hpp but I don't speak Lisp.

Best Answer

Take a look at ff-find-other-file, in find-file.el. If the .h and .cpp files are in the same directory, this will just work, but you should be able to use it with different locations by modifying the value of ff-search-directories.