When will the functions held by a hook be run in emacs?

Han*_*Sun 3 emacs hook elisp

For example, I put some codes within python-mode-hook, and the codes will be run when:

(1) Every time I open a python file *.py

(2) Only the first time that python-mode was triggered

Does anyone have ideas that which answer is right?

Thanks!

Dal*_*und 6

关于何时运行钩子没有一般规则:这仅由定义钩子的代码控制.但是,遵循的一般惯例是:

  • 如果foo-mode是某种主要模式,那么foo-mode-hook每次都会foo-mode在缓冲区中启用.

特别是,正如已经指出的那样,python-mode-hook每次.py加载文件时都会运行这些函数.