如何在调用mode-hook之前加载在dir-locals中定义的变量?

时间:2013-10-31 02:31:44

标签: emacs

我想在.dir-locals.el中定义一些变量,然后我在钩子中添加钩子到python-mode-hook,我想读取.dir-locals中定义的变量。问题是在加载.dir-locals.el

之前调用了模式钩子

交换加载顺序的任何想法?

1 个答案:

答案 0 :(得分:4)

您无法更换序列。它在normal-mode中被硬编码。

但是,您可以在hack-local-variables-hook处挂钩,在设置所有局部变量后运行。假设您目前有以下内容:

(defun my-python-hook-function ()
  (message "Hello world"))

(add-hook 'python-mode-hook #'my-python-hook-function)

您只需将其更改为:

(defun my-local-variables-hook ()
  (when (derived-mode-p 'python-mode) (my-python-hook-function)))

(add-hook 'hack-local-variables-hook #'my-local-variables-hook)