如果我打开doc.foo文件,我希望emacs在同一个文件夹中查找并打开doc.bar文件 [英] If I open doc.foo file, I want emacs to look for and open doc.bar file in the same folder
问题描述
对于每个doc.tex文件,我有一个关联和编辑的doc.sty文件在同一个文件夹。
有没有办法,只要我打开doc.tex文件,我可以让emacs打开该文件夹中的doc.sty文件?我在elisp中并不精通,所以一些非常简单的东西 - 它不需要是强大的代码:它可以工作在两个文件都被命名为doc。*并且都存在的假设。
查看评论:
Mx find-library
RET find-file
RET
这不是你要求的,但它是打开相关文件的内置解决方案。只需将键绑定到 ff-find-other-file
(或 ff-find-related-file
该别名),您可以轻松地在两个文件之间来回切换。
具体来说,请参阅:
- Ch v
ff-other-file-alist
RET - Ch v
ff-search-directories
RET
所以这样:
(add-hook'latex-mode-hook'my-latex-mode-hook)
(defun my-latex-mode- hook()
我的LaTeX自定义。
(setq ff-search-directories'(。)
ff-other-file-alist'((\\。 tex $(.sty))
(\\.sty $(.tex))))
(local-set-key(kbdCc f) 'ff-find-other-file))
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-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))
这篇关于如果我打开doc.foo文件,我希望emacs在同一个文件夹中查找并打开doc.bar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!