2011-02-14 64 views
1

我使用emacs + AucTeX編寫LaTeX文件。在.tex文件的底部有一些局部變量:使用emacs局部變量指定要在命令中使用的路徑

%%% Local Variables: 
%%% mode: latex 
%%% TeX-master: "master-file" 
%%% End: 

這些都是由AucTeX添加當我創建的文件。

我希望做的是寫一個Lisp函數,將做到以下幾點:

  1. 檢查特定的本地變量是否存在(稱之爲pdf-copy-path
  2. 如果這個變量存在檢查它是否是形成的阱(UNIX)目錄路徑
  3. 如果是,輸出概率分佈函數複製到該文件夾​​

輸出的PDF具有相同的名稱作爲當前.tex文件,但使用.pdf擴展名。

我的lisp-fu不符合這個,我不知道如何有一個函數檢查當前文件的本地變量。任何指針讚賞。

我對這個問題而不是SU選擇了SO,因爲它似乎是一個關於lisp編程比別的更重要的問題。

回答

2

我不知道你是否真的想要一個完整的解決方案,或者寧願多探索一下自己,但這裏有一些應該幫助的東西。如果後再次你堅持:

  • 變量file-local-variables-alist認爲你正在尋找的值。您需要使用assoc函數之一來獲取alist中pdf-copy-path的值。

  • 您可以使用file-exists-p函數檢查文件是否存在,以及它是否爲file-attributes(第一個元素)的目錄。

  • 然後使用copy-file

(FWIW,我想輸出PDF輸出將匹配TeX的主,而不是當前的文件。)

[編輯2011-03-24 - 提供代碼]

這應該工作與一個局部變量的TeX文件阻止像

%%% Local Variables: 
%%% mode: latex 
%%% TeX-master: "master" 
%%% pdf-copy-path: "/pdf/copy/path" 
%%% End: 

注意周圍的TeX的主值和PDF格式拷貝路徑值雙引號。 TeX-master也可以是t

(defun copy-master-pdf() 
    "Copies the TeX master pdf file into the path defined by the 
file-local variable `pdf-copy-path', given that both exist." 
    (interactive) 
    ;; make sure we have local variables, and the right ones 
    (when (and (boundp 'file-local-variables-alist) 
      (assoc 'pdf-copy-path file-local-variables-alist) 
      (assoc 'TeX-master file-local-variables-alist)) 
    (let* ((path (cdr (assoc 'pdf-copy-path file-local-variables-alist))) 
      (master (cdr (assoc 'TeX-master file-local-variables-alist))) 
      (pdf (cond ((stringp master) 
         ;; When master is a string, it should name another file. 
         (concat (file-name-sans-extension master) ".pdf")) 
         ((and master (buffer-file-name)) 
         ;; When master is t, the current file is the master. 
         (concat (file-name-sans-extension buffer-file-name) ".pdf")) 
         (t "")))) 
     (when (and (file-exists-p pdf) 
       (file-directory-p path)) 
     ;; The 1 tells copy-file to ask before clobbering 
     (copy-file pdf path 1))))) 
+0

啊。很好看TeX主人的事情。謝謝。 – Seamus 2011-02-14 15:41:33