2015-01-27 03:51:47 +00:00
|
|
|
;;; core-configuration-layer.el --- Spacemacs Core File
|
2015-01-14 04:12:56 +00:00
|
|
|
;;
|
|
|
|
;; Copyright (c) 2012-2014 Sylvain Benner
|
|
|
|
;; Copyright (c) 2014-2015 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
|
2015-08-06 03:39:39 +00:00
|
|
|
;;
|
|
|
|
;;; Commentary:
|
|
|
|
;;
|
|
|
|
;;; Code:
|
|
|
|
|
2015-08-29 07:09:13 +00:00
|
|
|
(require 'cl-lib)
|
2015-07-26 04:41:41 +00:00
|
|
|
(require 'eieio)
|
2015-01-05 05:20:38 +00:00
|
|
|
(require 'package)
|
2015-09-29 06:05:36 +00:00
|
|
|
(require 'warnings)
|
2015-08-06 03:39:39 +00:00
|
|
|
(require 'ht)
|
2015-12-03 04:25:00 +00:00
|
|
|
(require 'request)
|
2015-01-27 03:51:47 +00:00
|
|
|
(require 'core-dotspacemacs)
|
|
|
|
(require 'core-funcs)
|
|
|
|
(require 'core-spacemacs-buffer)
|
2015-01-05 05:20:38 +00:00
|
|
|
|
2015-12-03 04:25:00 +00:00
|
|
|
(defconst configuration-layer--refresh-package-timeout 3
|
|
|
|
"Timeout in seconds to reach a package archive page.")
|
2015-07-26 04:41:41 +00:00
|
|
|
|
2014-12-25 20:24:26 +00:00
|
|
|
(defconst configuration-layer-template-directory
|
|
|
|
(expand-file-name (concat spacemacs-core-directory "templates/"))
|
|
|
|
"Configuration layer templates directory.")
|
|
|
|
|
2015-09-08 01:16:15 +00:00
|
|
|
(defconst configuration-layer-directory
|
|
|
|
(expand-file-name (concat user-emacs-directory "layers/"))
|
2014-11-22 02:55:00 +00:00
|
|
|
"Spacemacs contribution layers base directory.")
|
2014-10-24 03:11:36 +00:00
|
|
|
|
2014-12-25 19:45:27 +00:00
|
|
|
(defconst configuration-layer-private-directory
|
2014-11-22 03:06:04 +00:00
|
|
|
(expand-file-name (concat user-emacs-directory "private/"))
|
|
|
|
"Spacemacs private layers base directory.")
|
|
|
|
|
2015-06-05 23:50:03 +00:00
|
|
|
(defconst configuration-layer-private-layer-directory
|
|
|
|
(let ((dotspacemacs-layer-dir
|
|
|
|
(when dotspacemacs-directory
|
|
|
|
(expand-file-name
|
|
|
|
(concat dotspacemacs-directory "layers/")))))
|
|
|
|
(if (and dotspacemacs-directory
|
|
|
|
(file-exists-p dotspacemacs-layer-dir))
|
|
|
|
dotspacemacs-layer-dir
|
|
|
|
configuration-layer-private-directory))
|
|
|
|
"Spacemacs default directory for private layers.")
|
|
|
|
|
2015-02-04 04:56:38 +00:00
|
|
|
(defconst configuration-layer-rollback-directory
|
|
|
|
(expand-file-name (concat spacemacs-cache-directory ".rollback/"))
|
|
|
|
"Spacemacs rollback directory.")
|
|
|
|
|
|
|
|
(defconst configuration-layer-rollback-info "rollback-info"
|
|
|
|
"Spacemacs rollback information file.")
|
|
|
|
|
2015-08-06 03:39:39 +00:00
|
|
|
(defclass cfgl-layer ()
|
|
|
|
((name :initarg :name
|
|
|
|
:type symbol
|
|
|
|
:documentation "Name of the layer.")
|
|
|
|
(dir :initarg :dir
|
|
|
|
:type string
|
|
|
|
:documentation "Absolute path to the layer directory.")
|
|
|
|
(variables :initarg :variables
|
|
|
|
:initform nil
|
|
|
|
:type list
|
2015-09-03 03:01:26 +00:00
|
|
|
:documentation "A list of variable-value pairs.")
|
|
|
|
(disabled :initarg :disabled-for
|
|
|
|
:initform nil
|
|
|
|
:type list
|
|
|
|
:documentation "A list of layer where this layer is disabled."))
|
2015-08-06 03:39:39 +00:00
|
|
|
"A configuration layer.")
|
|
|
|
|
|
|
|
(defclass cfgl-package ()
|
|
|
|
((name :initarg :name
|
|
|
|
:type symbol
|
|
|
|
:documentation "Name of the package.")
|
|
|
|
(owner :initarg :owner
|
|
|
|
:initform nil
|
|
|
|
:type symbol
|
|
|
|
:documentation "The layer defining the init function.")
|
|
|
|
(pre-layers :initarg :pre-layers
|
|
|
|
:initform '()
|
|
|
|
:type list
|
|
|
|
:documentation "Layers with a pre-init function.")
|
|
|
|
(post-layers :initarg :post-layers
|
|
|
|
:initform '()
|
|
|
|
:type list
|
|
|
|
:documentation "Layers with a post-init function.")
|
|
|
|
(location :initarg :location
|
|
|
|
:initform elpa
|
2015-08-14 19:31:22 +00:00
|
|
|
:type (satisfies (lambda (x)
|
2015-10-23 02:39:53 +00:00
|
|
|
(or (stringp x)
|
2015-10-22 19:29:40 +00:00
|
|
|
(member x '(built-in local elpa))
|
2015-08-14 19:31:22 +00:00
|
|
|
(and (listp x) (eq 'recipe (car x))))))
|
2015-08-06 03:39:39 +00:00
|
|
|
:documentation "Location of the package.")
|
|
|
|
(step :initarg :step
|
|
|
|
:initform nil
|
2015-09-24 04:02:02 +00:00
|
|
|
:type (satisfies (lambda (x) (member x '(nil pre))))
|
2015-08-06 03:39:39 +00:00
|
|
|
:documentation "Initialization step.")
|
2015-11-19 05:53:57 +00:00
|
|
|
(protected :initarg :protected
|
|
|
|
:initform nil
|
|
|
|
:type boolean
|
|
|
|
:documentation
|
|
|
|
"If non-nil then this package cannot be excluded.")
|
2015-08-06 03:39:39 +00:00
|
|
|
(excluded :initarg :excluded
|
|
|
|
:initform nil
|
|
|
|
:type boolean
|
2015-09-03 03:01:26 +00:00
|
|
|
:documentation
|
|
|
|
"If non-nil this package is excluded from all layers.")))
|
2015-08-06 03:39:39 +00:00
|
|
|
|
2015-12-03 04:25:00 +00:00
|
|
|
(defvar configuration-layer--elpa-archives
|
|
|
|
'(("melpa" . "melpa.org/packages/")
|
|
|
|
("org" . "orgmode.org/elpa/")
|
|
|
|
("gnu" . "elpa.gnu.org/packages/"))
|
|
|
|
"List of ELPA archives required by Spacemacs.")
|
|
|
|
|
2015-12-03 04:49:00 +00:00
|
|
|
(defvar configuration-layer--package-archives-refreshed nil
|
|
|
|
"Non nil if package archives have already been refreshed.")
|
|
|
|
|
2015-08-26 02:52:26 +00:00
|
|
|
(defvar configuration-layer--layers '()
|
2015-08-08 02:51:27 +00:00
|
|
|
"A non-sorted list of `cfgl-layer' objects.")
|
2015-08-06 03:39:39 +00:00
|
|
|
|
2015-08-26 02:52:26 +00:00
|
|
|
(defvar configuration-layer--packages '()
|
2015-08-08 02:51:27 +00:00
|
|
|
"An alphabetically sorted list of `cfgl-package' objects.")
|
2015-08-06 03:39:39 +00:00
|
|
|
|
2015-08-26 02:52:26 +00:00
|
|
|
(defvar configuration-layer--used-distant-packages '()
|
|
|
|
"A list of all distant packages that are effectively used.")
|
|
|
|
|
2015-08-29 07:09:13 +00:00
|
|
|
(defvar configuration-layer--skipped-packages nil
|
|
|
|
"A list of all packages that were skipped during last update attempt.")
|
|
|
|
|
2015-11-04 13:21:36 +00:00
|
|
|
(defvar configuration-layer--protected-packages nil
|
|
|
|
"A list of packages that will be protected from removal as orphans.")
|
|
|
|
|
2015-03-16 05:28:21 +00:00
|
|
|
(defvar configuration-layer-error-count nil
|
|
|
|
"Non nil indicates the number of errors occurred during the
|
|
|
|
installation of initialization.")
|
|
|
|
|
2015-04-03 21:12:56 +00:00
|
|
|
(defvar configuration-layer-paths (make-hash-table :size 256)
|
2014-12-20 20:08:02 +00:00
|
|
|
"Hash table of layers locations. The key is a layer symbol and the value is
|
|
|
|
the path for this layer.")
|
2014-10-24 03:11:36 +00:00
|
|
|
|
2015-06-06 02:47:23 +00:00
|
|
|
(defvar configuration-layer-categories '()
|
|
|
|
"List of strings corresponding to category names. A category is a
|
2015-09-11 00:21:27 +00:00
|
|
|
directory with a name starting with `+'.")
|
2014-11-11 03:26:11 +00:00
|
|
|
|
2015-12-03 04:25:00 +00:00
|
|
|
(defun configuration-layer/initialize ()
|
|
|
|
"Initialize `package.el'."
|
|
|
|
(unless package--initialized
|
|
|
|
(setq package-archives (configuration-layer//resolve-package-archives
|
|
|
|
configuration-layer--elpa-archives))
|
|
|
|
;; optimization, no need to activate all the packages so early
|
|
|
|
(setq package-enable-at-startup nil)
|
|
|
|
(package-initialize 'noactivate)
|
|
|
|
;; TODO remove the following hack when 24.3 support ends
|
|
|
|
;; Emacs 24.3 and above ships with python.el but in some Emacs 24.3.1
|
|
|
|
;; packages for Ubuntu, python.el seems to be missing.
|
|
|
|
;; This hack adds marmalade repository for this case only.
|
|
|
|
(unless (or (package-installed-p 'python) (version< emacs-version "24.3"))
|
|
|
|
(add-to-list 'package-archives
|
|
|
|
'("marmalade" . "https://marmalade-repo.org/packages/")))))
|
|
|
|
|
|
|
|
(defun configuration-layer//resolve-package-archives (archives)
|
|
|
|
"Resolve HTTP handlers for each archive in ARCHIVES and return a list
|
|
|
|
of all reachable ones.
|
|
|
|
If the address of an archive already contains the protocol then this address is
|
|
|
|
left untouched.
|
|
|
|
The returned list has a `package-archives' compliant format."
|
|
|
|
(mapcar
|
|
|
|
(lambda (x)
|
|
|
|
(cons (car x)
|
|
|
|
(if (string-match-p "http" (cdr x))
|
|
|
|
(cdr x)
|
|
|
|
(concat (if (and dotspacemacs-elpa-https
|
|
|
|
;; for now org ELPA repository does
|
|
|
|
;; not support HTTPS
|
|
|
|
;; TODO when org ELPA repo support
|
|
|
|
;; HTTPS remove the check
|
|
|
|
;; `(not (equal "org" (car x)))'
|
|
|
|
(not (equal "org" (car x))))
|
|
|
|
"https://"
|
|
|
|
"http://") (cdr x)))))
|
|
|
|
archives))
|
|
|
|
|
2015-12-03 04:49:00 +00:00
|
|
|
(defun configuration-layer/retrieve-package-archives (&optional quiet force)
|
2015-12-03 04:25:00 +00:00
|
|
|
"Retrieve all archives declared in current `package-archives'.
|
2015-12-03 04:49:00 +00:00
|
|
|
|
2015-12-03 04:25:00 +00:00
|
|
|
This function first performs a simple GET request with a timeout in order to
|
|
|
|
fix very long refresh time when an archive is not reachable.
|
2015-12-03 04:49:00 +00:00
|
|
|
|
2015-12-03 04:25:00 +00:00
|
|
|
Note that this simple GET is a heuristic to determine the availability
|
|
|
|
likelihood of an archive, so it can gives false positive if the archive
|
2015-12-03 04:49:00 +00:00
|
|
|
page is served but the archive is not.
|
|
|
|
|
|
|
|
If QUIET is non nil then the function does not print message in the Spacemacs
|
|
|
|
home buffer.
|
|
|
|
|
|
|
|
If FORCE is non nil then refresh the archives even if they have been already
|
|
|
|
refreshed during the current session."
|
|
|
|
(unless (and configuration-layer--package-archives-refreshed
|
|
|
|
(not force))
|
|
|
|
(setq configuration-layer--package-archives-refreshed t)
|
|
|
|
(let ((count (length package-archives))
|
|
|
|
(i 1))
|
|
|
|
(dolist (archive package-archives)
|
|
|
|
(unless quiet
|
|
|
|
(spacemacs-buffer/replace-last-line
|
|
|
|
(format "--> refreshing package archive: %s... [%s/%s]"
|
|
|
|
(car archive) i count) t))
|
|
|
|
(spacemacs//redisplay)
|
|
|
|
(setq i (1+ i))
|
|
|
|
(request (cdr archive) :sync t :type "GET"
|
|
|
|
:timeout configuration-layer--refresh-package-timeout
|
|
|
|
:error
|
|
|
|
(function* (lambda (&key error-thrown &allow-other-keys)
|
|
|
|
(configuration-layer//set-error)
|
|
|
|
(spacemacs-buffer/append
|
|
|
|
(format "\n%s: %s"
|
|
|
|
(car error-thrown)
|
|
|
|
(cdr error-thrown)))))
|
|
|
|
:status-code
|
|
|
|
'((200 . (lambda (&rest _)
|
|
|
|
(let ((package-archives (list archive)))
|
|
|
|
(package-refresh-contents)))))))
|
|
|
|
(package-read-all-archive-contents)
|
|
|
|
(unless quiet (spacemacs-buffer/append "\n")))))
|
2015-12-03 04:25:00 +00:00
|
|
|
|
2015-03-02 03:12:09 +00:00
|
|
|
(defun configuration-layer/sync ()
|
|
|
|
"Synchronize declared layers in dotfile with spacemacs."
|
|
|
|
(dotspacemacs|call-func dotspacemacs/layers "Calling dotfile layers...")
|
2015-09-13 06:32:17 +00:00
|
|
|
(when (spacemacs-buffer//choose-banner)
|
|
|
|
(spacemacs-buffer//inject-version t))
|
2015-08-26 02:27:31 +00:00
|
|
|
;; layers
|
2015-08-26 02:52:26 +00:00
|
|
|
(setq configuration-layer--layers (configuration-layer//declare-layers))
|
|
|
|
(configuration-layer//configure-layers configuration-layer--layers)
|
2015-08-26 02:27:31 +00:00
|
|
|
;; packages
|
2015-08-26 02:52:26 +00:00
|
|
|
(setq configuration-layer--packages (configuration-layer//declare-packages
|
|
|
|
configuration-layer--layers))
|
|
|
|
(setq configuration-layer--used-distant-packages
|
|
|
|
(configuration-layer//get-distant-used-packages
|
|
|
|
configuration-layer--packages))
|
2015-08-26 06:41:54 +00:00
|
|
|
(configuration-layer//load-packages configuration-layer--packages)
|
2015-03-02 03:12:09 +00:00
|
|
|
(when dotspacemacs-delete-orphan-packages
|
2015-08-26 02:52:26 +00:00
|
|
|
(configuration-layer/delete-orphan-packages configuration-layer--packages)))
|
2015-03-02 03:12:09 +00:00
|
|
|
|
2015-05-18 15:43:27 +00:00
|
|
|
(defun configuration-layer/create-layer ()
|
|
|
|
"Ask the user for a configuration layer name and the layer
|
|
|
|
directory to use. Create a layer with this name in the selected
|
|
|
|
layer directory."
|
|
|
|
(interactive)
|
|
|
|
(let* ((current-layer-paths (mapcar (lambda (dir) (expand-file-name dir))
|
|
|
|
(cl-pushnew
|
2015-06-05 23:50:03 +00:00
|
|
|
configuration-layer-private-layer-directory
|
2015-05-18 15:43:27 +00:00
|
|
|
dotspacemacs-configuration-layer-path)))
|
|
|
|
(other-choice "Another directory...")
|
|
|
|
(helm-lp-source
|
|
|
|
`((name . "Configuration Layer Paths")
|
|
|
|
(candidates . ,(append current-layer-paths
|
|
|
|
(list other-choice)))
|
|
|
|
(action . (lambda (c) c))))
|
|
|
|
(layer-path-sel (helm :sources helm-lp-source
|
|
|
|
:prompt "Configuration layer path: "))
|
|
|
|
(layer-path (cond
|
|
|
|
((string-equal layer-path-sel other-choice)
|
2015-08-06 03:39:39 +00:00
|
|
|
(read-directory-name (concat "Other configuration "
|
|
|
|
"layer path: ") "~/" ))
|
2015-05-18 15:43:27 +00:00
|
|
|
((member layer-path-sel current-layer-paths)
|
|
|
|
layer-path-sel)
|
|
|
|
(t
|
|
|
|
(error "Please select an option from the list"))))
|
|
|
|
(name (read-from-minibuffer "Configuration layer name: " ))
|
|
|
|
(layer-dir (concat layer-path "/" name)))
|
2014-11-22 05:08:44 +00:00
|
|
|
(cond
|
|
|
|
((string-equal "" name)
|
|
|
|
(message "Cannot create a configuration layer without a name."))
|
|
|
|
((file-exists-p layer-dir)
|
2015-08-06 03:39:39 +00:00
|
|
|
(message (concat "Cannot create configuration layer \"%s\", "
|
|
|
|
"this layer already exists.") name))
|
2014-11-22 05:08:44 +00:00
|
|
|
(t
|
2015-05-18 15:43:27 +00:00
|
|
|
(make-directory layer-dir t)
|
2015-11-16 13:13:06 +00:00
|
|
|
(configuration-layer//copy-template name "extensions.el" layer-dir)
|
|
|
|
(configuration-layer//copy-template name "packages.el" layer-dir)
|
|
|
|
(configuration-layer//copy-template name "README.org" layer-dir)
|
2015-05-18 15:43:27 +00:00
|
|
|
(message "Configuration layer \"%s\" successfully created." name)))))
|
2014-11-22 05:08:44 +00:00
|
|
|
|
2015-08-06 03:39:39 +00:00
|
|
|
(defun configuration-layer/make-layer (layer)
|
|
|
|
"Return a `cfgl-layer' object based on LAYER."
|
|
|
|
(let* ((name-sym (if (listp layer) (car layer) layer))
|
|
|
|
(name-str (symbol-name name-sym))
|
|
|
|
(base-dir (configuration-layer/get-layer-path name-sym))
|
2015-09-03 17:17:02 +00:00
|
|
|
(disabled (when (listp layer)
|
|
|
|
(spacemacs/mplist-get layer :disabled-for)))
|
2015-08-06 03:39:39 +00:00
|
|
|
(variables (when (listp layer)
|
|
|
|
(spacemacs/mplist-get layer :variables))))
|
|
|
|
(if base-dir
|
2015-08-09 02:57:12 +00:00
|
|
|
(let* ((dir (format "%s%s/" base-dir name-str)))
|
2015-08-06 03:39:39 +00:00
|
|
|
(cfgl-layer name-str
|
|
|
|
:name name-sym
|
|
|
|
:dir dir
|
2015-09-03 17:17:02 +00:00
|
|
|
:disabled-for disabled
|
2015-08-06 03:39:39 +00:00
|
|
|
:variables variables))
|
|
|
|
(spacemacs-buffer/warning "Cannot find layer %S !" name-sym)
|
|
|
|
nil)))
|
|
|
|
|
2015-08-26 02:27:31 +00:00
|
|
|
(defun configuration-layer//make-layers (symbols)
|
|
|
|
"Make `cfgl-layer' objects from the passed layer SYMBOLS."
|
|
|
|
(delq nil (mapcar 'configuration-layer/make-layer symbols)))
|
|
|
|
|
2015-08-13 05:23:39 +00:00
|
|
|
(defun configuration-layer/make-package (pkg &optional obj)
|
|
|
|
"Return a `cfgl-package' object based on PKG.
|
|
|
|
If OBJ is non nil then copy PKG properties into OBJ, otherwise create
|
|
|
|
a new object.
|
|
|
|
Properties that can be copied are `:location', `:step' and `:excluded'."
|
2015-08-06 03:39:39 +00:00
|
|
|
(let* ((name-sym (if (listp pkg) (car pkg) pkg))
|
|
|
|
(name-str (symbol-name name-sym))
|
|
|
|
(location (when (listp pkg) (plist-get (cdr pkg) :location)))
|
|
|
|
(step (when (listp pkg) (plist-get (cdr pkg) :step)))
|
2015-08-09 15:34:35 +00:00
|
|
|
(excluded (when (listp pkg) (plist-get (cdr pkg) :excluded)))
|
2015-11-19 05:53:57 +00:00
|
|
|
(protected (when (listp pkg) (plist-get (cdr pkg) :protected)))
|
|
|
|
(copyp (not (null obj)))
|
2015-08-13 05:23:39 +00:00
|
|
|
(obj (if obj obj (cfgl-package name-str :name name-sym))))
|
2015-08-06 03:39:39 +00:00
|
|
|
(when location (oset obj :location location))
|
|
|
|
(when step (oset obj :step step))
|
2015-08-09 15:34:35 +00:00
|
|
|
(oset obj :excluded excluded)
|
2015-11-19 05:53:57 +00:00
|
|
|
;; cannot override protected packages
|
|
|
|
(unless copyp
|
|
|
|
(oset obj :protected protected)
|
|
|
|
(when protected
|
|
|
|
(push name-sym configuration-layer--protected-packages)))
|
2015-08-06 03:39:39 +00:00
|
|
|
obj))
|
|
|
|
|
|
|
|
(defun configuration-layer/get-packages (layers &optional dotfile)
|
|
|
|
"Read the package lists of LAYERS and dotfile and return a list of packages."
|
|
|
|
(let (result)
|
|
|
|
(dolist (layer layers)
|
|
|
|
(let* ((name (oref layer :name))
|
|
|
|
(dir (oref layer :dir))
|
|
|
|
(packages-file (concat dir "packages.el"))
|
|
|
|
(extensions-file (concat dir "extensions.el")))
|
|
|
|
;; packages
|
|
|
|
(when (file-exists-p packages-file)
|
|
|
|
;; required for lazy-loading of unused layers
|
|
|
|
;; for instance for helm-spacemacs
|
2015-08-11 01:22:28 +00:00
|
|
|
(eval `(defvar ,(intern (format "%S-packages" name)) nil))
|
2015-08-06 03:39:39 +00:00
|
|
|
(unless (configuration-layer/layer-usedp name)
|
|
|
|
(load packages-file))
|
|
|
|
(dolist (pkg (symbol-value (intern (format "%S-packages" name))))
|
2015-08-13 05:23:39 +00:00
|
|
|
(let* ((pkg-name (if (listp pkg) (car pkg) pkg))
|
2015-08-06 03:39:39 +00:00
|
|
|
(init-func (intern (format "%S/init-%S"
|
2015-08-13 05:23:39 +00:00
|
|
|
name pkg-name)))
|
2015-08-06 03:39:39 +00:00
|
|
|
(pre-init-func (intern (format "%S/pre-init-%S"
|
2015-08-13 05:23:39 +00:00
|
|
|
name pkg-name)))
|
2015-08-06 03:39:39 +00:00
|
|
|
(post-init-func (intern (format "%S/post-init-%S"
|
2015-08-13 05:23:39 +00:00
|
|
|
name pkg-name)))
|
|
|
|
(obj (object-assoc pkg-name :name result)))
|
|
|
|
(if obj
|
|
|
|
(setq obj (configuration-layer/make-package pkg obj))
|
2015-08-06 03:39:39 +00:00
|
|
|
(setq obj (configuration-layer/make-package pkg))
|
|
|
|
(push obj result))
|
|
|
|
(when (fboundp init-func)
|
|
|
|
;; last owner wins over the previous one,
|
|
|
|
;; still warn about mutliple owners
|
|
|
|
(when (oref obj :owner)
|
|
|
|
(spacemacs-buffer/warning
|
|
|
|
(format (concat "More than one init function found for "
|
|
|
|
"package %S. Previous owner was %S, "
|
|
|
|
"replacing it with layer %S.")
|
|
|
|
pkg (oref obj :owner) name)))
|
|
|
|
(oset obj :owner name))
|
|
|
|
(when (fboundp pre-init-func)
|
|
|
|
(push name (oref obj :pre-layers)))
|
|
|
|
(when (fboundp post-init-func)
|
|
|
|
(push name (oref obj :post-layers)))))
|
2015-08-13 03:56:24 +00:00
|
|
|
;; TODO remove support for <layer>-excluded-packages in 0.105.0
|
2015-08-06 03:39:39 +00:00
|
|
|
(let ((xvar (intern (format "%S-excluded-packages" name))))
|
|
|
|
(when (boundp xvar)
|
|
|
|
(dolist (xpkg (symbol-value xvar))
|
|
|
|
(let ((obj (object-assoc xpkg :name result)))
|
|
|
|
(unless obj
|
|
|
|
(setq obj (configuration-layer/make-package xpkg))
|
|
|
|
(push obj result))
|
|
|
|
(oset obj :excluded t))))))
|
|
|
|
;; extensions (dummy duplication of the code above)
|
|
|
|
;; TODO remove extensions in 0.105.0
|
|
|
|
(when (file-exists-p extensions-file)
|
|
|
|
;; required for lazy-loading of unused layers
|
|
|
|
;; for instance for helm-spacemacs
|
|
|
|
(unless (configuration-layer/layer-usedp name)
|
|
|
|
(load extensions-file))
|
|
|
|
(dolist (step '(pre post))
|
2015-08-11 01:22:28 +00:00
|
|
|
(eval `(defvar ,(intern (format "%S-%S-extensions" name step)) nil))
|
2015-08-06 03:39:39 +00:00
|
|
|
(let ((var (intern (format "%S-%S-extensions" name step))))
|
|
|
|
(when (boundp var)
|
|
|
|
(dolist (pkg (symbol-value var))
|
2015-08-13 05:23:39 +00:00
|
|
|
(let ((pkg-name (if (listp pkg) (car pkg) pkg)))
|
2015-08-06 03:39:39 +00:00
|
|
|
(when (fboundp (intern (format "%S/init-%S"
|
2015-08-13 05:23:39 +00:00
|
|
|
name pkg-name)))
|
2015-08-06 03:39:39 +00:00
|
|
|
(let ((obj (configuration-layer/make-package pkg))
|
|
|
|
(init-func (intern (format "%S/init-%S"
|
2015-08-13 05:23:39 +00:00
|
|
|
name pkg-name)))
|
2015-08-06 03:39:39 +00:00
|
|
|
(pre-init-func (intern (format "%S/pre-init-%S"
|
2015-08-13 05:23:39 +00:00
|
|
|
name pkg-name)))
|
2015-08-06 03:39:39 +00:00
|
|
|
(post-init-func (intern (format "%S/post-init-%S"
|
2015-08-13 05:23:39 +00:00
|
|
|
name pkg-name)))
|
2015-08-06 03:39:39 +00:00
|
|
|
(obj (object-assoc pkg :name result)))
|
|
|
|
(unless obj
|
|
|
|
(setq obj (configuration-layer/make-package pkg))
|
|
|
|
(push obj result))
|
|
|
|
(when (fboundp init-func)
|
|
|
|
;; last owner wins over the previous one,
|
|
|
|
;; still warn about mutliple owners
|
|
|
|
(when (oref obj :owner)
|
|
|
|
(spacemacs-buffer/warning
|
|
|
|
(format (concat
|
|
|
|
"More than one init function found for "
|
|
|
|
"package %S. Previous owner was %S, "
|
|
|
|
"replacing it with layer %S.")
|
|
|
|
pkg (oref obj :owner) name)))
|
|
|
|
(oset obj :owner name))
|
|
|
|
(when (fboundp pre-init-func)
|
|
|
|
(push name (oref obj :pre-layers)))
|
|
|
|
(when (fboundp post-init-func)
|
|
|
|
(push name (oref obj :post-layers)))
|
|
|
|
(oset obj :location 'local)
|
2015-09-24 04:02:02 +00:00
|
|
|
(oset obj :step (when (eq 'pre step) step))))))))))))
|
2015-08-06 03:39:39 +00:00
|
|
|
;; additional and excluded packages from dotfile
|
|
|
|
(when dotfile
|
2015-09-14 19:35:06 +00:00
|
|
|
(dolist (pkg dotspacemacs-additional-packages)
|
|
|
|
(let* ((pkg-name (if (listp pkg) (car pkg) pkg))
|
|
|
|
(obj (object-assoc pkg-name :name result)))
|
|
|
|
(if obj
|
|
|
|
(setq obj (configuration-layer/make-package pkg obj))
|
|
|
|
(setq obj (configuration-layer/make-package pkg))
|
|
|
|
(push obj result)
|
|
|
|
(oset obj :owner 'dotfile))))
|
2015-08-06 03:39:39 +00:00
|
|
|
(dolist (xpkg dotspacemacs-excluded-packages)
|
|
|
|
(let ((obj (object-assoc xpkg :name result)))
|
|
|
|
(unless obj
|
|
|
|
(setq obj (configuration-layer/make-package xpkg))
|
|
|
|
(push obj result))
|
|
|
|
(oset obj :excluded t))))
|
|
|
|
result))
|
|
|
|
|
2015-08-08 02:51:27 +00:00
|
|
|
(defun configuration-layer//sort-packages (packages)
|
|
|
|
"Return a sorted list of PACKAGES objects."
|
|
|
|
(sort packages (lambda (x y) (string< (symbol-name (oref x :name))
|
|
|
|
(symbol-name (oref y :name))))))
|
|
|
|
|
2015-09-03 03:00:56 +00:00
|
|
|
(defun configuration-layer/filter-objects (objects ffunc)
|
|
|
|
"Return a filtered OBJECTS list where each element satisfies FFUNC."
|
2015-10-05 07:22:35 +00:00
|
|
|
(reverse (cl-reduce (lambda (acc x)
|
2015-08-08 04:01:36 +00:00
|
|
|
(if (funcall ffunc x) (push x acc) acc))
|
2015-09-03 03:00:56 +00:00
|
|
|
objects
|
2015-08-08 04:01:36 +00:00
|
|
|
:initial-value nil)))
|
|
|
|
|
2015-08-26 02:52:26 +00:00
|
|
|
(defun configuration-layer//get-distant-used-packages (packages)
|
|
|
|
"Return the distant packages (ie to be intalled) that are effectively used."
|
2015-09-03 03:00:56 +00:00
|
|
|
(configuration-layer/filter-objects
|
2015-08-26 02:52:26 +00:00
|
|
|
packages (lambda (x) (and (not (null (oref x :owner)))
|
2015-09-24 02:01:47 +00:00
|
|
|
(not (memq (oref x :location) '(built-in local)))
|
2015-10-22 19:29:40 +00:00
|
|
|
(not (stringp (oref x :location)))
|
2015-08-26 02:52:26 +00:00
|
|
|
(not (oref x :excluded))))))
|
|
|
|
|
2014-12-25 19:45:27 +00:00
|
|
|
(defun configuration-layer//get-private-layer-dir (name)
|
2015-09-19 05:37:45 +00:00
|
|
|
"Return an absolute path to the private configuration layer string NAME."
|
|
|
|
(file-name-as-directory
|
|
|
|
(concat configuration-layer-private-layer-directory name)))
|
2014-11-22 05:08:44 +00:00
|
|
|
|
2015-09-19 05:37:45 +00:00
|
|
|
(defun configuration-layer//copy-template (name template &optional layer-dir)
|
|
|
|
"Copy and replace special values of TEMPLATE to layer string NAME.
|
|
|
|
If LAYER_DIR is nil, the private directory is used."
|
2014-12-25 20:24:26 +00:00
|
|
|
(let ((src (concat configuration-layer-template-directory
|
2014-11-22 05:08:44 +00:00
|
|
|
(format "%s.template" template)))
|
2015-05-18 15:43:27 +00:00
|
|
|
(dest (if layer-dir
|
2015-11-16 13:13:06 +00:00
|
|
|
(concat layer-dir "/" (format "%s" template))
|
2015-05-18 15:43:27 +00:00
|
|
|
(concat (configuration-layer//get-private-layer-dir name)
|
2015-11-16 13:13:06 +00:00
|
|
|
(format "%s" template)))))
|
2014-11-22 05:08:44 +00:00
|
|
|
(copy-file src dest)
|
|
|
|
(find-file dest)
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (point-min))
|
2015-06-02 00:23:05 +00:00
|
|
|
(let ((case-fold-search nil))
|
|
|
|
(while (re-search-forward "%LAYERNAME%" nil t)
|
|
|
|
(replace-match name t))))
|
2014-11-22 05:08:44 +00:00
|
|
|
(save-buffer)))
|
|
|
|
|
2015-06-06 02:47:23 +00:00
|
|
|
(defun configuration-layer//directory-type (path)
|
|
|
|
"Return the type of directory pointed by PATH.
|
|
|
|
Possible return values:
|
|
|
|
layer - the directory is a layer
|
|
|
|
category - the directory is a category
|
|
|
|
nil - the directory is a regular directory."
|
2015-05-17 12:27:43 +00:00
|
|
|
(when (file-directory-p path)
|
2015-06-06 02:47:23 +00:00
|
|
|
(if (string-match
|
2015-09-11 00:21:27 +00:00
|
|
|
"^+" (file-name-nondirectory
|
2015-06-06 02:47:23 +00:00
|
|
|
(directory-file-name
|
2015-09-08 01:16:15 +00:00
|
|
|
(concat configuration-layer-directory path))))
|
2015-06-06 02:47:23 +00:00
|
|
|
'category
|
|
|
|
(let ((files (directory-files path)))
|
|
|
|
;; most frequent files encoutered in a layer are tested first
|
|
|
|
(when (or (member "packages.el" files)
|
|
|
|
(member "extensions.el" files)
|
|
|
|
(member "config.el" files)
|
|
|
|
(member "keybindings.el" files)
|
|
|
|
(member "funcs.el" files))
|
|
|
|
'layer)))))
|
|
|
|
|
|
|
|
(defun configuration-layer//get-category-from-path (dirpath)
|
|
|
|
"Return a category symbol from the given DIRPATH.
|
2015-09-11 00:21:27 +00:00
|
|
|
The directory name must start with `+'.
|
2015-06-06 02:47:23 +00:00
|
|
|
Returns nil if the directory is not a category."
|
|
|
|
(when (file-directory-p dirpath)
|
|
|
|
(let ((dirname (file-name-nondirectory
|
|
|
|
(directory-file-name
|
2015-09-08 01:16:15 +00:00
|
|
|
(concat configuration-layer-directory
|
2015-06-06 02:47:23 +00:00
|
|
|
dirpath)))))
|
2015-09-11 00:21:27 +00:00
|
|
|
(when (string-match "^+" dirname)
|
2015-06-06 02:47:23 +00:00
|
|
|
(intern (substring dirname 1))))))
|
2014-11-11 03:26:11 +00:00
|
|
|
|
2014-12-25 19:45:27 +00:00
|
|
|
(defun configuration-layer//discover-layers ()
|
2014-12-20 20:08:02 +00:00
|
|
|
"Return a hash table where the key is the layer symbol and the value is its
|
|
|
|
path."
|
2015-05-29 17:08:48 +00:00
|
|
|
;; load private layers at the end on purpose we asume that the user layers
|
|
|
|
;; must have the final word on configuration choices. Let
|
|
|
|
;; `dotspacemacs-directory' override the private directory if it exists.
|
2015-09-08 01:16:15 +00:00
|
|
|
(let ((search-paths (append (list configuration-layer-directory)
|
2015-05-17 12:27:43 +00:00
|
|
|
dotspacemacs-configuration-layer-path
|
2015-06-05 23:50:03 +00:00
|
|
|
(list configuration-layer-private-layer-directory)
|
2015-07-24 02:59:45 +00:00
|
|
|
(when dotspacemacs-directory
|
|
|
|
(list dotspacemacs-directory))))
|
2015-04-25 05:26:22 +00:00
|
|
|
(discovered '())
|
2015-04-03 21:12:56 +00:00
|
|
|
(result (make-hash-table :size 256)))
|
2015-05-17 12:27:43 +00:00
|
|
|
;; depth-first search of subdirectories
|
|
|
|
(while search-paths
|
|
|
|
(let ((current-path (car search-paths)))
|
|
|
|
(setq search-paths (cdr search-paths))
|
|
|
|
(dolist (sub (directory-files current-path t nil 'nosort))
|
|
|
|
;; ignore ".", ".." and non-directories
|
|
|
|
(unless (or (string-equal ".." (substring sub -2))
|
|
|
|
(string-equal "." (substring sub -1))
|
|
|
|
(not (file-directory-p sub)))
|
2015-06-06 02:47:23 +00:00
|
|
|
(let ((type (configuration-layer//directory-type sub)))
|
|
|
|
(cond
|
|
|
|
((eq 'category type)
|
|
|
|
(let ((category (configuration-layer//get-category-from-path
|
|
|
|
sub)))
|
|
|
|
(spacemacs-buffer/message "-> Discovered category: %S"
|
|
|
|
category)
|
|
|
|
(push category configuration-layer-categories)
|
|
|
|
(setq search-paths (cons sub search-paths))))
|
|
|
|
((eq 'layer type)
|
2015-05-17 12:27:43 +00:00
|
|
|
(let ((layer-name (file-name-nondirectory sub))
|
|
|
|
(layer-dir (file-name-directory sub)))
|
2015-08-06 03:39:39 +00:00
|
|
|
(spacemacs-buffer/message
|
|
|
|
"-> Discovered configuration layer: %s" layer-name)
|
2015-06-06 02:47:23 +00:00
|
|
|
(push (cons (intern layer-name) layer-dir) discovered)))
|
|
|
|
(t
|
|
|
|
;; layer not found, add it to search path
|
|
|
|
(setq search-paths (cons sub search-paths)))))))))
|
2015-05-17 12:27:43 +00:00
|
|
|
;; add discovered layers to hash table
|
2015-05-10 01:59:03 +00:00
|
|
|
(mapc (lambda (l)
|
|
|
|
(if (ht-contains? result (car l))
|
2015-05-17 12:27:43 +00:00
|
|
|
;; the same layer may have been discovered twice,
|
|
|
|
;; in which case we don't need a warning
|
|
|
|
(unless (string-equal (ht-get result (car l)) (cdr l))
|
|
|
|
(spacemacs-buffer/warning
|
|
|
|
(concat "Duplicated layer %s detected in directory \"%s\", "
|
|
|
|
"keeping only the layer in directory \"%s\"")
|
|
|
|
(car l) (cdr l) (ht-get result (car l))))
|
|
|
|
(puthash (car l) (cdr l) result)))
|
|
|
|
discovered)
|
2015-04-25 05:26:22 +00:00
|
|
|
result))
|
2014-12-20 20:08:02 +00:00
|
|
|
|
2015-08-26 02:27:31 +00:00
|
|
|
(defun configuration-layer//declare-layers ()
|
2015-09-08 01:16:15 +00:00
|
|
|
"Declare default layers and user layers declared in the dotfile."
|
2015-09-07 23:42:22 +00:00
|
|
|
(setq configuration-layer--layers nil)
|
2015-01-25 05:01:43 +00:00
|
|
|
(setq configuration-layer-paths (configuration-layer//discover-layers))
|
2015-09-08 01:16:15 +00:00
|
|
|
(when (eq 'all dotspacemacs-configuration-layers)
|
|
|
|
(setq dotspacemacs-configuration-layers
|
|
|
|
(ht-keys configuration-layer-paths)))
|
|
|
|
(dolist (layer dotspacemacs-configuration-layers)
|
|
|
|
(let ((layer-name (if (listp layer) (car layer) layer)))
|
2015-09-09 15:50:23 +00:00
|
|
|
(if (ht-contains? configuration-layer-paths layer-name)
|
2015-09-11 00:21:27 +00:00
|
|
|
(unless (string-match-p "+distribution"
|
2015-09-09 15:50:23 +00:00
|
|
|
(ht-get configuration-layer-paths layer-name))
|
|
|
|
(push (configuration-layer/make-layer layer)
|
|
|
|
configuration-layer--layers))
|
2015-09-10 01:24:27 +00:00
|
|
|
(spacemacs-buffer/warning "Unknown layer %s declared in dotfile."
|
|
|
|
layer-name))))
|
2015-09-08 01:16:15 +00:00
|
|
|
(setq configuration-layer--layers (reverse configuration-layer--layers))
|
|
|
|
;; distribution layer is always first
|
|
|
|
(push (configuration-layer/make-layer dotspacemacs-distribution)
|
|
|
|
configuration-layer--layers))
|
2015-08-06 03:39:39 +00:00
|
|
|
|
2015-08-26 06:41:54 +00:00
|
|
|
(defun configuration-layer/declare-layers (layer-names)
|
|
|
|
"Add layer with LAYER-NAMES to used layers."
|
|
|
|
(mapc 'configuration-layer/declare-layer layer-names))
|
|
|
|
|
|
|
|
(defun configuration-layer/declare-layer (layer-name)
|
|
|
|
"Declare a single layer"
|
|
|
|
(unless (object-assoc layer-name :name configuration-layer--layers)
|
|
|
|
(let ((new-layer (configuration-layer/make-layer layer-name)))
|
|
|
|
(push new-layer configuration-layer--layers)
|
|
|
|
(configuration-layer//configure-layer new-layer))))
|
|
|
|
|
2015-01-26 04:22:41 +00:00
|
|
|
(defun configuration-layer//set-layers-variables (layers)
|
|
|
|
"Set the configuration variables for the passed LAYERS."
|
2015-08-26 06:41:54 +00:00
|
|
|
(mapc 'configuration-layer//set-layer-variables layers))
|
|
|
|
|
|
|
|
(defun configuration-layer//set-layer-variables (layer)
|
|
|
|
"Set the configuration variables for the passed LAYER."
|
|
|
|
(let ((variables (oref layer :variables)))
|
|
|
|
(while variables
|
|
|
|
(let ((var (pop variables)))
|
|
|
|
(if (consp variables)
|
|
|
|
(condition-case err
|
|
|
|
(set-default var (eval (pop variables)))
|
|
|
|
('error
|
|
|
|
(configuration-layer//set-error)
|
|
|
|
(spacemacs-buffer/append
|
2015-12-03 04:25:00 +00:00
|
|
|
(format (concat "\nAn error occurred while setting layer "
|
2015-08-26 06:41:54 +00:00
|
|
|
"variable %s "
|
|
|
|
"(error: %s). Be sure to quote the value "
|
|
|
|
"if needed.\n") var err))))
|
|
|
|
(spacemacs-buffer/warning "Missing value for variable %s !"
|
|
|
|
var))))))
|
2015-06-01 04:29:38 +00:00
|
|
|
|
2015-07-26 04:41:41 +00:00
|
|
|
(defun configuration-layer/layer-usedp (name)
|
|
|
|
"Return non-nil if NAME is the name of a used layer."
|
2015-08-26 02:52:26 +00:00
|
|
|
(not (null (object-assoc name :name configuration-layer--layers))))
|
2015-08-06 03:39:39 +00:00
|
|
|
|
|
|
|
(defun configuration-layer/package-usedp (name)
|
|
|
|
"Return non-nil if NAME is the name of a used package."
|
2015-08-26 02:52:26 +00:00
|
|
|
(let ((obj (object-assoc name :name configuration-layer--packages)))
|
2015-11-01 04:59:29 +00:00
|
|
|
(when (and obj (not (oref obj :excluded))) (oref obj :owner))))
|
2014-11-30 05:52:22 +00:00
|
|
|
|
2015-08-26 02:27:31 +00:00
|
|
|
(defun configuration-layer//configure-layers (layers)
|
|
|
|
"Configure LAYERS."
|
|
|
|
;; FIFO loading of layers, this allow the user to put her layers at the
|
2015-08-06 03:39:39 +00:00
|
|
|
;; end of the list to override previous layers.
|
2015-08-26 06:41:54 +00:00
|
|
|
(let ((warning-minimum-level :error))
|
2015-09-07 23:42:22 +00:00
|
|
|
(dolist (l layers)
|
2015-08-26 06:41:54 +00:00
|
|
|
(configuration-layer//configure-layer l))))
|
|
|
|
|
|
|
|
(defun configuration-layer//configure-layer (layer)
|
|
|
|
"Configure LAYER."
|
|
|
|
(configuration-layer//set-layer-variables layer)
|
|
|
|
(configuration-layer//load-layer-files layer '("funcs.el"
|
|
|
|
"config.el"
|
|
|
|
"keybindings.el")))
|
2015-08-26 02:27:31 +00:00
|
|
|
|
|
|
|
(defun configuration-layer//declare-packages (layers)
|
|
|
|
"Declare all packages contained in LAYERS."
|
2015-09-07 23:42:22 +00:00
|
|
|
(let ((layers2 layers)
|
2015-08-26 02:27:31 +00:00
|
|
|
(warning-minimum-level :error))
|
2015-08-06 03:39:39 +00:00
|
|
|
;; TODO remove extensions in 0.105.0
|
2015-08-26 06:41:54 +00:00
|
|
|
(configuration-layer//load-layers-files layers2 '("packages.el" "extensions.el"))
|
2015-08-26 02:27:31 +00:00
|
|
|
;; gather all the packages of current layer
|
|
|
|
(configuration-layer//sort-packages (configuration-layer/get-packages
|
2015-08-26 06:41:54 +00:00
|
|
|
layers2 t))))
|
2015-08-26 02:27:31 +00:00
|
|
|
|
|
|
|
(defun configuration-layer//load-packages (packages)
|
|
|
|
"Load PACKAGES."
|
|
|
|
;; number of chuncks for the loading screen
|
|
|
|
(setq spacemacs-loading-dots-chunk-threshold
|
|
|
|
(/ (configuration-layer/configured-packages-count)
|
|
|
|
spacemacs-loading-dots-chunk-count))
|
|
|
|
(configuration-layer//install-packages packages)
|
|
|
|
(configuration-layer//configure-packages packages))
|
2014-12-20 20:08:02 +00:00
|
|
|
|
2015-03-05 05:00:18 +00:00
|
|
|
(defun configuration-layer//load-layers-files (layers files)
|
|
|
|
"Load the files of list FILES for all passed LAYERS."
|
2014-12-20 20:08:02 +00:00
|
|
|
(dolist (layer layers)
|
2015-03-05 05:00:18 +00:00
|
|
|
(configuration-layer//load-layer-files layer files)))
|
|
|
|
|
|
|
|
(defun configuration-layer//load-layer-files (layer files)
|
|
|
|
"Load the files of list FILES for the given LAYER."
|
2015-07-26 04:41:41 +00:00
|
|
|
(dolist (file files)
|
|
|
|
(let ((file (concat (oref layer :dir) file)))
|
|
|
|
(if (file-exists-p file) (load file)))))
|
2014-09-03 06:25:27 +00:00
|
|
|
|
2015-08-09 02:57:12 +00:00
|
|
|
(defun configuration-layer/configured-packages-count ()
|
|
|
|
"Return the number of configured packages."
|
2015-08-26 02:52:26 +00:00
|
|
|
(length configuration-layer--packages))
|
2015-08-09 02:57:12 +00:00
|
|
|
|
|
|
|
(defun configuration-layer//install-packages (packages)
|
|
|
|
"Install PACKAGES."
|
2014-09-03 06:25:27 +00:00
|
|
|
(interactive)
|
2015-08-26 02:52:26 +00:00
|
|
|
(let* ((noinst-pkg-names
|
|
|
|
(configuration-layer//get-uninstalled-packages
|
|
|
|
(mapcar 'car
|
|
|
|
(object-assoc-list
|
|
|
|
:name configuration-layer--used-distant-packages))))
|
2015-08-15 04:08:21 +00:00
|
|
|
(noinst-count (length noinst-pkg-names)))
|
2014-09-03 06:25:27 +00:00
|
|
|
;; installation
|
2015-08-15 04:08:21 +00:00
|
|
|
(when noinst-pkg-names
|
2015-08-13 03:56:24 +00:00
|
|
|
(spacemacs-buffer/append
|
|
|
|
(format "Found %s new package(s) to install...\n"
|
2015-08-15 04:08:21 +00:00
|
|
|
noinst-count))
|
2015-12-03 04:49:00 +00:00
|
|
|
(configuration-layer/retrieve-package-archives)
|
2015-08-13 03:56:24 +00:00
|
|
|
(setq installed-count 0)
|
2015-08-15 04:08:21 +00:00
|
|
|
(dolist (pkg-name noinst-pkg-names)
|
2015-08-13 03:56:24 +00:00
|
|
|
(setq installed-count (1+ installed-count))
|
2015-08-26 02:52:26 +00:00
|
|
|
(let* ((pkg (object-assoc pkg-name :name configuration-layer--packages))
|
2015-08-15 04:08:21 +00:00
|
|
|
(layer (when pkg (oref pkg :owner)))
|
|
|
|
(location (when pkg (oref pkg :location))))
|
2015-08-13 03:56:24 +00:00
|
|
|
(spacemacs-buffer/replace-last-line
|
2015-12-03 04:25:00 +00:00
|
|
|
(format "--> installing %s: %s%s... [%s/%s]"
|
|
|
|
(if layer "package" "dependency")
|
|
|
|
pkg-name (if layer (format "@%S" layer) "")
|
|
|
|
installed-count noinst-count) t)
|
2015-08-13 03:56:24 +00:00
|
|
|
(unless (package-installed-p pkg-name)
|
|
|
|
(condition-case err
|
|
|
|
(cond
|
2015-08-15 04:08:21 +00:00
|
|
|
((or (null pkg) (eq 'elpa location))
|
|
|
|
(configuration-layer//install-from-elpa pkg-name))
|
2015-08-14 19:31:22 +00:00
|
|
|
((and (listp location) (eq 'recipe (car location)))
|
2015-08-13 03:56:24 +00:00
|
|
|
(configuration-layer//install-from-recipe pkg))
|
2015-08-15 04:08:21 +00:00
|
|
|
(t (spacemacs-buffer/warning "Cannot install package %S."
|
|
|
|
pkg-name)))
|
2015-08-13 03:56:24 +00:00
|
|
|
('error
|
|
|
|
(configuration-layer//set-error)
|
|
|
|
(spacemacs-buffer/append
|
2015-12-03 04:25:00 +00:00
|
|
|
(format (concat "\nAn error occurred while installing %s "
|
2015-08-13 03:56:24 +00:00
|
|
|
"(error: %s)\n") pkg-name err))))))
|
|
|
|
(spacemacs//redisplay))
|
|
|
|
(spacemacs-buffer/append "\n"))))
|
|
|
|
|
2015-08-15 04:08:21 +00:00
|
|
|
(defun configuration-layer//install-from-elpa (pkg-name)
|
2015-08-13 03:56:24 +00:00
|
|
|
"Install PKG from ELPA."
|
|
|
|
(if (not (assq pkg-name package-archive-contents))
|
|
|
|
(spacemacs-buffer/append
|
|
|
|
(format (concat "\nPackage %s is unavailable. "
|
|
|
|
"Is the package name misspelled?\n")
|
|
|
|
pkg-name))
|
|
|
|
(dolist
|
|
|
|
(dep (configuration-layer//get-package-deps-from-archive
|
|
|
|
pkg-name))
|
|
|
|
(configuration-layer//activate-package (car dep)))
|
|
|
|
(package-install pkg-name)))
|
|
|
|
|
|
|
|
(defun configuration-layer//install-from-recipe (pkg)
|
|
|
|
"Install PKG from a recipe."
|
2015-08-19 17:08:57 +00:00
|
|
|
(let* ((pkg-name (oref pkg :name))
|
2015-08-13 03:56:24 +00:00
|
|
|
(layer (oref pkg :owner))
|
2015-08-14 19:31:22 +00:00
|
|
|
(recipe (cons pkg-name (cdr (oref pkg :location)))))
|
2015-08-13 03:56:24 +00:00
|
|
|
(if recipe
|
|
|
|
(quelpa recipe)
|
|
|
|
(spacemacs-buffer/warning
|
|
|
|
(concat "Cannot find any recipe for package %S! Be sure "
|
|
|
|
"to add a recipe for it in alist %S.")
|
|
|
|
pkg-name recipes-var))))
|
2014-09-03 06:25:27 +00:00
|
|
|
|
2015-09-18 03:05:32 +00:00
|
|
|
(defun configuration-layer//filter-packages-with-deps
|
|
|
|
(pkg-names filter &optional use-archive)
|
2015-08-09 03:16:56 +00:00
|
|
|
"Return a filtered PACKAGES list where each elements satisfies FILTER."
|
|
|
|
(when pkg-names
|
2015-02-03 07:05:29 +00:00
|
|
|
(let (result)
|
2015-08-09 03:16:56 +00:00
|
|
|
(dolist (pkg-name pkg-names)
|
2015-02-03 07:05:29 +00:00
|
|
|
;; recursively check dependencies
|
|
|
|
(let* ((deps
|
2015-09-18 03:05:32 +00:00
|
|
|
(if use-archive
|
|
|
|
(configuration-layer//get-package-deps-from-archive
|
|
|
|
pkg-name)
|
|
|
|
(configuration-layer//get-package-deps-from-alist pkg-name)))
|
2015-04-08 03:51:08 +00:00
|
|
|
(install-deps
|
|
|
|
(when deps (configuration-layer//filter-packages-with-deps
|
|
|
|
(mapcar 'car deps) filter))))
|
|
|
|
(when install-deps
|
|
|
|
(setq result (append install-deps result))))
|
2015-08-09 03:16:56 +00:00
|
|
|
(when (funcall filter pkg-name)
|
|
|
|
(add-to-list 'result pkg-name t)))
|
2015-02-03 07:05:29 +00:00
|
|
|
(delete-dups result))))
|
2015-02-03 05:58:17 +00:00
|
|
|
|
2015-08-09 03:16:56 +00:00
|
|
|
(defun configuration-layer//get-uninstalled-packages (pkg-names)
|
|
|
|
"Return a filtered list of PKG-NAMES to install."
|
2015-04-08 03:51:08 +00:00
|
|
|
(configuration-layer//filter-packages-with-deps
|
2015-08-09 03:16:56 +00:00
|
|
|
pkg-names (lambda (x) (not (package-installed-p x)))))
|
2015-04-08 03:51:08 +00:00
|
|
|
|
2015-08-15 04:07:56 +00:00
|
|
|
(defun configuration-layer//package-has-recipe-p (pkg-name)
|
|
|
|
"Return non nil if PKG-NAME is the name of a package declared with a recipe."
|
2015-08-26 02:52:26 +00:00
|
|
|
(when (object-assoc pkg-name :name configuration-layer--packages)
|
|
|
|
(let* ((pkg (object-assoc pkg-name :name configuration-layer--packages))
|
2015-08-15 04:07:56 +00:00
|
|
|
(location (oref pkg :location)))
|
|
|
|
(and (listp location) (eq 'recipe (car location))))))
|
|
|
|
|
|
|
|
(defun configuration-layer//get-package-recipe (pkg-name)
|
|
|
|
"Return the recipe for PGK-NAME if it has one."
|
2015-08-26 02:52:26 +00:00
|
|
|
(let ((pkg (object-assoc pkg-name :name configuration-layer--packages)))
|
2015-08-15 04:07:56 +00:00
|
|
|
(when pkg
|
|
|
|
(let ((location (oref pkg :location)))
|
|
|
|
(when (and (listp location) (eq 'recipe (car location)))
|
|
|
|
location)))))
|
|
|
|
|
|
|
|
(defun configuration-layer//new-version-available-p (pkg-name)
|
|
|
|
"Return non nil if there is a new version available for PKG-NAME."
|
|
|
|
(let ((recipe (configuration-layer//get-package-recipe pkg-name))
|
|
|
|
(cur-version (configuration-layer//get-package-version-string pkg-name))
|
|
|
|
new-version)
|
|
|
|
(when cur-version
|
|
|
|
(setq new-version
|
|
|
|
(if recipe
|
|
|
|
(quelpa-checkout recipe (expand-file-name (symbol-name pkg-name)
|
|
|
|
quelpa-build-dir))
|
|
|
|
(configuration-layer//get-latest-package-version-string
|
|
|
|
pkg-name)))
|
|
|
|
;; (message "%s: %s > %s ?" pkg-name cur-version new-version)
|
2015-08-29 07:09:13 +00:00
|
|
|
(if new-version
|
|
|
|
(version< cur-version new-version)
|
|
|
|
(cl-pushnew pkg-name configuration-layer--skipped-packages :test #'eq)
|
|
|
|
nil))))
|
2015-08-15 04:07:56 +00:00
|
|
|
|
2015-08-09 04:47:22 +00:00
|
|
|
(defun configuration-layer//get-packages-to-update (pkg-names)
|
|
|
|
"Return a filtered list of PKG-NAMES to update."
|
2015-04-08 03:51:08 +00:00
|
|
|
(configuration-layer//filter-packages-with-deps
|
2015-09-18 03:05:32 +00:00
|
|
|
pkg-names 'configuration-layer//new-version-available-p 'use-archive))
|
2015-04-08 03:51:08 +00:00
|
|
|
|
2015-08-09 02:57:12 +00:00
|
|
|
(defun configuration-layer//configure-packages (packages)
|
|
|
|
"Configure all passed PACKAGES honoring the steps order."
|
|
|
|
(configuration-layer//configure-packages-2
|
2015-09-03 03:00:56 +00:00
|
|
|
(configuration-layer/filter-objects
|
2015-08-09 02:57:12 +00:00
|
|
|
packages (lambda (x) (eq 'pre (oref x :step)))))
|
|
|
|
(configuration-layer//configure-packages-2
|
2015-09-03 03:00:56 +00:00
|
|
|
(configuration-layer/filter-objects
|
2015-09-24 04:02:02 +00:00
|
|
|
packages (lambda (x) (null (oref x :step))))))
|
2015-08-09 02:57:12 +00:00
|
|
|
|
|
|
|
(defun configuration-layer//configure-packages-2 (packages)
|
|
|
|
"Configure all passed PACKAGES."
|
|
|
|
(dolist (pkg packages)
|
|
|
|
(spacemacs-buffer/loading-animation)
|
|
|
|
(let ((pkg-name (oref pkg :name)))
|
|
|
|
(cond
|
2015-11-19 05:53:57 +00:00
|
|
|
((and (oref pkg :excluded)
|
|
|
|
(not (oref pkg :protected)))
|
2015-08-09 02:57:12 +00:00
|
|
|
(spacemacs-buffer/message
|
|
|
|
(format "%S ignored since it has been excluded." pkg-name)))
|
|
|
|
((null (oref pkg :owner))
|
|
|
|
(spacemacs-buffer/message
|
|
|
|
(format "%S ignored since it has no owner layer." pkg-name)))
|
|
|
|
(t
|
2015-09-20 04:49:18 +00:00
|
|
|
;; load-path
|
2015-10-23 02:39:53 +00:00
|
|
|
(let ((location (oref pkg :location)))
|
|
|
|
(cond
|
|
|
|
((stringp location)
|
|
|
|
(if (file-directory-p location)
|
|
|
|
(push (file-name-as-directory location) load-path)
|
|
|
|
(spacemacs-buffer/warning
|
|
|
|
"Location path for package %S does not exists (value: %s)."
|
|
|
|
pkg location)))
|
|
|
|
((and (eq 'local location)
|
|
|
|
(eq 'dotfile (oref pkg :owner)))
|
|
|
|
(push (file-name-as-directory
|
|
|
|
(concat configuration-layer-private-directory "local/"
|
|
|
|
(symbol-name (oref pkg :name))))
|
|
|
|
load-path))
|
|
|
|
((eq 'local location)
|
|
|
|
(let* ((owner (object-assoc (oref pkg :owner) :name configuration-layer--layers))
|
|
|
|
(dir (when owner (oref owner :dir))))
|
|
|
|
(push (format "%slocal/%S/" dir pkg-name) load-path)
|
|
|
|
;; TODO remove extensions in 0.105.0
|
|
|
|
(push (format "%sextensions/%S/" dir pkg-name) load-path)))))
|
2015-09-20 04:49:18 +00:00
|
|
|
;; configuration
|
|
|
|
(cond
|
|
|
|
((eq 'dotfile (oref pkg :owner))
|
|
|
|
(configuration-layer//activate-package pkg-name)
|
|
|
|
(spacemacs-buffer/message
|
|
|
|
(format "%S is configured in the dotfile." pkg-name)))
|
|
|
|
(t
|
|
|
|
(configuration-layer//activate-package pkg-name)
|
|
|
|
(configuration-layer//configure-package pkg))))))))
|
2015-08-09 02:57:12 +00:00
|
|
|
|
|
|
|
(defun configuration-layer//configure-package (pkg)
|
|
|
|
"Configure PKG."
|
2015-09-03 03:01:26 +00:00
|
|
|
(let* ((pkg-name (oref pkg :name))
|
|
|
|
(owner (oref pkg :owner))
|
|
|
|
(owner-layer (object-assoc owner :name configuration-layer--layers))
|
|
|
|
(disabled-for-layers (oref owner-layer :disabled-for)))
|
2015-08-09 02:57:12 +00:00
|
|
|
(spacemacs-buffer/message (format "Configuring %S..." pkg-name))
|
|
|
|
;; pre-init
|
|
|
|
(mapc (lambda (layer)
|
2015-09-03 03:01:26 +00:00
|
|
|
(if (memq layer disabled-for-layers)
|
|
|
|
(spacemacs-buffer/message
|
2015-09-03 17:17:02 +00:00
|
|
|
(format " -> ignored pre-init (%S)..." layer))
|
2015-09-03 03:01:26 +00:00
|
|
|
(spacemacs-buffer/message
|
|
|
|
(format " -> pre-init (%S)..." layer))
|
|
|
|
(condition-case err
|
|
|
|
(funcall (intern (format "%S/pre-init-%S" layer pkg-name)))
|
|
|
|
('error
|
|
|
|
(configuration-layer//set-error)
|
|
|
|
(spacemacs-buffer/append
|
|
|
|
(format
|
2015-12-03 04:25:00 +00:00
|
|
|
(concat "\nAn error occurred while pre-configuring %S "
|
2015-09-03 03:01:26 +00:00
|
|
|
"in layer %S (error: %s)\n")
|
|
|
|
pkg-name layer err))))))
|
2015-08-09 02:57:12 +00:00
|
|
|
(oref pkg :pre-layers))
|
|
|
|
;; init
|
2015-09-03 03:01:26 +00:00
|
|
|
(spacemacs-buffer/message (format " -> init (%S)..." owner))
|
|
|
|
(funcall (intern (format "%S/init-%S" owner pkg-name)))
|
2015-08-09 02:57:12 +00:00
|
|
|
;; post-init
|
|
|
|
(mapc (lambda (layer)
|
2015-09-03 03:01:26 +00:00
|
|
|
(if (memq layer disabled-for-layers)
|
|
|
|
(spacemacs-buffer/message
|
2015-09-03 17:17:02 +00:00
|
|
|
(format " -> ignored post-init (%S)..." layer))
|
2015-09-03 03:01:26 +00:00
|
|
|
(spacemacs-buffer/message
|
|
|
|
(format " -> post-init (%S)..." layer))
|
|
|
|
(condition-case err
|
|
|
|
(funcall (intern (format "%S/post-init-%S" layer pkg-name)))
|
|
|
|
('error
|
|
|
|
(configuration-layer//set-error)
|
|
|
|
(spacemacs-buffer/append
|
|
|
|
(format
|
2015-12-03 04:25:00 +00:00
|
|
|
(concat "\nAn error occurred while post-configuring %S "
|
2015-09-03 03:01:26 +00:00
|
|
|
"in layer %S (error: %s)\n")
|
|
|
|
pkg-name layer err))))))
|
2015-08-09 02:57:12 +00:00
|
|
|
(oref pkg :post-layers))))
|
|
|
|
|
2015-11-10 22:34:27 +00:00
|
|
|
(defun configuration-layer//cleanup-rollback-directory ()
|
2015-11-10 21:40:26 +00:00
|
|
|
"Clean up the rollback directory."
|
|
|
|
(let* ((dirattrs (delq nil
|
|
|
|
(mapcar (lambda (d)
|
|
|
|
(unless (eq t d) d))
|
|
|
|
(directory-files-and-attributes
|
|
|
|
configuration-layer-rollback-directory
|
|
|
|
nil "\\`\\(\\.\\{0,2\\}[^.\n].*\\)\\'" t))))
|
|
|
|
(dirs (sort dirattrs
|
|
|
|
(lambda (d e)
|
|
|
|
(time-less-p (nth 6 d) (nth 6 e))))))
|
2015-11-11 05:14:46 +00:00
|
|
|
(dotimes (c (- (length dirs) dotspacemacs-max-rollback-slots))
|
2015-11-10 21:40:26 +00:00
|
|
|
(delete-directory (concat configuration-layer-rollback-directory
|
|
|
|
"/" (car (pop dirs)))
|
|
|
|
t t))))
|
2015-11-08 19:20:43 +00:00
|
|
|
|
2015-06-28 02:33:48 +00:00
|
|
|
(defun configuration-layer/update-packages (&optional always-update)
|
2015-08-09 04:47:22 +00:00
|
|
|
"Update packages.
|
|
|
|
|
|
|
|
If called with a prefix argument ALWAYS-UPDATE, assume yes to update."
|
2015-06-28 02:33:48 +00:00
|
|
|
(interactive "P")
|
2015-04-12 04:24:03 +00:00
|
|
|
(spacemacs-buffer/insert-page-break)
|
2015-12-03 04:25:00 +00:00
|
|
|
(spacemacs-buffer/append (concat "\nUpdating Emacs packages from remote "
|
|
|
|
"repositories (ELPA, MELPA, etc.)...\n"))
|
2015-12-03 04:49:00 +00:00
|
|
|
(configuration-layer/retrieve-package-archives nil 'force)
|
2015-08-29 07:09:13 +00:00
|
|
|
(setq configuration-layer--skipped-packages nil)
|
2015-08-26 02:52:26 +00:00
|
|
|
(let* ((update-packages
|
|
|
|
(configuration-layer//get-packages-to-update
|
|
|
|
(mapcar 'car (object-assoc-list
|
|
|
|
:name configuration-layer--used-distant-packages))))
|
2015-08-29 07:09:13 +00:00
|
|
|
(skipped-count (length configuration-layer--skipped-packages))
|
2015-02-04 04:56:38 +00:00
|
|
|
(date (format-time-string "%y-%m-%d_%H.%M.%S"))
|
|
|
|
(rollback-dir (expand-file-name
|
|
|
|
(concat configuration-layer-rollback-directory
|
|
|
|
(file-name-as-directory date))))
|
|
|
|
(upgrade-count (length update-packages))
|
|
|
|
(upgraded-count 0)
|
|
|
|
(update-packages-alist))
|
2015-08-29 07:09:13 +00:00
|
|
|
(when configuration-layer--skipped-packages
|
|
|
|
(spacemacs-buffer/append
|
|
|
|
(format (concat "--> Warning: cannot update %s package(s), possibly due"
|
|
|
|
" to a temporary network problem: %s\n")
|
|
|
|
skipped-count
|
|
|
|
(mapconcat #'symbol-name
|
|
|
|
configuration-layer--skipped-packages
|
|
|
|
" "))))
|
2015-08-09 04:47:22 +00:00
|
|
|
;; (message "packages to udpate: %s" update-packages)
|
2015-02-03 05:58:17 +00:00
|
|
|
(if (> upgrade-count 0)
|
2015-06-28 02:33:48 +00:00
|
|
|
(if (and (not always-update)
|
|
|
|
(not (yes-or-no-p (format (concat "%s package(s) to update, "
|
2015-08-29 07:09:13 +00:00
|
|
|
(if (> skipped-count 0)
|
|
|
|
(format "%s package(s) skipped, "
|
|
|
|
skipped-count)
|
|
|
|
"")
|
2015-06-28 02:33:48 +00:00
|
|
|
"do you want to continue ? ")
|
|
|
|
upgrade-count))))
|
2015-04-12 04:24:03 +00:00
|
|
|
(spacemacs-buffer/append
|
2015-02-11 02:56:18 +00:00
|
|
|
"Packages update has been cancelled.\n")
|
2015-02-04 04:56:38 +00:00
|
|
|
;; backup the package directory and construct an alist
|
|
|
|
;; variable to be cached for easy update and rollback
|
2015-04-12 04:24:03 +00:00
|
|
|
(spacemacs-buffer/append
|
2015-02-11 02:56:18 +00:00
|
|
|
"--> performing backup of package(s) to update...\n" t)
|
2015-02-16 02:25:12 +00:00
|
|
|
(spacemacs//redisplay)
|
2015-02-04 04:56:38 +00:00
|
|
|
(dolist (pkg update-packages)
|
2015-02-04 05:28:58 +00:00
|
|
|
(let* ((src-dir (configuration-layer//get-package-directory pkg))
|
2015-02-04 04:56:38 +00:00
|
|
|
(dest-dir (expand-file-name
|
|
|
|
(concat rollback-dir
|
|
|
|
(file-name-as-directory
|
|
|
|
(file-name-nondirectory src-dir))))))
|
|
|
|
(copy-directory src-dir dest-dir 'keeptime 'create 'copy-content)
|
|
|
|
(push (cons pkg (file-name-nondirectory src-dir))
|
|
|
|
update-packages-alist)))
|
|
|
|
(spacemacs/dump-vars-to-file
|
|
|
|
'(update-packages-alist)
|
|
|
|
(expand-file-name (concat rollback-dir
|
|
|
|
configuration-layer-rollback-info)))
|
|
|
|
(dolist (pkg update-packages)
|
2015-02-03 07:05:29 +00:00
|
|
|
(setq upgraded-count (1+ upgraded-count))
|
2015-04-12 04:24:03 +00:00
|
|
|
(spacemacs-buffer/replace-last-line
|
2015-04-03 02:23:16 +00:00
|
|
|
(format "--> preparing update of package %s... [%s/%s]"
|
2015-02-03 07:05:29 +00:00
|
|
|
pkg upgraded-count upgrade-count) t)
|
2015-02-16 02:25:12 +00:00
|
|
|
(spacemacs//redisplay)
|
2015-04-03 02:23:16 +00:00
|
|
|
(configuration-layer//package-delete pkg))
|
2015-04-12 04:24:03 +00:00
|
|
|
(spacemacs-buffer/append
|
2015-04-03 02:23:16 +00:00
|
|
|
(format "\n--> %s package(s) to be updated.\n" upgraded-count))
|
2015-04-12 04:24:03 +00:00
|
|
|
(spacemacs-buffer/append
|
2015-04-03 02:23:16 +00:00
|
|
|
"\nEmacs has to be restarted to actually install the new packages.\n")
|
2015-11-08 19:20:43 +00:00
|
|
|
(configuration-layer//cleanup-rollback-directory)
|
2015-02-16 02:25:12 +00:00
|
|
|
(spacemacs//redisplay))
|
2015-04-12 04:24:03 +00:00
|
|
|
(spacemacs-buffer/append "--> All packages are up to date.\n")
|
2015-02-16 02:25:12 +00:00
|
|
|
(spacemacs//redisplay))))
|
2014-12-28 18:46:15 +00:00
|
|
|
|
2015-02-04 04:56:38 +00:00
|
|
|
(defun configuration-layer//ido-candidate-rollback-slot ()
|
|
|
|
"Return a list of candidates to select a rollback slot."
|
|
|
|
(let ((rolldir configuration-layer-rollback-directory))
|
|
|
|
(when (file-exists-p rolldir)
|
|
|
|
(reverse
|
|
|
|
(delq nil (mapcar
|
|
|
|
(lambda (x)
|
2015-02-11 02:56:44 +00:00
|
|
|
(when (not (or (string= "." x) (string= ".." x)))
|
|
|
|
(let ((p (length (directory-files (file-name-as-directory
|
|
|
|
(concat rolldir x))))))
|
|
|
|
;; -3 for . .. and rollback-info
|
|
|
|
(format "%s (%s packages)" x (- p 3)))))
|
2015-02-04 04:56:38 +00:00
|
|
|
(directory-files rolldir)))))))
|
|
|
|
|
|
|
|
(defun configuration-layer/rollback (slot)
|
|
|
|
"Rollback all the packages in the given SLOT.
|
|
|
|
If called interactively and SLOT is nil then an ido buffers appears
|
|
|
|
to select one."
|
|
|
|
(interactive
|
|
|
|
(list
|
|
|
|
(if (boundp 'slot) slot
|
|
|
|
(let ((candidates (configuration-layer//ido-candidate-rollback-slot)))
|
|
|
|
(when candidates
|
2015-02-11 02:56:44 +00:00
|
|
|
(ido-completing-read "Rollback slots (most recent are first): "
|
2015-02-04 04:56:38 +00:00
|
|
|
candidates))))))
|
2015-04-12 04:24:03 +00:00
|
|
|
(spacemacs-buffer/insert-page-break)
|
2015-02-11 02:56:44 +00:00
|
|
|
(if (not slot)
|
|
|
|
(message "No rollback slot available.")
|
|
|
|
(string-match "^\\(.+?\\)\s.*$" slot)
|
|
|
|
(let* ((slot-dir (match-string 1 slot))
|
|
|
|
(rollback-dir (file-name-as-directory
|
|
|
|
(concat configuration-layer-rollback-directory
|
|
|
|
(file-name-as-directory slot-dir))))
|
|
|
|
(info-file (expand-file-name
|
|
|
|
(concat rollback-dir
|
|
|
|
configuration-layer-rollback-info))))
|
2015-04-12 04:24:03 +00:00
|
|
|
(spacemacs-buffer/append
|
2015-02-11 02:56:44 +00:00
|
|
|
(format "\nRollbacking ELPA packages from slot %s...\n" slot-dir))
|
|
|
|
(load-file info-file)
|
|
|
|
(let ((rollback-count (length update-packages-alist))
|
|
|
|
(rollbacked-count 0))
|
2015-04-12 04:24:03 +00:00
|
|
|
(spacemacs-buffer/append
|
2015-02-11 02:56:44 +00:00
|
|
|
(format "Found %s package(s) to rollback...\n" rollback-count))
|
2015-02-16 02:25:12 +00:00
|
|
|
(spacemacs//redisplay)
|
2015-02-11 02:56:44 +00:00
|
|
|
(dolist (apkg update-packages-alist)
|
|
|
|
(let* ((pkg (car apkg))
|
|
|
|
(pkg-dir-name (cdr apkg))
|
2015-04-08 03:51:08 +00:00
|
|
|
(installed-ver
|
|
|
|
(configuration-layer//get-package-version-string pkg))
|
2015-02-11 02:56:44 +00:00
|
|
|
(elpa-dir (concat user-emacs-directory "elpa/"))
|
|
|
|
(src-dir (expand-file-name
|
|
|
|
(concat rollback-dir (file-name-as-directory
|
|
|
|
pkg-dir-name))))
|
|
|
|
(dest-dir (expand-file-name
|
|
|
|
(concat elpa-dir (file-name-as-directory
|
|
|
|
pkg-dir-name)))))
|
|
|
|
(setq rollbacked-count (1+ rollbacked-count))
|
2015-04-08 03:51:08 +00:00
|
|
|
(if (string-equal (format "%S-%s" pkg installed-ver) pkg-dir-name)
|
2015-04-12 04:24:03 +00:00
|
|
|
(spacemacs-buffer/replace-last-line
|
2015-04-08 03:51:08 +00:00
|
|
|
(format "--> package %s already rollbacked! [%s/%s]"
|
|
|
|
pkg rollbacked-count rollback-count) t)
|
|
|
|
;; rollback the package
|
2015-04-12 04:24:03 +00:00
|
|
|
(spacemacs-buffer/replace-last-line
|
2015-04-08 03:51:08 +00:00
|
|
|
(format "--> rollbacking package %s... [%s/%s]"
|
|
|
|
pkg rollbacked-count rollback-count) t)
|
|
|
|
(configuration-layer//package-delete pkg)
|
|
|
|
(copy-directory src-dir dest-dir 'keeptime 'create 'copy-content))
|
|
|
|
(spacemacs//redisplay)))
|
2015-04-12 04:24:03 +00:00
|
|
|
(spacemacs-buffer/append
|
2015-02-11 02:56:44 +00:00
|
|
|
(format "\n--> %s packages rollbacked.\n" rollbacked-count))
|
2015-04-12 04:24:03 +00:00
|
|
|
(spacemacs-buffer/append
|
2015-02-11 02:56:44 +00:00
|
|
|
"\nEmacs has to be restarted for the changes to take effect.\n")))))
|
2015-02-04 04:56:38 +00:00
|
|
|
|
2015-01-10 05:58:27 +00:00
|
|
|
(defun configuration-layer//activate-package (pkg)
|
|
|
|
"Activate PKG."
|
2015-01-28 03:24:22 +00:00
|
|
|
(if (version< emacs-version "24.3.50")
|
2015-01-10 05:58:27 +00:00
|
|
|
;; fake version list to always activate the package
|
|
|
|
(package-activate pkg '(0 0 0 0))
|
|
|
|
(package-activate pkg)))
|
|
|
|
|
2015-07-26 04:41:41 +00:00
|
|
|
(defun configuration-layer/get-layers-list ()
|
|
|
|
"Return a list of all discovered layer symbols."
|
|
|
|
(ht-keys configuration-layer-paths))
|
|
|
|
|
|
|
|
(defun configuration-layer/get-layer-property (layer slot)
|
|
|
|
"Return the value of SLOT for the given LAYER."
|
2015-08-26 02:52:26 +00:00
|
|
|
(slot-value (object-assoc layer :name configuration-layer--layers) slot))
|
2015-07-26 04:41:41 +00:00
|
|
|
|
2015-08-13 13:02:03 +00:00
|
|
|
(defun configuration-layer/get-layer-local-dir (layer)
|
|
|
|
"Return the value of SLOT for the given LAYER."
|
2015-08-26 02:52:26 +00:00
|
|
|
(concat (slot-value (object-assoc layer :name configuration-layer--layers)
|
2015-08-13 13:02:03 +00:00
|
|
|
:dir) "local/"))
|
|
|
|
|
2015-07-26 04:41:41 +00:00
|
|
|
(defun configuration-layer/get-layer-path (layer)
|
|
|
|
"Return the path for LAYER symbol."
|
|
|
|
(ht-get configuration-layer-paths layer))
|
2014-10-21 05:41:33 +00:00
|
|
|
|
2015-09-18 03:05:32 +00:00
|
|
|
(defun configuration-layer//get-packages-dependencies ()
|
2015-08-09 04:21:18 +00:00
|
|
|
"Returns dependencies hash map for all packages in `package-alist'."
|
2015-05-20 06:05:58 +00:00
|
|
|
(let ((result (make-hash-table :size 512)))
|
2014-10-21 05:41:33 +00:00
|
|
|
(dolist (pkg package-alist)
|
|
|
|
(let* ((pkg-sym (car pkg))
|
2015-09-18 03:05:32 +00:00
|
|
|
(deps (configuration-layer//get-package-deps-from-alist pkg-sym)))
|
2014-10-21 05:41:33 +00:00
|
|
|
(dolist (dep deps)
|
|
|
|
(let* ((dep-sym (car dep))
|
|
|
|
(value (ht-get result dep-sym)))
|
|
|
|
(puthash dep-sym
|
|
|
|
(if value (add-to-list 'value pkg-sym) (list pkg-sym))
|
|
|
|
result)))))
|
|
|
|
result))
|
|
|
|
|
2015-08-09 04:21:18 +00:00
|
|
|
(defun configuration-layer//get-implicit-packages (packages)
|
|
|
|
"Returns packages in `packages-alist' which are not found in PACKAGES."
|
|
|
|
(let (imp-pkgs)
|
2014-10-21 05:41:33 +00:00
|
|
|
(dolist (pkg package-alist)
|
|
|
|
(let ((pkg-sym (car pkg)))
|
2015-08-09 04:21:18 +00:00
|
|
|
(unless (object-assoc pkg-sym :name packages)
|
2015-08-08 04:01:36 +00:00
|
|
|
(add-to-list 'imp-pkgs pkg-sym))))
|
2014-10-21 05:41:33 +00:00
|
|
|
imp-pkgs))
|
|
|
|
|
2015-08-26 02:52:26 +00:00
|
|
|
(defun configuration-layer//get-orphan-packages
|
|
|
|
(dist-pkgs implicit-pkgs dependencies)
|
2015-08-09 04:21:18 +00:00
|
|
|
"Return orphan packages."
|
|
|
|
(let (result)
|
2014-10-21 05:41:33 +00:00
|
|
|
(dolist (imp-pkg implicit-pkgs)
|
2015-08-26 02:52:26 +00:00
|
|
|
(when (configuration-layer//is-package-orphan
|
|
|
|
imp-pkg dist-pkgs dependencies)
|
2015-08-09 04:21:18 +00:00
|
|
|
(add-to-list 'result imp-pkg)))
|
2014-11-11 05:09:52 +00:00
|
|
|
result))
|
|
|
|
|
2015-08-26 02:52:26 +00:00
|
|
|
(defun configuration-layer//is-package-orphan (pkg-name dist-pkgs dependencies)
|
2015-08-09 04:21:18 +00:00
|
|
|
"Returns not nil if PKG-NAME is the name of an orphan package."
|
2015-11-04 13:21:36 +00:00
|
|
|
(unless (or (object-assoc pkg-name :name dist-pkgs)
|
|
|
|
(memq pkg-name configuration-layer--protected-packages))
|
2015-08-09 04:21:18 +00:00
|
|
|
(if (ht-contains? dependencies pkg-name)
|
|
|
|
(let ((parents (ht-get dependencies pkg-name)))
|
2014-11-15 04:54:08 +00:00
|
|
|
(reduce (lambda (x y) (and x y))
|
2014-12-25 19:45:27 +00:00
|
|
|
(mapcar (lambda (p) (configuration-layer//is-package-orphan
|
2015-08-26 02:52:26 +00:00
|
|
|
p dist-pkgs dependencies))
|
2014-11-15 04:54:08 +00:00
|
|
|
parents)
|
|
|
|
:initial-value t))
|
2015-08-26 02:52:26 +00:00
|
|
|
(not (object-assoc pkg-name :name dist-pkgs)))))
|
2014-10-21 05:41:33 +00:00
|
|
|
|
2015-08-09 04:27:21 +00:00
|
|
|
(defun configuration-layer//get-package-directory (pkg-name)
|
|
|
|
"Return the directory path for package with name PKG-NAME."
|
|
|
|
(let ((pkg-desc (assq pkg-name package-alist)))
|
2014-10-25 02:39:03 +00:00
|
|
|
(cond
|
2015-02-04 05:28:58 +00:00
|
|
|
((version< emacs-version "24.3.50")
|
|
|
|
(let* ((version (aref (cdr pkg-desc) 0))
|
|
|
|
(elpa-dir (concat user-emacs-directory "elpa/"))
|
|
|
|
(pkg-dir-name (format "%s-%s.%s"
|
2015-08-09 04:27:21 +00:00
|
|
|
(symbol-name pkg-name)
|
2015-02-04 05:28:58 +00:00
|
|
|
(car version)
|
|
|
|
(cadr version))))
|
|
|
|
(expand-file-name (concat elpa-dir pkg-dir-name))))
|
|
|
|
(t (package-desc-dir (cadr pkg-desc))))))
|
|
|
|
|
2015-09-18 03:05:32 +00:00
|
|
|
(defun configuration-layer//get-package-deps-from-alist (pkg-name)
|
2015-08-09 04:27:21 +00:00
|
|
|
"Return the dependencies alist for package with name PKG-NAME."
|
|
|
|
(let ((pkg-desc (assq pkg-name package-alist)))
|
2015-09-18 03:05:32 +00:00
|
|
|
(when pkg-desc
|
|
|
|
(cond
|
|
|
|
((version< emacs-version "24.3.50") (aref (cdr pkg-desc) 1))
|
|
|
|
(t (package-desc-reqs (cadr pkg-desc)))))))
|
2014-10-25 02:39:03 +00:00
|
|
|
|
2015-08-09 03:16:56 +00:00
|
|
|
(defun configuration-layer//get-package-deps-from-archive (pkg-name)
|
|
|
|
"Return the dependencies alist for a PKG-NAME from the archive data."
|
|
|
|
(let* ((pkg-arch (assq pkg-name package-archive-contents))
|
2015-02-04 05:28:58 +00:00
|
|
|
(reqs (when pkg-arch (if (version< emacs-version "24.3.50")
|
|
|
|
(aref (cdr pkg-arch) 1)
|
|
|
|
(package-desc-reqs (cadr pkg-arch))))))
|
2015-01-10 06:55:36 +00:00
|
|
|
;; recursively get the requirements of reqs
|
|
|
|
(dolist (req reqs)
|
2015-08-09 03:16:56 +00:00
|
|
|
(let* ((pkg-name2 (car req))
|
|
|
|
(reqs2 (configuration-layer//get-package-deps-from-archive
|
|
|
|
pkg-name2)))
|
2015-01-10 06:55:36 +00:00
|
|
|
(when reqs2 (setq reqs (append reqs2 reqs)))))
|
|
|
|
reqs))
|
2015-01-10 05:58:27 +00:00
|
|
|
|
2015-08-09 04:27:21 +00:00
|
|
|
(defun configuration-layer//get-package-version-string (pkg-name)
|
|
|
|
"Return the version string for package with name PKG-NAME."
|
|
|
|
(let ((pkg-desc (assq pkg-name package-alist)))
|
2015-02-04 05:28:58 +00:00
|
|
|
(when pkg-desc
|
2015-02-03 05:57:55 +00:00
|
|
|
(cond
|
2015-02-09 04:03:52 +00:00
|
|
|
((version< emacs-version "24.3.50") (package-version-join
|
|
|
|
(aref (cdr pkg-desc) 0)))
|
2015-02-04 05:28:58 +00:00
|
|
|
(t (package-version-join (package-desc-version (cadr pkg-desc))))))))
|
2014-12-28 18:46:15 +00:00
|
|
|
|
2015-08-09 04:27:21 +00:00
|
|
|
(defun configuration-layer//get-package-version (pkg-name)
|
|
|
|
"Return the version list for package with name PKG-NAME."
|
|
|
|
(let ((version-string (configuration-layer//get-package-version-string pkg-name)))
|
2015-02-09 04:03:52 +00:00
|
|
|
(unless (string-empty-p version-string)
|
|
|
|
(version-to-list version-string))))
|
|
|
|
|
2015-08-09 04:27:21 +00:00
|
|
|
(defun configuration-layer//get-latest-package-version-string (pkg-name)
|
|
|
|
"Return the version string for package with name PKG-NAME."
|
|
|
|
(let ((pkg-arch (assq pkg-name package-archive-contents)))
|
2015-02-04 05:28:58 +00:00
|
|
|
(when pkg-arch
|
2015-02-03 05:57:55 +00:00
|
|
|
(cond
|
2015-02-09 04:03:52 +00:00
|
|
|
((version< emacs-version "24.3.50") (package-version-join
|
|
|
|
(aref (cdr pkg-arch) 0)))
|
2015-02-04 05:28:58 +00:00
|
|
|
(t (package-version-join (package-desc-version (cadr pkg-arch))))))))
|
2014-10-25 02:39:03 +00:00
|
|
|
|
2015-08-09 04:27:21 +00:00
|
|
|
(defun configuration-layer//get-latest-package-version (pkg-name)
|
|
|
|
"Return the versio list for package with name PKG-NAME."
|
2015-02-11 02:57:14 +00:00
|
|
|
(let ((version-string
|
2015-08-09 04:27:21 +00:00
|
|
|
(configuration-layer//get-latest-package-version-string pkg-name)))
|
2015-02-09 04:03:52 +00:00
|
|
|
(unless (string-empty-p version-string)
|
|
|
|
(version-to-list version-string))))
|
|
|
|
|
2015-08-09 04:21:18 +00:00
|
|
|
(defun configuration-layer//package-delete (pkg-name)
|
|
|
|
"Delete package with name PKG-NAME."
|
2014-10-25 02:39:03 +00:00
|
|
|
(cond
|
2015-01-28 03:24:22 +00:00
|
|
|
((version< emacs-version "24.3.50")
|
2015-08-09 04:21:18 +00:00
|
|
|
(let ((v (configuration-layer//get-package-version-string pkg-name)))
|
|
|
|
(when v (package-delete (symbol-name pkg-name) v))))
|
2015-08-14 15:28:14 +00:00
|
|
|
((version<= "25.0.50" emacs-version)
|
|
|
|
(let ((p (cadr (assq pkg-name package-alist))))
|
|
|
|
;; add force flag to ignore dependency checks in Emacs25
|
2015-09-14 12:52:20 +00:00
|
|
|
(when p (package-delete p t t))))
|
2015-08-09 04:21:18 +00:00
|
|
|
(t (let ((p (cadr (assq pkg-name package-alist))))
|
2015-02-11 02:57:14 +00:00
|
|
|
(when p (package-delete p))))))
|
2014-10-21 05:41:33 +00:00
|
|
|
|
2015-08-09 04:21:18 +00:00
|
|
|
(defun configuration-layer/delete-orphan-packages (packages)
|
|
|
|
"Delete PACKAGES if they are orphan."
|
2014-10-21 05:41:33 +00:00
|
|
|
(interactive)
|
2015-09-18 03:05:32 +00:00
|
|
|
(let* ((dependencies (configuration-layer//get-packages-dependencies))
|
2015-08-09 04:21:18 +00:00
|
|
|
(implicit-packages (configuration-layer//get-implicit-packages
|
2015-08-26 02:52:26 +00:00
|
|
|
configuration-layer--used-distant-packages))
|
2015-11-04 13:21:36 +00:00
|
|
|
(orphans (configuration-layer//get-orphan-packages
|
|
|
|
configuration-layer--used-distant-packages
|
|
|
|
implicit-packages
|
|
|
|
dependencies))
|
2014-10-21 05:41:33 +00:00
|
|
|
(orphans-count (length orphans)))
|
2014-11-15 04:54:08 +00:00
|
|
|
;; (message "dependencies: %s" dependencies)
|
|
|
|
;; (message "implicit: %s" implicit-packages)
|
|
|
|
;; (message "orphans: %s" orphans)
|
2014-10-21 19:43:08 +00:00
|
|
|
(if orphans
|
|
|
|
(progn
|
2015-04-12 04:24:03 +00:00
|
|
|
(spacemacs-buffer/append
|
2014-10-21 19:43:08 +00:00
|
|
|
(format "Found %s orphan package(s) to delete...\n"
|
|
|
|
orphans-count))
|
|
|
|
(setq deleted-count 0)
|
|
|
|
(dolist (orphan orphans)
|
|
|
|
(setq deleted-count (1+ deleted-count))
|
2015-04-12 04:24:03 +00:00
|
|
|
(spacemacs-buffer/replace-last-line
|
2014-10-21 19:43:08 +00:00
|
|
|
(format "--> deleting %s... [%s/%s]"
|
|
|
|
orphan
|
|
|
|
deleted-count
|
|
|
|
orphans-count) t)
|
2014-12-25 19:45:27 +00:00
|
|
|
(configuration-layer//package-delete orphan)
|
2015-02-16 02:25:12 +00:00
|
|
|
(spacemacs//redisplay))
|
2015-04-12 04:24:03 +00:00
|
|
|
(spacemacs-buffer/append "\n"))
|
|
|
|
(spacemacs-buffer/message "No orphan package to delete."))))
|
2014-10-24 03:07:40 +00:00
|
|
|
|
2015-03-16 05:28:21 +00:00
|
|
|
(defun configuration-layer//set-error ()
|
|
|
|
"Set the error flag and change the mode-line color to red."
|
|
|
|
(if configuration-layer-error-count
|
|
|
|
(setq configuration-layer-error-count
|
|
|
|
(1+ configuration-layer-error-count))
|
|
|
|
(face-remap-add-relative 'mode-line '((:background "red") mode-line))
|
|
|
|
(setq configuration-layer-error-count 1)))
|
|
|
|
|
2015-01-27 03:51:47 +00:00
|
|
|
(provide 'core-configuration-layer)
|
2015-08-06 03:39:39 +00:00
|
|
|
|
|
|
|
;;; core-configuration-layer.el ends here
|
|
|
|
|