I have lots of directories filled with a bunch of TeX documents. So, there's lots of files with the same base filename and different extensions. Only one of them, though, is editable. I'd like a way to convince Emacs that if I'm in a directory where I've got
我有很多目录充满了一堆TeX文档。因此,有许多文件具有相同的基本文件名和不同的扩展名。但是,其中只有一个是可编辑的。我想要一种方法来说服Emacs如果我在我所拥有的目录中
document.tex
document.log
document.pdf
document.bbl
document.aux
...
and I'm in the minibuffer and do
而且我在迷你游戏中并做到了
~/Documents/.../doc<TAB>
it fills in 'document.tex', because that's the only really properly editable document in that directory. Anybody know of a good way to do that?
它填写'document.tex',因为那是该目录中唯一真正可编辑的文档。有人知道这样做的好方法吗?
3 个解决方案
#1
I've written some code that should do what you want. The basic idea is to set the variable 'completion-ignored-extensions
to match the extensions you want to skip, but only when there are .tex
files present. This code does that.
我写了一些应该做你想做的代码。基本思想是设置变量'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)
Enjoy.
#2
Probably the easiest way to do this in your case is just to customize the variable "completion-ignored-extensions".
在您的情况下,最简单的方法就是自定义变量“completion-ignored-extensions”。
However, this will mean that emacs always ignores things like ".log" and ".pdf" which may not be what you want. If you want it to be more selective, you may have to effectively re-implement the function file-name-completion.
但是,这意味着emacs总是忽略“。log”和“.pdf”之类的东西,这可能不是你想要的。如果您希望它更具选择性,您可能必须有效地重新实现函数file-name-completion。
#3
If you are open to installing a large-ish library and reading some documentation, you could take a look at Icicles and define a sort function that meets your needs. An alternative is ido whose wiki page has an example of sorting by mtime, which should be easy to change to sort by a function of the filename extension.
如果您愿意安装一个大型库并阅读一些文档,您可以查看Icicles并定义一个满足您需求的排序功能。另一种方法是ido,其wiki页面有一个按mtime排序的例子,应该很容易通过文件扩展名的功能进行排序。
#1
I've written some code that should do what you want. The basic idea is to set the variable 'completion-ignored-extensions
to match the extensions you want to skip, but only when there are .tex
files present. This code does that.
我写了一些应该做你想做的代码。基本思想是设置变量'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)
Enjoy.
#2
Probably the easiest way to do this in your case is just to customize the variable "completion-ignored-extensions".
在您的情况下,最简单的方法就是自定义变量“completion-ignored-extensions”。
However, this will mean that emacs always ignores things like ".log" and ".pdf" which may not be what you want. If you want it to be more selective, you may have to effectively re-implement the function file-name-completion.
但是,这意味着emacs总是忽略“。log”和“.pdf”之类的东西,这可能不是你想要的。如果您希望它更具选择性,您可能必须有效地重新实现函数file-name-completion。
#3
If you are open to installing a large-ish library and reading some documentation, you could take a look at Icicles and define a sort function that meets your needs. An alternative is ido whose wiki page has an example of sorting by mtime, which should be easy to change to sort by a function of the filename extension.
如果您愿意安装一个大型库并阅读一些文档,您可以查看Icicles并定义一个满足您需求的排序功能。另一种方法是ido,其wiki页面有一个按mtime排序的例子,应该很容易通过文件扩展名的功能进行排序。