2009-04-26 37 views
4

我有很多目錄充滿了一堆TeX文檔。所以,有很多文件具有相同的基本文件名和不同的擴展名。但其中只有一個是可編輯的。我想辦法說服Emacs的,如果我在我有喜歡使用Emacs文件名完成某些文件擴展名

document.tex 
document.log 
document.pdf 
document.bbl 
document.aux 
... 

一個目錄,我在小緩衝區並做

~/Documents/.../doc<TAB> 

它的文檔中填充.tex',因爲這是該目錄中唯一真正可編輯的文檔。任何人都知道有一個很好的方法來做到這一點?

回答

6

我寫了一些代碼,應該做你想做的。基本思想是設置變量'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) 

享受。

+0

我收到'mapcq'的未定義函數錯誤 - 是由我應該加載的elisp包提供的嗎? – 2009-04-28 19:55:09

1

在你的情況下,最簡單的方法就是自定義變量「completion-ignored-extensions」。

但是,這將意味着emacs總會忽略諸如「.log」和「.pdf」之類的東西,這可能不是您想要的。如果您希望它更具選擇性,您可能不得不有效地重新實現函數file-name-completion。

1

如果您願意安裝大型圖書館並閱讀一些文檔,您可以查看Icicles並定義符合您需求的sort function。另一種方法是ido,其wiki頁面有一個例子sorting by mtime,應該很容易通過文件擴展名的功能進行排序。