Add pre and post init functions support to configuration-layers

Now in addition to the <layer>/init-<pkg> function there are
- <layer>/pre-init-<pkg> (executed before <layer>/init-<pkg>)
- <layer>/post-init-<pkg> (executed after <layer>/init-<pkg>)

The init function is mandatory, if it is not present then the
package is ignored and not installed.

This mechanism allows soft (implicit) cross layers dependencies
between packages (see company for more info).

It is now possible to remove flycheck from spacemacs layer and
move it to its own syntax-checking layer.
This commit is contained in:
syl20bnr 2015-04-03 17:12:56 -04:00
parent 9f3f2b9741
commit 318bd23dc4
17 changed files with 284 additions and 238 deletions

View File

@ -12,4 +12,7 @@
;; variables
(spacemacs|init-company-backends c-c++)
(when (configuration-layer/layer-declaredp 'auto-completion)
(spacemacs|init-company-backends c-c++)
(spacemacs|init-company-backends cmake-mode))

View File

@ -46,65 +46,10 @@ which require an initialization must be listed explicitly in the list.")
(defun c-c++/init-cmake-mode ()
(use-package cmake-mode
:defer t
:mode (("CMakeLists\\.txt\\'" . cmake-mode) ("\\.cmake\\'" . cmake-mode))
:init
;; lower priority for this backend, we append it
(add-to-list 'company-backends-c-c++ 'company-cmake 'append)))
(defun c-c++/init-company ()
;; push this backend by default
(push '(company-clang :with company-yasnippet) company-backends-c-c++)
(spacemacs|enable-company c-c++ c-common-mode-hook)
;; .clang_complete file loading
;; Sets the arguments for company-clang based on a project-specific text file.
;; START Based on the Sarcasm/irony-mode compilation database code.
(defun company-mode/find-clang-complete-file ()
(when buffer-file-name
(let ((dir (locate-dominating-file buffer-file-name ".clang_complete")))
(when dir
(concat (file-name-as-directory dir) ".clang_complete")))))
(defun company-mode/load-clang-complete-file (cc-file)
"Load the flags from CC-FILE, one flag per line."
(let ((invocation-dir (expand-file-name (file-name-directory cc-file)))
(case-fold-search nil)
compile-flags)
(with-temp-buffer
(insert-file-contents cc-file)
;; Replace relative paths with absolute paths (by @trishume)
;; (goto-char (point-min))
(while (re-search-forward "\\(-I\\|-isystem\n\\)\\(\\S-\\)" nil t)
(replace-match (format "%s%s" (match-string 1)
(expand-file-name (match-string 2) invocation-dir))))
;; Turn lines into a list
(setq compile-flags
;; remove whitespaces at the end of each line, if any
(mapcar #'(lambda (line)
(if (string-match "[ \t]+$" line)
(replace-match "" t t line)
line))
(split-string (buffer-string) "\n" t))))
compile-flags))
;; END Back to things written by @trishume
(defun company-mode/more-than-prefix-guesser ()
(unless company-clang-arguments
(let* ((cc-file (company-mode/find-clang-complete-file))
(flags (if cc-file (company-mode/load-clang-complete-file cc-file) '())))
(setq-local company-clang-arguments flags)
(setq flycheck-clang-args flags)))
(company-clang-guess-prefix))
(setq company-clang-prefix-guesser 'company-mode/more-than-prefix-guesser))
(defun c-c++/init-company-c-headers ()
(use-package company-c-headers
:if (configuration-layer/layer-declaredp 'auto-completion)
:defer t
:init (push 'company-c-headers company-backends-c-c++)))
:config
(when (configuration-layer/layer-declaredp 'auto-completion)
(push 'company-cmake company-backends-cmake-mode))))
(defun c-c++/init-flycheck ()
(add-to-hooks 'flycheck-mode '(c-mode-hook c++-mode-hook)))
@ -129,3 +74,57 @@ which require an initialization must be listed explicitly in the list.")
(require 'stickyfunc-enhance))
(add-to-hooks 'spacemacs/lazy-load-stickyfunc-enhance
'(c-mode-hook c++-mode-hook)))))
(when (configuration-layer/layer-declaredp 'auto-completion)
(defun c-c++/post-init-company ()
;; push this backend by default
(push '(company-clang :with company-yasnippet) company-backends-c-c++)
(spacemacs|enable-company c-c++ c-common-mode-hook)
;; .clang_complete file loading
;; Sets the arguments for company-clang based on a project-specific text file.
;; START Based on the Sarcasm/irony-mode compilation database code.
(defun company-mode/find-clang-complete-file ()
(when buffer-file-name
(let ((dir (locate-dominating-file buffer-file-name ".clang_complete")))
(when dir
(concat (file-name-as-directory dir) ".clang_complete")))))
(defun company-mode/load-clang-complete-file (cc-file)
"Load the flags from CC-FILE, one flag per line."
(let ((invocation-dir (expand-file-name (file-name-directory cc-file)))
(case-fold-search nil)
compile-flags)
(with-temp-buffer
(insert-file-contents cc-file)
;; Replace relative paths with absolute paths (by @trishume)
;; (goto-char (point-min))
(while (re-search-forward "\\(-I\\|-isystem\n\\)\\(\\S-\\)" nil t)
(replace-match (format "%s%s" (match-string 1)
(expand-file-name (match-string 2) invocation-dir))))
;; Turn lines into a list
(setq compile-flags
;; remove whitespaces at the end of each line, if any
(mapcar #'(lambda (line)
(if (string-match "[ \t]+$" line)
(replace-match "" t t line)
line))
(split-string (buffer-string) "\n" t))))
compile-flags))
;; END Back to things written by @trishume
(defun company-mode/more-than-prefix-guesser ()
(unless company-clang-arguments
(let* ((cc-file (company-mode/find-clang-complete-file))
(flags (if cc-file (company-mode/load-clang-complete-file cc-file) '())))
(setq-local company-clang-arguments flags)
(setq flycheck-clang-args flags)))
(company-clang-guess-prefix))
(setq company-clang-prefix-guesser 'company-mode/more-than-prefix-guesser))
(defun c-c++/init-company-c-headers ()
(use-package company-c-headers
:defer t
:init (push 'company-c-headers company-backends-c-c++))))

View File

@ -12,4 +12,5 @@
;; variables
(spacemacs|init-company-backends csharp-mode)
(when (configuration-layer/layer-declaredp 'auto-completion)
(spacemacs|init-company-backends csharp-mode))

View File

@ -17,9 +17,6 @@
(defvar csharp-excluded-packages '()
"List of packages to exclude.")
(defun csharp/init-company ()
(spacemacs|enable-company csharp-mode))
(defun csharp/init-omnisharp ()
;; Load omnisharp-mode with csharp-mode, this should start the omnisharp server automatically
(add-hook 'csharp-mode-hook 'omnisharp-mode)
@ -65,3 +62,7 @@
"mu" 'omnisharp-auto-complete-overrides
"mi" 'omnisharp-fix-usings
"m=" 'omnisharp-code-format)))
(when (configuration-layer/layer-declaredp 'auto-completion)
(defun csharp/post-init-company ()
(spacemacs|enable-company csharp-mode)))

View File

@ -12,7 +12,8 @@
;; Variables
(spacemacs|init-company-backends ess-mode)
(when (configuration-layer/layer-declaredp 'auto-completion)
(spacemacs|init-company-backends ess-mode))
(defvar ess-enable-smart-equals t
"If non-nil smart-equal support is enabled")

View File

@ -26,16 +26,6 @@ which require an initialization must be listed explicitly in the list.")
(defvar ess-excluded-packages '()
"List of packages to exclude.")
(defun ess/init-company ()
(spacemacs|enable-company ess-mode))
(defun ess/init-company-ess ()
(use-package company-ess
:if (configuration-layer/layer-declaredp 'auto-completion)
:defer t
:init (push '(company-ess-backend :with company-yasnippet)
company-backends-ess-mode)))
(defun ess/init-ess ()
;; ESS is not quick to load so we just load it when
;; we need it (see my-keybindings.el for the associated
@ -148,3 +138,13 @@ not play nicely with autoloads"
(progn
(add-hook 'ess-mode-hook 'ess-smart-equals-mode)
(add-hook 'inferior-ess-mode-hook 'ess-smart-equals-mode))))
(when (configuration-layer/layer-declaredp 'auto-completion)
(defun ess/post-init-company ()
(spacemacs|enable-company ess-mode))
(defun ess/init-company-ess ()
(use-package company-ess
:defer t
:init (push '(company-ess-backend :with company-yasnippet)
company-backends-ess-mode))))

View File

@ -12,4 +12,5 @@
;; variables
(spacemacs|init-company-backends go-mode)
(when (configuration-layer/layer-declaredp 'auto-completion)
(spacemacs|init-company-backends go-mode))

View File

@ -10,9 +10,6 @@
"List of all packages to install and/or initialize. Built-in packages
which require an initialization must be listed explicitly in the list.")
(defun go/init-company ()
(spacemacs|enable-company go-mode))
(defun go/init-flycheck ()
(add-hook 'go-mode-hook 'flycheck-mode))
@ -38,12 +35,14 @@ which require an initialization must be listed explicitly in the list.")
(use-package go-autocomplete
:if (boundp 'ac-sources)
:defer t
:init (add-to-list 'ac-sources 'ac-source-go)
)
)
(defun go/init-company-go ()
(use-package company-go
:if (configuration-layer/layer-declaredp 'auto-completion)
:defer t
:init (push '(company-go :with company-yasnippet)
company-backends-go-mode)))
:init (add-to-list 'ac-sources 'ac-source-go)))
(when (configuration-layer/layer-declaredp 'auto-completion)
(defun go/post-init-company ()
(spacemacs|enable-company go-mode))
(defun go/init-company-go ()
(use-package company-go
:defer t
:init (push '(company-go :with company-yasnippet)
company-backends-go-mode))))

View File

@ -11,7 +11,8 @@
;; Variables
(spacemacs|init-company-backends haskell-mode)
(when (configuration-layer/layer-declaredp 'auto-completion)
(spacemacs|init-company-backends haskell-mode))
(defvar haskell-enable-ghci-ng-support nil
"If non-nil ghci-ng support is enabled")

View File

@ -18,21 +18,10 @@
flycheck-haskell
ghc
haskell-mode
;; hi2
hindent
shm
))
(defun haskell/init-company ()
(spacemacs|enable-company haskell-mode))
(defun haskell/init-company-ghc ()
(use-package company-ghc
:if (configuration-layer/layer-declaredp 'auto-completion)
:defer t
:init (push '(company-ghc :with company-yasnippet)
company-backends-haskell-mode)))
(defun haskell/init-flycheck ()
(add-hook 'haskell-mode-hook 'flycheck-mode))
@ -41,53 +30,7 @@
:commands flycheck-haskell-configure
:init (add-hook 'flycheck-mode-hook 'flycheck-haskell-configure)))
(defun haskell/init-shm ()
(use-package shm
:defer t
:if haskell-enable-shm-support
:init
(add-hook 'haskell-mode-hook 'structured-haskell-mode)
:config
(progn
(when (require 'shm-case-split nil 'noerror)
;;TODO: Find some better bindings for case-splits
(define-key shm-map (kbd "C-c S") 'shm/case-split)
(define-key shm-map (kbd "C-c C-s") 'shm/do-case-split))
(evil-define-key 'normal shm-map
(kbd "RET") nil
(kbd "C-k") nil
(kbd "C-j") nil
(kbd "D") 'shm/kill-line
(kbd "R") 'shm/raise
(kbd "P") 'shm/yank
(kbd "RET") 'shm/newline-indent
(kbd "RET") 'shm/newline-indent
(kbd "M-RET") 'evil-ret
)
(evil-define-key 'operator map
(kbd ")") 'shm/forward-node
(kbd "(") 'shm/backward-node)
(evil-define-key 'motion map
(kbd ")") 'shm/forward-node
(kbd "(") 'shm/backward-node)
(define-key shm-map (kbd "C-j") nil)
(define-key shm-map (kbd "C-k") nil))))
(defun haskell/init-hindent ()
(use-package hindent
:defer t
:if (stringp haskell-enable-hindent-style)
:init
(add-hook 'haskell-mode-hook #'hindent-mode)
:config
(progn
(setq hindent-style haskell-enable-hindent-style)
(evil-leader/set-key-for-mode 'haskell-mode
"mF" 'hindent/reformat-decl))))
(defun haskell/init-ghc ())
(defun haskell/init-haskell-mode ()
(require 'haskell-yas)
@ -228,3 +171,60 @@
'(define-key haskell-cabal-mode-map
[?\C-c ?\C-z] 'haskell-interactive-switch)))))
(defun haskell/init-hindent ()
(use-package hindent
:defer t
:if (stringp haskell-enable-hindent-style)
:init
(add-hook 'haskell-mode-hook #'hindent-mode)
:config
(progn
(setq hindent-style haskell-enable-hindent-style)
(evil-leader/set-key-for-mode 'haskell-mode
"mF" 'hindent/reformat-decl))))
(defun haskell/init-shm ()
(use-package shm
:defer t
:if haskell-enable-shm-support
:init
(add-hook 'haskell-mode-hook 'structured-haskell-mode)
:config
(progn
(when (require 'shm-case-split nil 'noerror)
;;TODO: Find some better bindings for case-splits
(define-key shm-map (kbd "C-c S") 'shm/case-split)
(define-key shm-map (kbd "C-c C-s") 'shm/do-case-split))
(evil-define-key 'normal shm-map
(kbd "RET") nil
(kbd "C-k") nil
(kbd "C-j") nil
(kbd "D") 'shm/kill-line
(kbd "R") 'shm/raise
(kbd "P") 'shm/yank
(kbd "RET") 'shm/newline-indent
(kbd "RET") 'shm/newline-indent
(kbd "M-RET") 'evil-ret
)
(evil-define-key 'operator map
(kbd ")") 'shm/forward-node
(kbd "(") 'shm/backward-node)
(evil-define-key 'motion map
(kbd ")") 'shm/forward-node
(kbd "(") 'shm/backward-node)
(define-key shm-map (kbd "C-j") nil)
(define-key shm-map (kbd "C-k") nil))))
(when (configuration-layer/layer-declaredp 'auto-completion)
(defun haskell/post-init-company ()
(spacemacs|enable-company haskell-mode))
(defun haskell/init-company-ghc ()
(use-package company-ghc
:defer t
:init (push '(company-ghc :with company-yasnippet)
company-backends-haskell-mode))))

View File

@ -12,4 +12,6 @@
;; Variables
(spacemacs|init-company-backends js2-mode)
(when (configuration-layer/layer-declaredp 'auto-completion)
(spacemacs|init-company-backends js2-mode))

View File

@ -40,16 +40,6 @@ which require an initialization must be listed explicitly in the list.")
(add-hook 'coffee-mode-hook '(lambda ()
(setq indent-line-function 'javascript/coffee-indent
evil-shift-width coffee-tab-width))))))
(defun javascript/init-company ()
(spacemacs|enable-company js2-mode))
(defun javascript/init-company-tern ()
(use-package company-tern
:if (and (configuration-layer/package-declaredp 'tern)
(configuration-layer/layer-declaredp 'auto-completion))
:defer t
:init (push '(company-tern :with company-yasnippet)
company-backends-js2-mode)))
(defun javascript/init-flycheck ()
(add-hook 'coffee-mode-hook 'flycheck-mode)
@ -164,3 +154,14 @@ which require an initialization must be listed explicitly in the list.")
(evil-leader/set-key-for-mode 'js2-mode "mgG" 'tern-find-definition-by-name)
(evil-leader/set-key-for-mode 'js2-mode (kbd "m C-g") 'tern-pop-find-definition)
(evil-leader/set-key-for-mode 'js2-mode "mt" 'tern-get-type))))
(when (configuration-layer/layer-declaredp 'auto-completion)
(defun javascript/post-init-company ()
(spacemacs|enable-company js2-mode))
(defun javascript/init-company-tern ()
(use-package company-tern
:if (configuration-layer/package-declaredp 'tern)
:defer t
:init (push '(company-tern :with company-yasnippet)
company-backends-js2-mode))))

View File

@ -12,7 +12,8 @@
;; variables
(spacemacs|init-company-backends python-mode)
(when (configuration-layer/layer-declaredp 'auto-completion)
(spacemacs|init-company-backends python-mode))
;; Command prefixes

View File

@ -55,20 +55,6 @@ which require an initialization must be listed explicitly in the list.")
"mgg" 'anaconda-mode-goto)
(spacemacs|hide-lighter anaconda-mode))))
(defun python/init-company ()
(spacemacs|enable-company python-mode))
(defun python/init-company-anaconda ()
(use-package company-anaconda
:if (configuration-layer/layer-declaredp 'auto-completion)
:defer t
:init
;; we don't use the yasnippet backend here because it
;; produces some weird bug in company-anaconda back end
;; (like the f, s, v suffix being at the wrong place in the
;; completion menu)
(push 'company-anaconda company-backends-python-mode)))
(defun python/init-cython-mode ()
(use-package cython-mode
:defer t
@ -270,3 +256,17 @@ which require an initialization must be listed explicitly in the list.")
(if pythonp
ad-do-it
(call-interactively 'sp-backward-delete-char)))))
(when (configuration-layer/layer-declaredp 'auto-completion)
(defun python/post-init-company ()
(spacemacs|enable-company python-mode))
(defun python/init-company-anaconda ()
(use-package company-anaconda
:defer t
:init
;; we don't use the yasnippet backend here because it
;; produces some weird bug in company-anaconda back end
;; (like the f, s, v suffix being at the wrong place in the
;; completion menu)
(push 'company-anaconda company-backends-python-mode))))

View File

@ -56,11 +56,11 @@ installation of initialization.")
(defvar configuration-layer-layers '()
"Alist of declared configuration layers.")
(defvar configuration-layer-paths (make-hash-table :size 128)
(defvar configuration-layer-paths (make-hash-table :size 256)
"Hash table of layers locations. The key is a layer symbol and the value is
the path for this layer.")
(defvar configuration-layer-all-packages (make-hash-table :size 256)
(defvar configuration-layer-all-packages (make-hash-table :size 512)
"Hash table of all declared packages in all layers where the key is a package
symbol and the value is a list of layer symbols responsible for initializing
and configuring the package.")
@ -68,7 +68,11 @@ and configuring the package.")
(defvar configuration-layer-all-packages-sorted '()
"Sorted list of all package symbols.")
(defvar configuration-layer-all-pre-extensions (make-hash-table :size 128)
(defvar configuration-layer-packages-init-funcs '(make-hash-table :size 512)
"Hash table of packages initialization functions. The key is a package symbol
and the value is an odered list of initialization functions to execute.")
(defvar configuration-layer-all-pre-extensions (make-hash-table :size 256)
"Hash table of all declared pre-extensions in all layers where the key is a
extension symbol and the value is the layer symbols responsible for initializing
and configuring the package.")
@ -76,11 +80,19 @@ and configuring the package.")
(defvar configuration-layer-all-pre-extensions-sorted '()
"Sorted list of all pre extensions symbols.")
(defvar configuration-layer-all-post-extensions (make-hash-table :size 128)
(defvar configuration-layer-pre-extensions-init-funcs '(make-hash-table :size 256)
"Hash table of pre-extensions initialization functions. The key is a package
symbol and the value is an odered list of initialization functions to execute.")
(defvar configuration-layer-all-post-extensions (make-hash-table :size 256)
"Hash table of all declared post-extensions in all layers where the key is a
extension symbol and the value is the layer symbols responsible for initializing
and configuring the package.")
(defvar configuration-layer-post-extensions-init-funcs '(make-hash-table :size 256)
"Hash table of post-extensions initialization functions. The key is a package
symbol and the value is an odered list of initialization functions to execute.")
(defvar configuration-layer-all-post-extensions-sorted '()
"Sorted list of all post extensions symbols.")
@ -151,7 +163,7 @@ in `configuration-layer-contrib-categories'"
"Return a hash table where the key is the layer symbol and the value is its
path."
(let ((cat-dirs (configuration-layer//get-contrib-category-dirs))
(result (make-hash-table :size 128)))
(result (make-hash-table :size 256)))
;; add spacemacs layer
(puthash 'spacemacs (expand-file-name user-emacs-directory) result)
(mapc (lambda (dir)
@ -274,19 +286,26 @@ the following keys:
(configuration-layer//filter-out-excluded configuration-layer-all-packages excluded)
(configuration-layer//filter-out-excluded configuration-layer-all-pre-extensions excluded)
(configuration-layer//filter-out-excluded configuration-layer-all-post-extensions excluded))
(setq configuration-layer-packages-init-funcs
(configuration-layer//filter-init-funcs configuration-layer-all-packages))
(setq configuration-layer-pre-extensions-init-funcs
(configuration-layer//filter-init-funcs configuration-layer-all-pre-extensions t))
(setq configuration-layer-post-extensions-init-funcs
(configuration-layer//filter-init-funcs configuration-layer-all-post-extensions t))
;; (message "package init-funcs: %s" configuration-layer-packages-init-funcs)
;; number of chuncks for the loading screen
(let ((total (+ (ht-size configuration-layer-all-packages)
(ht-size configuration-layer-all-pre-extensions)
(ht-size configuration-layer-all-post-extensions))))
(setq spacemacs-loading-dots-chunk-threshold
(/ total spacemacs-loading-dots-chunk-count)))
;; filter them
;; sort packages before initializing them
(configuration-layer//sort-packages-and-extensions)
;; install and initialize packages and extensions
(configuration-layer//initialize-extensions configuration-layer-all-pre-extensions-sorted t)
(configuration-layer//initialize-pre-extensions)
(configuration-layer//install-packages)
(configuration-layer//initialize-packages)
(configuration-layer//initialize-extensions configuration-layer-all-post-extensions-sorted)
(configuration-layer//initialize-post-extensions)
;; restore warning level before initialization
(setq warning-minimum-level :warning)
(configuration-layer//load-layers-files layers '("keybindings.el"))))
@ -310,10 +329,40 @@ the following keys:
(eval `(push ',layer list))
(puthash pkg list hash)))
(defsubst configuration-layer//filter-out-excluded (hash excluded)
(defun configuration-layer//filter-out-excluded (hash excluded)
"Remove EXCLUDED packages from the hash tables HASH."
(dolist (pkg (ht-keys (eval hash)))
(when (or (member pkg excluded)) (ht-remove (eval hash) pkg))))
(dolist (pkg (ht-keys hash))
(when (or (member pkg excluded)) (ht-remove hash pkg))))
(defun configuration-layer//filter-init-funcs (hash &optional extension-p)
"Remove from HASH packages with no corresponding initialization function and
returns a hash table of package symbols mapping to a list of initialization
functions to execute."
(let ((result (make-hash-table :size 512)))
(dolist (pkg (ht-keys hash))
(let (initlayer prefuncs initfuncs postfuncs)
(dolist (layer (ht-get hash pkg))
(let ((initf (intern (format "%s/init-%S" layer pkg)))
(pref (intern (format "%s/pre-init-%S" layer pkg)))
(postf (intern (format "%s/post-init-%S" layer pkg))))
(when (fboundp initf)
(setq initlayer layer)
(push initf initfuncs))
(when (fboundp pref) (push pref prefuncs))
(when (fboundp postf) (push postf postfuncs))))
(if initfuncs
(progn
(puthash pkg (append prefuncs initfuncs postfuncs) result)
(when extension-p
(push (format "%s%s/"
(configuration-layer/get-layer-property
initlayer :ext-dir) pkg)
load-path)))
(spacemacs/message
(format "%s %S is ignored since it has no init function."
(if extension-p "Extension" "Package") pkg))
(ht-remove hash pkg))))
result))
(defun configuration-layer//sort-packages-and-extensions ()
"Sort the packages and extensions symbol and store them in
@ -568,29 +617,42 @@ to select one."
(defun configuration-layer//initialize-packages ()
"Initialize all the declared packages."
(mapc (lambda (x) (configuration-layer//initialize-package
x (ht-get configuration-layer-all-packages x)))
(mapc (lambda (x)
(spacemacs/message (format "Package: Initializing %S..." x))
(configuration-layer//eval-init-functions
x (ht-get configuration-layer-packages-init-funcs x)))
configuration-layer-all-packages-sorted))
(defun configuration-layer//initialize-package (pkg layers)
"Initialize the package PKG from the configuration layers LAYERS."
(dolist (layer layers)
(condition-case err
(let* ((init-func (intern (format "%s/init-%s" layer pkg)))
(msg (format "Package: Initializing %s:%s..." layer pkg)))
(when (package-installed-p pkg)
(configuration-layer//activate-package pkg)
(if (not (fboundp init-func))
(spacemacs/message (concat msg " (no init function)"))
(spacemacs/message msg)
(funcall init-func))
(setq initializedp t)))
('error
(configuration-layer//set-error)
(spacemacs/append-to-buffer
(format (concat "An error occurred while initializing %s "
"(error: %s)\n") pkg err)))))
(spacemacs/loading-animation))
(defun configuration-layer//initialize-pre-extensions ()
"Initialize all the declared pre-extensions."
(mapc (lambda (x)
(spacemacs/message (format "Pre-extension: Initializing %S..." x))
(configuration-layer//eval-init-functions
x (ht-get configuration-layer-pre-extensions-init-funcs x) t))
configuration-layer-all-pre-extensions-sorted))
(defun configuration-layer//initialize-post-extensions ()
"Initialize all the declared post-extensions."
(mapc (lambda (x)
(spacemacs/message (format "Post-extension: Initializing %S..." x))
(configuration-layer//eval-init-functions
x (ht-get configuration-layer-post-extensions-init-funcs x) t))
configuration-layer-all-post-extensions-sorted))
(defun configuration-layer//eval-init-functions (pkg funcs &optional extension-p)
"Initialize the package PKG by evaluating the functions of FUNCS."
(when (or extension-p (package-installed-p pkg))
(configuration-layer//activate-package pkg)
(dolist (f funcs)
(spacemacs/message (format "-> %S..." f))
(condition-case err
(funcall f)
('error
(configuration-layer//set-error)
(spacemacs/append-to-buffer
(format (concat "An error occurred while initializing %s "
"(error: %s)\n") pkg err)))))
(spacemacs/loading-animation)))
(defun configuration-layer//activate-package (pkg)
"Activate PKG."
@ -599,38 +661,6 @@ to select one."
(package-activate pkg '(0 0 0 0))
(package-activate pkg)))
(defun configuration-layer//initialize-pre-extension (ext layers)
"Initialize the pre-extensions EXT from configuration layers LAYERS."
(configuration-layer//initialize-extension ext layers t))
(defun configuration-layer//initialize-extensions (ext-list &optional pre)
"Initialize all the declared extensions in EXT-LIST hash table.
If PRE is non nil then the extensions are pre-extensions."
(let ((func (if pre 'configuration-layer//initialize-pre-extension
'configuration-layer//initialize-extension))
(hash (if pre configuration-layer-all-pre-extensions
configuration-layer-all-post-extensions)))
(mapc (lambda (x) (funcall func x (ht-get hash x))) ext-list)))
(defun configuration-layer//initialize-extension (ext layers &optional pre)
"Initialize the extension EXT from the configuration layers LAYERS.
If PRE is non nil then the extension is a pre-extensions."
(dolist (layer layers)
(condition-case err
(let* ((l (assq layer configuration-layer-layers))
(ext-dir (plist-get (cdr l) :ext-dir))
(init-func (intern (format "%s/init-%s" layer ext))))
(add-to-list 'load-path (format "%s%s/" ext-dir ext))
(spacemacs/loading-animation)
(spacemacs/message "%s-extension: Initializing %s:%s..."
(if pre "Pre" "Post") layer ext)
(if (fboundp init-func) (funcall init-func)))
('error
(configuration-layer//set-error)
(spacemacs/append-to-buffer
(format (concat "An error occurred while initializing %s "
"(error: %s)\n") ext err))))))
(defun configuration-layer//initialized-packages-count ()
"Return the number of initialized packages and extensions."
(+ (ht-size configuration-layer-all-packages)
@ -645,7 +675,7 @@ If PRE is non nil then the extension is a pre-extensions."
(defun configuration-layer//get-packages-dependencies ()
"Returns a hash map where key is a dependency package symbol and value is
a list of all packages which depend on it."
(let ((result (make-hash-table :size 200)))
(let ((result (make-hash-table :size 256)))
(dolist (pkg package-alist)
(let* ((pkg-sym (car pkg))
(deps (configuration-layer//get-package-dependencies pkg-sym)))

View File

@ -107,7 +107,8 @@ It runs `tabulated-list-revert-hook', then calls `tabulated-list-print'."
;; Edit
;; ---------------------------------------------------------------------------
(spacemacs|init-company-backends emacs-lisp-mode)
(when (configuration-layer/layer-declaredp 'auto-completion)
(spacemacs|init-company-backends emacs-lisp-mode))
;; start scratch in text mode (usefull to get a faster Emacs load time
;; because it avoids autoloads of elisp modes)
(setq initial-major-mode 'text-mode)

View File

@ -18,6 +18,7 @@
auto-dictionary
auto-highlight-symbol
base16-theme
bind-key
bookmark
buffer-move
diminish
@ -348,6 +349,8 @@ which require an initialization must be listed explicitly in the list.")
(echo "%s %s%s press (n/N) to navigate, (e) to edit, (r) to change range or (R) for reset (d) to go to next definition (D) to go to previous definition"
propplugin propx/y prophidden)))))))
(defun spacemacs/init-bind-key ())
(defun spacemacs/init-bookmark ()
(use-package bookmark
:defer t
@ -2518,6 +2521,8 @@ displayed in the mode-line.")
:config
(spacemacs|hide-lighter undo-tree-mode)))
(defun spacemacs/init-use-package ())
(defun spacemacs/init-vi-tilde-fringe ()
(use-package vi-tilde-fringe
:if window-system