使用emacs局部变量指定要在命令中使用的路径
我使用emacs+AucTeX来编写LaTeX文件。使用emacs局部变量指定要在命令中使用的路径,emacs,lisp,local-variables,Emacs,Lisp,Local Variables,我使用emacs+AucTeX来编写LaTeX文件。.tex文件底部有一些局部变量: %%% Local Variables: %%% mode: latex %%% TeX-master: "master-file" %%% End: 这些是在我创建文件时由AucTeX添加的 我想做的是编写一个lisp函数,它将执行以下操作: 检查是否存在特定的局部变量(将其称为pdf copy path) 如果此变量存在,请检查它是否是格式正确的(unix)目录路径 如果是,请将输出pdf复制到该文件
.tex
文件底部有一些局部变量:
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "master-file"
%%% End:
这些是在我创建文件时由AucTeX添加的
我想做的是编写一个lisp函数,它将执行以下操作:
pdf copy path
).tex
文件同名,但扩展名为.pdf
我的lisp-fu无法满足这一要求,我不知道如何让函数检查当前文件中的局部变量。欢迎指点
对于这个问题,我选择这样而不是SU,因为这似乎是一个关于lisp编程的问题,而不是其他任何问题。我不知道您是否真的想要一个完整的解决方案,或者更愿意自己探索更多,但这里有一些事情应该会有所帮助。如果您被卡住,请再次发布:
- 变量
保存您要查找的值。您需要使用file local variables alist
函数之一从列表中获取pdf副本路径的值assoc
- 您可以使用
功能检查文件是否存在,以及它是否是具有file-exists-p
文件属性的目录(第一个元素)
- 然后使用
复制文件
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "master"
%%% pdf-copy-path: "/pdf/copy/path"
%%% End:
请注意,TeX master值和pdf copy path值周围有双引号。TeX主机也可以是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)))))
啊。关于TeX master的事,大家都知道了。谢谢。我真的是口齿不清的新手。因此,我想在
file local…
上使用某种assoc
函数来提取正确变量的值(如果存在)。如果有,将其作为参数传递给copy file
对吗assoc
为您提供配对,而不是cdr
?我真正需要的是一个好的“lisp for emacs”教程…我不会声称自己是一个熟练的lisp程序员,但更新的解决方案应该能让你在大部分方面达到目的。非常感谢!这很有效。有一件事:用一个“用例”更新您的答案可能是值得的:我花了几次时间才确定我希望路径位于“double/quotes/”