Emacs Lisp:如何向列表“LaTeX-clean-intermediate-suffixes”添加内容?

3
我希望为latex命令LaTeX-clean-intermediate-suffixes添加一些正则表达式。我尝试过,但是……
(setq LaTeX-clean-intermediate-suffixes
        (append LaTeX-clean-intermediate-suffixes (list "\\.foo" "\\.bar"))) 

但我收到如下警告:

Warning (initialization): An error occurred while loading `/Users/myusername/.emacs':

Symbol's value as variable is void: LaTeX-clean-intermediate-suffixes

To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file.  Start Emacs with
the `--debug-init' option to view a complete error backtrace.

如何将一些字符串/后缀添加到此列表中?

感谢您的帮助,我已经在上面添加了警告。 - Marius Hofert
1个回答

8

看起来你正在尝试在定义变量的包加载之前修改变量的值。C-h v显示该变量在"latex.el"文件中定义,因此请尝试执行以下操作:

(eval-after-load 'latex
  '(setq LaTeX-clean-intermediate-suffixes
     (append LaTeX-clean-intermediate-suffixes (list "\\.foo" "\\.bar"))))

请注意,eval-after-load是一个函数,需要将要评估的代码引用起来--这有点令人困惑,因为它与同名的eval-when-compile和朋友们不同,后者是宏。
顺便说一下,您也可以使用add-to-list将项目添加到列表中,第三个参数为t,使其附加而不是连接到前面。 add-to-list也是一个函数,所以这里变量的名称需要引用。有时,这比setqappend的组合更易读,但您只能一次添加一个项目:
(add-to-list 'LaTeX-clean-intermediate-suffixes "\\.foo" t)

另一个好处是,在添加之前,它将检查列表中是否已经存在"\\.foo",这对于加载路径等事情非常有用。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接