[core] Add pre-dump for layers and function spacemacs/dump-modes

This commit is contained in:
syl20bnr 2019-07-26 16:32:27 -04:00
parent cfd2b110f2
commit f51fc8e13b
3 changed files with 42 additions and 3 deletions

View File

@ -13,6 +13,7 @@
- [[#install-emacs][Install Emacs]]
- [[#windows-1][Windows]]
- [[#update-your-dotfile][Update your dotfile]]
- [[#add-pre-dump-function-to-layers][Add pre-dump function to layers]]
- [[#test][Test]]
- [[#report-issues][Report issues]]
- [[#usage][Usage]]
@ -201,13 +202,37 @@ Add this to your dotfile if you don't have it already.
)
#+END_SRC
This is a good place to use the function =spacemacs/dump-modes= which
all to easily load modes in a temporary buffer to trigger all the possible
side effects.
For instance to load my-mode:
#+begin_src emacs-lisp
(spacemacs/dump-modes '(my-mode))
#+end_src
*Friendly suggestions:*
- If you have a lot of personal configuration in =user-init= and =user-config=,
you can try to move them into =user-load= as this can reduce the time to load
those customized configurations.
- It is better to use =(with-temp-buffer (org-mode))= lines in =user-load=
section instead of =(require 'org)=. This will decrease load times by a lot.
Suggested by [[https://github.com/syl20bnr/spacemacs/issues/10902#issuecomment-398710755][@et2010]].
*** Add pre-dump function to layers
It is also possible to execute some lisp for each used layer by defining a
function named =<layer>/pre-dump= in the =config.el= file of the layer.
Example for the org layer:
#+begin_src emacs-lisp
;; Dumper
(defun org/pre-dump ()
(spacemacs/dump-modes '(org-mode)))
#+end_src
*Note*: In order to not generate dump files that are too big we try to use this
mechanism only when it makes a noticeable difference for all users.
*** Test
Restart Emacs. Each time Emacs starts, Spacemacs will check if the list of your

View File

@ -666,6 +666,12 @@ To prevent package from being installed or uninstalled set the variable
(configuration-layer//load-layers-files configuration-layer--used-layers
'("keybindings.el"))
(when (spacemacs-is-dumping-p)
;; dump stuff in layers
(dolist (layer-name configuration-layer--used-layers)
(let ((layer-dump-func (intern (format "%S/pre-dump" layer-name))))
(when (fboundp layer-dump-func)
(configuration-layer/message "Pre-dumping layer %S..." layer-name)
(funcall layer-dump-func))))
(dotspacemacs|call-func dotspacemacs/user-load
"Calling dotfile user-load...")))

View File

@ -65,6 +65,14 @@ You should not used this function, it is reserved for some specific process."
(locate-file (or dotspacemacs-emacs-pdumper-executable-file "emacs")
exec-path exec-suffixes 'file-executable-p))))
(defun spacemacs/dump-modes (modes)
"Load given MODES in order to be dumped."
(dolist (mode modes)
(with-temp-buffer
(when (fboundp mode)
(message "Loading mode %S..." mode)
(funcall-interactively mode)))))
(defun spacemacs/dump-emacs ()
"Dump emacs in a subprocess."
(when spacemacs-dump-process