Spacemacs ConfigurationLayers 文档: http://spacemacs.org/doc/LAYERS.html#case-study-auto-completion
里面第五点讲解了Spacemacs 加载过程,里面有这段话:
“Spacemacs goes through all the enabled layers and evaluates their files. The changes introduced by config.el are thus applied, then funcs.el and packages.el are loaded, but nothing happens from packages.el, since these files only define functions and variables.”
这句话意思是 config.el 先于 funcs.el 和 packages.el 加载?并且后面说 packages.el 只是定义了一些函数和变量。
这个过程与上面介绍的 Layer 的组成不一样? 另外我打开了 spacemacs 的 message 看了下 load 过程,基本是这样的过程 packages.el → funcs.el → config.el 。与文档中这段话不符,求大神解释。是不是我理解错了?
你可以在一个 layer 的 config.el 和 packages.el 里面用 message 去打印日志,看看 eval 的顺序是什么。
message buffer 里面显示的应该是加载文件的顺序,但是不等于 eval 的顺序。而文档说的是顺序 config.el -> funcs.el -> packages.el 应该是指 eval 的顺序。
在每个文件第一行加了 message 日志后 eval 的顺序,我贴一下大神看一下,跟loading file 的过程一致:
Loading /Users/Baitianyu/.spacemacs.d/baitianyu/packages.el (source)…
Evaluate baitianyu/packages.el
Loading /Users/Baitianyu/.spacemacs.d/baitianyu/packages.el (source)…done
Loading /Users/Baitianyu/.spacemacs.d/baitianyu/layers.el (source)…
Evaluate baitianyu/layers.el
Loading /Users/Baitianyu/.spacemacs.d/baitianyu/layers.el (source)…done
Loading /Users/Baitianyu/.spacemacs.d/baitianyu/funcs.el (source)…
Evaluate baitianyu/funcs.el
Loading /Users/Baitianyu/.spacemacs.d/baitianyu/funcs.el (source)…done
Loading /Users/Baitianyu/.spacemacs.d/baitianyu/config.el (source)…
Evaluate baitianyu/config
Loading /Users/Baitianyu/.spacemacs.d/baitianyu/config.el (source)…done
Loading /Users/Baitianyu/.spacemacs.d/baitianyu/keybindings.el (source)…
Evaluate baitianyu/keybindings.el
Loading /Users/Baitianyu/.spacemacs.d/baitianyu/keybindings.el (source)…done
这个顺序跟 Configuration layer 文档里介绍 Layer 的文件那一部分讲到的一致,但是跟第五部分讲的加载过程不太一样…
这个估计要看源码了,因为 elisp 是可以重复 eval 的,可能加载完后,又按照文档说的顺序执行了一遍也说不准。
你可以就这个问题去提 issue 跟作者讨论一下。
不过,应该不是重新执行了一遍,因为message日志里只有一遍过程.
message 只过一遍,但是其它地方还是可以调用里面的函数啊。我指的 eval 是调用。
额.好吧,我理解的 eval 是执行符号表达式,不是函数调用。
去 spacemacs 提了 documentation 的 issue,这个是给的答案,之前的文档有错误。
opened 06:52AM - 12 Jan 17 UTC
closed 02:25AM - 16 Jan 17 UTC
Documentation ✏
- Bug tracker -
Hi,
I have som questiones about the [Spacemacs Configuration Layers](http://s… pacemacs.org/doc/LAYERS.html#case-study-auto-completion3) document:
1. A questione about loading process of spacemacs.
In the [Spacemacs Configuration Layers](http://spacemacs.org/doc/LAYERS.html#case-study-auto-completion3), section 5 said: "Spacemacs goes through all the enabled layers and evaluates their files. The changes introduced by config.el are thus applied, then funcs.el and packages.el are loaded, but nothing happens from packages.el, since these files only define functions and variables."
I think it's talking some thing that config.el has high priority than funcs.el and packages.el, it means that the layer's loading process is : config.el > funcs.el > packages.el?
But in section4 of the upper document , the priority of the layers' files is not like this. And I have a try to observe the loading and evaluate process in my layer, the result as follows:
Loading /Users/Baitianyu/.spacemacs.d/baitianyu/packages.el (source)...
Evaluate baitianyu/packages.el
Loading /Users/Baitianyu/.spacemacs.d/baitianyu/packages.el (source)...done
Loading /Users/Baitianyu/.spacemacs.d/baitianyu/layers.el (source)...
Evaluate baitianyu/layers.el
Loading /Users/Baitianyu/.spacemacs.d/baitianyu/layers.el (source)...done
Loading /Users/Baitianyu/.spacemacs.d/baitianyu/funcs.el (source)...
Evaluate baitianyu/funcs.el
Loading /Users/Baitianyu/.spacemacs.d/baitianyu/funcs.el (source)...done
Loading /Users/Baitianyu/.spacemacs.d/baitianyu/config.el (source)...
Evaluate baitianyu/config
Loading /Users/Baitianyu/.spacemacs.d/baitianyu/config.el (source)...done
Loading /Users/Baitianyu/.spacemacs.d/baitianyu/keybindings.el (source)...
Evaluate baitianyu/keybindings.el
Loading /Users/Baitianyu/.spacemacs.d/baitianyu/keybindings.el (source)...done
This shows the process is in accordance with section 4, but inverse with section 5. What I want to know is whether I have some mistakes in understanding or there's some error in the document?
2. Question about Cross-dependencies statements:
Section 7.1 says "For layers that require another layers to be enabled, use the functions configuration-layer/declare-layer and configuration-layer/declare-layers to ensure that layers are enabled even if the user has not enabled them explicitly. Calls to these functions must go in the config.el file."
The "funtions" in last sentence means which function?
Function "configuration-layer/declare-layer" and "configuration-layer/declare-layers" should be in the layer.el, right? So does function "configuration-layer/package-usedp" must go in the config.el?
5 个赞