Я не знаю, действительно ли вы хотите получить полное решение или предпочитаете сами исследовать больше, но вот несколько вещей, которые должны помочь. Опубликуйте еще раз, если вы застряли:
Переменная file-local-variables-alist
содержит значения, которые вы ищете. Вы бы хотели использовать одну из assoc
функций, чтобы получить значение pdf-copy-path из списка.
Вы можете проверить, существует ли файл с помощью функции file-exists-p
и является ли он каталогом с file-attributes
(первый элемент).
Тогда используйте copy-file
.
(FWIW, я думаю, что вывод PDF будет соответствовать TeX-master, а не текущему файлу.)
[Отредактировано 2011-03-24 - введите код]
это должно работать с файлами TeX с блоком локальных переменных, например
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "master"
%%% pdf-copy-path: "/pdf/copy/path"
%%% End:
Обратите внимание на двойные кавычки вокруг значения TeX-master и значения pdf-copy-path. 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)))))