我有很多目录充满了一堆TeX文档.因此,有很多文件具有相同的基本文件名和不同的扩展名.但是,其中只有一个是可编辑的.我想要一种方法来说服Emacs,如果我在一个我所拥有的目录中
document.tex document.log document.pdf document.bbl document.aux ...
而且我在迷你游戏中并且做到了
~/Documents/.../doc
它填写'document.tex',因为那是该目录中唯一真正可编辑的文档.有人知道这样做的好方法吗?
我写了一些应该做你想要的代码.基本思想是将变量设置'completion-ignored-extensions
为与要跳过的扩展名匹配,但仅限于存在.tex
文件时.这段代码就是这样.
(defadvice find-file-read-args (around find-file-read-args-limit-choices activate) "set some stuff up for controlling extensions when tab completing" (let ((completion-ignored-extensions completion-ignored-extensions) (find-file-limit-choices t)) ad-do-it)) (defadvice minibuffer-complete (around minibuffer-complete-limit-choices nil activate) "When in find-file, check for files of extension .tex, and if they're found, ignore .log .pdf .bbl .aux" (let ((add-or-remove (if (and (boundp 'find-file-limit-choices) find-file-limit-choices (save-excursion (let ((b (progn (beginning-of-line) (point))) (e (progn (end-of-line) (point)))) (directory-files (file-name-directory (buffer-substring-no-properties b e)) nil "\\.tex$")))) 'add-to-list 'remove))) (mapc (lambda (e) (setq completion-ignored-extensions (funcall add-or-remove 'completion-ignored-extensions e))) '(".log" ".pdf" ".bbl" ".aux"))) ad-do-it)
请享用.