2018-05-06 03:01:37 +00:00
|
|
|
;;; core-dumper.el --- Spacemacs Core File
|
2018-03-31 04:31:52 +00:00
|
|
|
;;
|
|
|
|
;; 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'.")
|
|
|
|
|
2018-05-08 05:36:08 +00:00
|
|
|
(defvar spacemacs-dump-process nil
|
|
|
|
"The process object to dump Emacs.")
|
|
|
|
|
2018-05-08 04:58:12 +00:00
|
|
|
(defconst spacemacs-dump-directory
|
|
|
|
(concat spacemacs-cache-directory "dumps/"))
|
|
|
|
|
2018-05-08 05:36:08 +00:00
|
|
|
(defconst spacemacs-dump-buffer-name "*spacemacs-dumper*")
|
|
|
|
|
2018-06-11 05:34:08 +00:00
|
|
|
(defun spacemacs/defer (&optional idle-time)
|
|
|
|
"Return t or IDLE-TIME when Spacemacs is not running from a dump."
|
|
|
|
(when (eq 'not-dumped spacemacs-dump-mode)
|
|
|
|
(or idle-time t)))
|
2018-03-31 04:31:52 +00:00
|
|
|
|
|
|
|
(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))
|
|
|
|
|
2018-05-06 15:41:33 +00:00
|
|
|
(defun spacemacs-run-from-dump-p ()
|
|
|
|
"Return non-nil if Spacemacs is running from a dump."
|
|
|
|
(eq 'dumped spacemacs-dump-mode))
|
|
|
|
|
2018-03-31 04:31:52 +00:00
|
|
|
(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))
|
|
|
|
|
2018-05-08 04:46:32 +00:00
|
|
|
(defun spacemacs/emacs-with-pdumper-set-p ()
|
|
|
|
"Return non-nil if a portable dumper capable emacs executable is set."
|
2018-05-20 08:35:30 +00:00
|
|
|
(and dotspacemacs-enable-emacs-pdumper
|
2018-06-01 03:17:46 +00:00
|
|
|
(file-exists-p
|
2019-07-26 19:35:23 +00:00
|
|
|
(locate-file (or dotspacemacs-emacs-pdumper-executable-file "emacs")
|
2018-06-01 03:17:46 +00:00
|
|
|
exec-path exec-suffixes 'file-executable-p))))
|
2018-05-08 04:46:32 +00:00
|
|
|
|
2019-07-26 20:32:27 +00:00
|
|
|
(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)))))
|
|
|
|
|
2018-05-06 03:01:37 +00:00
|
|
|
(defun spacemacs/dump-emacs ()
|
|
|
|
"Dump emacs in a subprocess."
|
2018-05-08 05:36:08 +00:00
|
|
|
(when spacemacs-dump-process
|
|
|
|
(message "Cancel running dumping process to start a new one.")
|
2018-05-08 05:49:03 +00:00
|
|
|
(delete-process spacemacs-dump-process)
|
|
|
|
(with-current-buffer spacemacs-dump-buffer-name
|
|
|
|
(erase-buffer)))
|
2018-05-20 08:35:30 +00:00
|
|
|
(make-directory spacemacs-dump-directory t)
|
|
|
|
(setq spacemacs-dump-process
|
|
|
|
(make-process
|
|
|
|
:name "spacemacs-dumper"
|
|
|
|
:buffer spacemacs-dump-buffer-name
|
|
|
|
:command
|
|
|
|
(list dotspacemacs-emacs-pdumper-executable-file
|
|
|
|
"--batch"
|
|
|
|
"-l" "~/.emacs.d/dump-init.el"
|
|
|
|
"-eval" (concat "(dump-emacs-portable \""
|
|
|
|
(concat spacemacs-dump-directory
|
|
|
|
dotspacemacs-emacs-dumper-dump-file)
|
|
|
|
"\")")))))
|
2018-05-06 03:01:37 +00:00
|
|
|
|
2018-03-31 04:31:52 +00:00
|
|
|
;; ;; 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))))))
|
|
|
|
|
2018-05-06 03:01:37 +00:00
|
|
|
(provide 'core-dumper)
|