If I open doc.foo file, I want emacs to look for and open doc.bar file in the same folder
Asked Answered
M

1

2

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.

Mystery answered 9/6, 2012 at 5:35 Comment(0)
P
6

Take a look at the commentary for:
M-x find-library RET find-file RET

It'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 (or ff-find-related-file if you prefer that alias), and you can switch back and forth between the two files easily.

In particular, see:

  • C-hv ff-other-file-alist RET
  • C-hv ff-search-directories RET

So something like this:

(add-hook 'latex-mode-hook 'my-latex-mode-hook)

(defun my-latex-mode-hook ()
  "My LaTeX customisations."
  (setq ff-search-directories '(".")
        ff-other-file-alist  '(("\\.tex$" (".sty"))
                               ("\\.sty$" (".tex"))))
  (local-set-key (kbd "C-c f") 'ff-find-other-file))
Prine answered 9/6, 2012 at 6:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.