X-Git-Url: https://code.delx.au/gnu-emacs-elpa/blobdiff_plain/3ba79b2f8f27bd281bef5a334b611143807aca65..0b60259ca8e7553c7029bb3471a1d29c3893200e:/async-bytecomp.el diff --git a/async-bytecomp.el b/async-bytecomp.el index 2105fee85..0daa07942 100644 --- a/async-bytecomp.el +++ b/async-bytecomp.el @@ -42,15 +42,19 @@ (require 'cl-lib) (require 'async) -(defcustom async-bytecomp-allowed-packages '(async helm) +(defcustom async-bytecomp-allowed-packages + '(async helm helm-core helm-ls-git helm-ls-hg magit) "Packages in this list will be compiled asynchronously by `package--compile'. All the dependencies of these packages will be compiled async too, -so no need to add dependencies to this list." +so no need to add dependencies to this list. +The value of this variable can also be a list with a single element, +the symbol `all', in this case packages are always compiled asynchronously." :group 'async :type '(repeat (choice symbol))) (defvar async-byte-compile-log-file "~/.emacs.d/async-bytecomp.log") +;;;###autoload (defun async-byte-recompile-directory (directory &optional quiet) "Compile all *.el files in DIRECTORY asynchronously. All *.elc files are systematically deleted before proceeding." @@ -99,41 +103,44 @@ All *.elc files are systematically deleted before proceeding." (erase-buffer) (insert error-data)))))) call-back) - (message "Started compiling asynchronously directory %s" directory))) + (unless quiet (message "Started compiling asynchronously directory %s" directory)))) (defvar package-archive-contents) -(defvar package-alist) (declare-function package-desc-reqs "package.el" (cl-x)) -(declare-function package--get-deps "package.el" (pkg &optional only)) - -(unless (fboundp 'package--get-deps) - (defun package--get-deps (pkg &optional only) - (let* ((pkg-desc (cadr (assq pkg package-alist))) - (direct-deps (cl-loop for p in (package-desc-reqs pkg-desc) - for name = (car p) - when (assq name package-alist) - collect name)) - (indirect-deps (unless (eq only 'direct) - (delete-dups - (cl-loop for p in direct-deps - append (package--get-deps p)))))) - (cl-case only - (direct direct-deps) - (separate (list direct-deps indirect-deps)) - (indirect indirect-deps) - (t (delete-dups (append direct-deps indirect-deps))))))) + +(defun async-bytecomp--get-package-deps (pkg &optional only) + ;; Same as `package--get-deps' but parse instead `package-archive-contents' + ;; because PKG is not already installed and not present in `package-alist'. + (let* ((pkg-desc (cadr (assq pkg package-archive-contents))) + (direct-deps (cl-loop for p in (package-desc-reqs pkg-desc) + for name = (car p) + when (assq name package-archive-contents) + collect name)) + (indirect-deps (unless (eq only 'direct) + (delete-dups + (cl-loop for p in direct-deps append + (async-bytecomp--get-package-deps p)))))) + (cl-case only + (direct direct-deps) + (separate (list direct-deps indirect-deps)) + (indirect indirect-deps) + (t (delete-dups (append direct-deps indirect-deps)))))) (defun async-bytecomp-get-allowed-pkgs () - (when async-bytecomp-allowed-packages - (cl-loop for p in async-bytecomp-allowed-packages - append (package--get-deps p) into reqs - finally return - (delete-dups - (append async-bytecomp-allowed-packages reqs))))) - -(defadvice package--compile (around byte-compile-async activate) + (when (and async-bytecomp-allowed-packages + (listp async-bytecomp-allowed-packages)) + (if package-archive-contents + (cl-loop for p in async-bytecomp-allowed-packages + append (async-bytecomp--get-package-deps p) into reqs + finally return + (delete-dups + (append async-bytecomp-allowed-packages reqs))) + async-bytecomp-allowed-packages))) + +(defadvice package--compile (around byte-compile-async) (let ((cur-package (package-desc-name pkg-desc))) - (if (memq cur-package (async-bytecomp-get-allowed-pkgs)) + (if (or (equal async-bytecomp-allowed-packages '(all)) + (memq cur-package (async-bytecomp-get-allowed-pkgs))) (progn (when (eq cur-package 'async) (fmakunbound 'async-byte-recompile-directory)) @@ -142,6 +149,16 @@ All *.elc files are systematically deleted before proceeding." (async-byte-recompile-directory (package-desc-dir pkg-desc) t)) ad-do-it))) +;;;###autoload +(define-minor-mode async-bytecomp-package-mode + "Byte compile asynchronously packages installed with package.el. +Async compilation of packages can be controlled by +`async-bytecomp-allowed-packages'." + :group 'async + :global t + (if async-bytecomp-package-mode + (ad-activate 'package--compile) + (ad-deactivate 'package--compile))) (provide 'async-bytecomp)