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

一个人想着一个人 提交于 2019-12-13 15:21:37

问题


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.


回答1:


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))


来源:https://stackoverflow.com/questions/10958672/if-i-open-doc-foo-file-i-want-emacs-to-look-for-and-open-doc-bar-file-in-the-sa

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