Specifically this problem arises when working in LaTeX (auctex) for me, but I think it must have a general emacs solution.
To every doc.tex file, I have an associated and oft-edited doc.sty file in the same folder.
Is there a way that whenever I open the doc.tex file I can have emacs open the doc.sty file in that folder? I’m not proficient at all in elisp, so something very simple—it doesn’t need to be robust code: it can work on the assumption that both files are named doc.* and that both exist.
Take a look at the commentary for:
M-x
find-libraryRETfind-fileRETIt’s not precisely what you asked for, but it is a built-in solution for opening related files. Just bind a key to
ff-find-other-file(orff-find-related-fileif you prefer that alias), and you can switch back and forth between the two files easily.In particular, see:
ff-other-file-alistRETff-search-directoriesRETSo something like this: