Add support for dumping Spacemacs

Create dump with:

   ./emacs --batch -l ~/.emacs.d/dump-init.el \
           -eval '(dump-emacs-portable "spacemacs.pdmp")'

Load dump with:

   ./emacs --dump-file=spacemacs.pdmp

User can require/load additional libraries in new dotfile function:

   dotspacemacs/user-load
This commit is contained in:
syl20bnr 2018-03-31 00:31:52 -04:00
parent a14060a228
commit 2580e43c66
8 changed files with 146 additions and 63 deletions

View File

@ -555,55 +555,57 @@ To prevent package from being installed or uninstalled set the variable
`spacemacs-sync-packages' to nil." `spacemacs-sync-packages' to nil."
(run-hooks 'configuration-layer-pre-load-hook) (run-hooks 'configuration-layer-pre-load-hook)
(dotspacemacs|call-func dotspacemacs/layers "Calling dotfile layers...") (dotspacemacs|call-func dotspacemacs/layers "Calling dotfile layers...")
(setq dotspacemacs--configuration-layers-saved (spacemacs|when-dumping
dotspacemacs-configuration-layers) (setq dotspacemacs--configuration-layers-saved
(when (spacemacs-buffer//choose-banner) dotspacemacs-configuration-layers)
(spacemacs-buffer//inject-version)) (when (spacemacs-buffer//choose-banner)
;; declare used layers then packages as soon as possible to resolve (spacemacs-buffer//inject-version))
;; usage and ownership ;; declare used layers then packages as soon as possible to resolve
(configuration-layer/discover-layers 'refresh-index) ;; usage and ownership
(configuration-layer//declare-used-layers dotspacemacs-configuration-layers) (configuration-layer/discover-layers 'refresh-index)
(configuration-layer//declare-used-packages configuration-layer--used-layers) (configuration-layer//declare-used-layers dotspacemacs-configuration-layers)
;; then load the functions and finally configure the layers (configuration-layer//declare-used-packages configuration-layer--used-layers)
(configuration-layer//load-layers-files configuration-layer--used-layers ;; then load the functions and finally configure the layers
'("funcs.el")) (configuration-layer//load-layers-files configuration-layer--used-layers
(configuration-layer//configure-layers configuration-layer--used-layers) '("funcs.el"))
;; load layers lazy settings (configuration-layer//configure-layers configuration-layer--used-layers)
(configuration-layer/load-auto-layer-file) ;; load layers lazy settings
;; install and/or uninstall packages (configuration-layer/load-auto-layer-file)
(when spacemacs-sync-packages ;; install and/or uninstall packages
(let ((packages (when spacemacs-sync-packages
(append (let ((packages
;; install used packages (append
(configuration-layer//filter-distant-packages ;; install used packages
configuration-layer--used-packages t (configuration-layer//filter-distant-packages
'(not (oref pkg :lazy-install))) configuration-layer--used-packages t
;; also install all other packages if requested '(not (oref pkg :lazy-install)))
(when (eq 'all dotspacemacs-install-packages) ;; also install all other packages if requested
(let (all-other-packages) (when (eq 'all dotspacemacs-install-packages)
(dolist (layer (configuration-layer/get-layers-list)) (let (all-other-packages)
(let ((configuration-layer--declared-layers-usedp nil) (dolist (layer (configuration-layer/get-layers-list))
(configuration-layer--load-packages-files t)) (let ((configuration-layer--declared-layers-usedp nil)
(configuration-layer/declare-layer layer) (configuration-layer--load-packages-files t))
(let* ((obj (configuration-layer/get-layer layer)) (configuration-layer/declare-layer layer)
(pkgs (when obj (oref obj :packages)))) (let* ((obj (configuration-layer/get-layer layer))
(configuration-layer/make-packages-from-layers (pkgs (when obj (oref obj :packages))))
(list layer)) (configuration-layer/make-packages-from-layers
(dolist (pkg pkgs) (list layer))
(let ((pkg-name (if (listp pkg) (car pkg) pkg))) (dolist (pkg pkgs)
(add-to-list 'all-other-packages pkg-name)))))) (let ((pkg-name (if (listp pkg) (car pkg) pkg)))
(configuration-layer//filter-distant-packages (add-to-list 'all-other-packages pkg-name))))))
all-other-packages nil)))))) (configuration-layer//filter-distant-packages
(configuration-layer//install-packages packages) all-other-packages nil))))))
(when (and (or (eq 'used dotspacemacs-install-packages) (configuration-layer//install-packages packages)
(eq 'used-only dotspacemacs-install-packages)) (when (and (or (eq 'used dotspacemacs-install-packages)
(not configuration-layer-force-distribution) (eq 'used-only dotspacemacs-install-packages))
(not configuration-layer-exclude-all-layers)) (not configuration-layer-force-distribution)
(configuration-layer/delete-orphan-packages packages)))) (not configuration-layer-exclude-all-layers))
;; configure used packages (configuration-layer/delete-orphan-packages packages))))
(configuration-layer//configure-packages configuration-layer--used-packages) ;; configure used packages
(configuration-layer//load-layers-files configuration-layer--used-layers (configuration-layer//configure-packages configuration-layer--used-packages)
'("keybindings.el")) (configuration-layer//load-layers-files configuration-layer--used-layers
'("keybindings.el"))
(dotspacemacs|call-func dotspacemacs/user-load "Calling dotfile user-load..."))
(run-hooks 'configuration-layer-post-load-hook)) (run-hooks 'configuration-layer-post-load-hook))
(defun configuration-layer/load-auto-layer-file () (defun configuration-layer/load-auto-layer-file ()

59
core/core-dump.el Normal file
View File

@ -0,0 +1,59 @@
;;; core-dump.el --- Spacemacs Core File
;;
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(defvar spacemacs-dump-mode 'not-dumped
"Spacemacs dump mode, can be `not-dumped', `dumped' or `dumping'.")
(defun spacemacs/defer ()
"Return non-nil if dump is not supported."
(eq 'not-dumped spacemacs-dump-mode))
(defmacro spacemacs|require (&rest args)
"Require feature if dumping."
(spacemacs|when-dumping-strict `(require ,@args)))
(defun spacemacs-is-dumping-p ()
"Return non-nil if Spacemacs is dumping."
(eq 'dumping spacemacs-dump-mode))
(defmacro spacemacs|when-dumping (&rest body)
"Execute body if dumping.
This function considers that we are always dumping if dumping is not supported.
You should always use this function."
(declare (indent defun))
`(when (not (eq 'dumped spacemacs-dump-mode))
,@body))
(defmacro spacemacs|when-dumping-strict (&rest body)
"Execute body if we are really dumping.
You should not used this function, it is reserved for some specific process."
(declare (indent defun))
`(when (eq 'dumping spacemacs-dump-mode)
,@body))
(defmacro spacemacs|unless-dumping (&rest body)
"Execute body if not dumping"
(declare (indent defun))
`(unless (eq 'dumping spacemacs-dump-mode)
,@body))
;; ;; Brute-force load all .el files in ELPA packages
;; (dolist (d (directory-files package-user-dir t nil 'nosort))
;; (unless (or (string-equal ".." (substring d -2))
;; (string-equal "." (substring d -1))
;; (not (file-directory-p d)))
;; (message "%s" d)
;; (dolist (f (directory-files d t "\\.el$" 'nosort))
;; (unless (string-match-p ".*pkg\\.el$" f)
;; (message "%s" f)
;; (ignore-errors (load f t))))))
(provide 'core-dump)

View File

@ -9,9 +9,9 @@
;; ;;
;;; License: GPLv3 ;;; License: GPLv3
(setq message-log-max 16384) (setq message-log-max 16384)
(defconst emacs-start-time (current-time))
(require 'subr-x nil 'noerror) (require 'subr-x nil 'noerror)
(require 'core-dump)
(require 'core-emacs-backports) (require 'core-emacs-backports)
(require 'page-break-lines) (require 'page-break-lines)
(require 'core-debug) (require 'core-debug)
@ -86,7 +86,8 @@ the final step of executing code in `emacs-startup-hook'.")
(unless (frame-parameter nil 'fullscreen) (unless (frame-parameter nil 'fullscreen)
(toggle-frame-maximized)) (toggle-frame-maximized))
(add-to-list 'default-frame-alist '(fullscreen . maximized))) (add-to-list 'default-frame-alist '(fullscreen . maximized)))
(dotspacemacs|call-func dotspacemacs/user-init "Calling dotfile user init...") (spacemacs|unless-dumping
(dotspacemacs|call-func dotspacemacs/user-init "Calling dotfile user init..."))
;; Given the loading process of Spacemacs we have no choice but to set the ;; Given the loading process of Spacemacs we have no choice but to set the
;; custom settings twice: ;; custom settings twice:
;; - once at the very beginning of startup (here) ;; - once at the very beginning of startup (here)
@ -202,7 +203,8 @@ defer call using `spacemacs-post-user-config-hook'."
(add-hook 'spacemacs-post-user-config-hook func))) (add-hook 'spacemacs-post-user-config-hook func)))
(defun spacemacs/setup-startup-hook () (defun spacemacs/setup-startup-hook ()
"Add post init processing." "Add post init processing.
Note: the hooked function is not executed when in dumped mode."
(add-hook (add-hook
'emacs-startup-hook 'emacs-startup-hook
(defun spacemacs/startup-hook () (defun spacemacs/startup-hook ()
@ -214,9 +216,9 @@ defer call using `spacemacs-post-user-config-hook'."
;; Ultimate configuration decisions are given to the user who can defined ;; Ultimate configuration decisions are given to the user who can defined
;; them in his/her ~/.spacemacs file ;; them in his/her ~/.spacemacs file
(dotspacemacs|call-func dotspacemacs/user-config (dotspacemacs|call-func dotspacemacs/user-config
"Calling dotfile user config...") "Calling dotfile user config...")
(dotspacemacs|call-func dotspacemacs/emacs-custom-settings (dotspacemacs|call-func dotspacemacs/emacs-custom-settings
"Calling dotfile Emacs custom settings...") "Calling dotfile Emacs custom settings...")
(run-hooks 'spacemacs-post-user-config-hook) (run-hooks 'spacemacs-post-user-config-hook)
(setq spacemacs-post-user-config-hook-run t) (setq spacemacs-post-user-config-hook-run t)
(when (fboundp dotspacemacs-scratch-mode) (when (fboundp dotspacemacs-scratch-mode)

View File

@ -10,4 +10,4 @@
;;; License: GPLv3 ;;; License: GPLv3
(defconst spacemacs-version "0.300.0" "Spacemacs version.") (defconst spacemacs-version "0.300.0" "Spacemacs version.")
(defconst spacemacs-emacs-min-version "25.1" "Minimal version of Emacs.") (defconst spacemacs-emacs-min-version "27.0" "Minimal version of Emacs.")

View File

@ -436,6 +436,13 @@ It is mostly for variables that should be set before packages are loaded.
If you are unsure, try setting them in `dotspacemacs/user-config' first." If you are unsure, try setting them in `dotspacemacs/user-config' first."
) )
(defun dotspacemacs/user-load ()
"Library to load while dumping.
This function is called while dumping Spacemacs configuration. You can
`require' or `load' the libraries of your choice that will be included
in the dump."
)
(defun dotspacemacs/user-config () (defun dotspacemacs/user-config ()
"Configuration for user code: "Configuration for user code:
This function is called at the very end of Spacemacs startup, after layer This function is called at the very end of Spacemacs startup, after layer

2
dump-init.el Normal file
View File

@ -0,0 +1,2 @@
(setq spacemacs-dump-mode 'dumping)
(load (concat (file-name-directory load-file-name) "init.el"))

19
init.el
View File

@ -14,6 +14,7 @@
;; Avoid garbage collection during startup. ;; Avoid garbage collection during startup.
;; see `SPC h . dotspacemacs-gc-cons' for more info ;; see `SPC h . dotspacemacs-gc-cons' for more info
(defconst emacs-start-time (current-time))
(setq gc-cons-threshold 402653184 gc-cons-percentage 0.6) (setq gc-cons-threshold 402653184 gc-cons-percentage 0.6)
(load-file (concat (file-name-directory load-file-name) (load-file (concat (file-name-directory load-file-name)
"core/core-versions.el")) "core/core-versions.el"))
@ -27,12 +28,24 @@
;; Disable file-name-handlers for a speed boost during init ;; Disable file-name-handlers for a speed boost during init
(let ((file-name-handler-alist nil)) (let ((file-name-handler-alist nil))
(require 'core-spacemacs) (require 'core-spacemacs)
(spacemacs|unless-dumping
(when (boundp 'load-path-backup)
(setq load-path load-path-backup)))
(configuration-layer/load-lock-file) (configuration-layer/load-lock-file)
(spacemacs/init) (spacemacs/init)
(configuration-layer/stable-elpa-download-tarball) (configuration-layer/stable-elpa-download-tarball)
(configuration-layer/load) (configuration-layer/load)
(spacemacs-buffer/display-startup-note) (spacemacs-buffer/display-startup-note)
(spacemacs/setup-startup-hook) (spacemacs/setup-startup-hook)
(when dotspacemacs-enable-server (spacemacs|unless-dumping
(require 'server) (global-font-lock-mode)
(unless (server-running-p) (server-start))))) (global-undo-tree-mode 1))
;; (when dotspacemacs-enable-server
;; (require 'server)
;; (unless (server-running-p) (server-start)))
(spacemacs|when-dumping-strict
(setq load-path-backup load-path)
;; disable undo-tree to prevent from segfaulting when loading the dump
(global-undo-tree-mode -1)
(setq spacemacs-dump-mode 'dumped)
(garbage-collect))))

View File

@ -400,11 +400,9 @@
(defun spacemacs-editing/init-undo-tree () (defun spacemacs-editing/init-undo-tree ()
(use-package undo-tree (use-package undo-tree
:init :defer t
(progn :init (setq undo-tree-visualizer-timestamps t
(global-undo-tree-mode) undo-tree-visualizer-diff t)
(setq undo-tree-visualizer-timestamps t
undo-tree-visualizer-diff t))
:config :config
(progn (progn
;; restore diff window after quit. TODO fix upstream ;; restore diff window after quit. TODO fix upstream