Merge pull request from kovrik/issue-299

Move :pin out of macro expansion phase
GitHub-reference: https://github.com/jwiegley/use-package/issues/302
This commit is contained in:
John Wiegley 2016-01-12 16:01:19 -05:00
commit 38c170e17b

View file

@ -419,23 +419,22 @@ manually updated package."
(let ((archive-symbol (if (symbolp archive) archive (intern archive))) (let ((archive-symbol (if (symbolp archive) archive (intern archive)))
(archive-name (if (stringp archive) archive (symbol-name archive)))) (archive-name (if (stringp archive) archive (symbol-name archive))))
(if (use-package--archive-exists-p archive-symbol) (if (use-package--archive-exists-p archive-symbol)
(push (cons package archive-name) package-pinned-packages) (add-to-list 'package-pinned-packages (cons package archive-name))
(error "Archive '%s' requested for package '%s' is not available." (error "Archive '%s' requested for package '%s' is not available."
archive-name package)) archive-name package))
(package-initialize t))) (package-initialize t)))
(defun use-package-handler/:pin (name keyword archive-name rest state) (defun use-package-handler/:pin (name keyword archive-name rest state)
(let ((body (use-package-process-keywords name rest state))) (let ((body (use-package-process-keywords name rest state))
;; This happens at macro expansion time, not when the expanded code is (pin-form (if archive-name
;; compiled or evaluated. `(use-package-pin-package ',(use-package-as-symbol name)
(if (null archive-name) ,archive-name))))
body ;; Pinning should occur just before ensuring
(use-package-pin-package name archive-name) ;; See `use-package-handler/:ensure'.
(use-package-concat (if (bound-and-true-p byte-compile-current-file)
body (eval pin-form) ; Eval when byte-compiling,
`((push '(,(use-package-as-symbol name) . ,archive-name) (push pin-form body)) ; or else wait until runtime.
package-pinned-packages) body))
t)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;