Skip to content

Commit 7be6176

Browse files
committed
core: add guards around package-refresh-contents redefinition
Authorize Spacemacs to redefine the function only for tested versions.
1 parent 87b6d3f commit 7be6176

File tree

1 file changed

+41
-30
lines changed

1 file changed

+41
-30
lines changed

core/core-emacs-ext.el

+41-30
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,50 @@
1111
;;; License: GPLv3
1212
(require 'core-spacemacs-buffer)
1313

14-
;; for some reason with-eval-after-load does not work here in 24.3
15-
;; maybe the backport is incorrect!
16-
(eval-after-load 'package
17-
'(progn
18-
(defun package-refresh-contents ()
19-
"Download the ELPA archive description if needed.
14+
;; Disclaimer:
15+
;; The code in this file is not meant to stay for ever, they are
16+
;; temporary fixes that we should remove as soon as a better
17+
;; solution is found.
18+
19+
;; TODO remove this code as soon as we have a clean alternative.
20+
;; A good proposal is available here:
21+
;; https://github.com/syl20bnr/spacemacs/commit/4d87ea626dafc066d911c83538e260dd2bef762f#commitcomment-14708731
22+
(when (and (version<= "24.3.1" emacs-version)
23+
(version<= emacs-version "24.5.1"))
24+
;; for some reason with-eval-after-load does not work here in 24.3
25+
;; maybe the backport is incorrect!
26+
(eval-after-load 'package
27+
'(progn
28+
(defun package-refresh-contents ()
29+
"Download the ELPA archive description if needed.
2030
This informs Emacs about the latest versions of all packages, and
2131
makes them available for download.
2232
2333
This redefinition adds a timeout of 5 seconds to contact each archive."
24-
(interactive)
25-
;; the first part is not available before Emacs 24.4 so we just ignore
26-
;; it to be safe.
27-
(unless (version< emacs-version "24.4")
28-
;; FIXME: Do it asynchronously.
29-
(unless (file-exists-p package-user-dir)
30-
(make-directory package-user-dir t))
31-
(let ((default-keyring (expand-file-name "package-keyring.gpg"
32-
data-directory)))
33-
(when (and package-check-signature (file-exists-p default-keyring))
34-
(condition-case-unless-debug error
35-
(progn
36-
(epg-check-configuration (epg-configuration))
37-
(package-import-keyring default-keyring))
38-
(error (message "Cannot import default keyring: %S" (cdr error)))))))
39-
(dolist (archive package-archives)
40-
(condition-case-unless-debug nil
41-
(with-timeout (5 (spacemacs-buffer/warning
42-
"Cannot contact archive %s (reason: timeout)"
43-
(cdr archive)))
44-
(package--download-one-archive archive "archive-contents"))
45-
(error (message "Failed to download `%s' archive."
46-
(car archive)))))
47-
(package-read-all-archive-contents))))
34+
(interactive)
35+
;; the first part is not available before Emacs 24.4 so we just ignore
36+
;; it to be safe.
37+
(unless (version< emacs-version "24.4")
38+
;; FIXME: Do it asynchronously.
39+
(unless (file-exists-p package-user-dir)
40+
(make-directory package-user-dir t))
41+
(let ((default-keyring (expand-file-name "package-keyring.gpg"
42+
data-directory)))
43+
(when (and package-check-signature (file-exists-p default-keyring))
44+
(condition-case-unless-debug error
45+
(progn
46+
(epg-check-configuration (epg-configuration))
47+
(package-import-keyring default-keyring))
48+
(error (message "Cannot import default keyring: %S" (cdr error)))))))
49+
(dolist (archive package-archives)
50+
(condition-case-unless-debug nil
51+
;; add timeout here
52+
(with-timeout (5 (spacemacs-buffer/warning
53+
"Cannot contact archive %s (reason: timeout)"
54+
(cdr archive)))
55+
(package--download-one-archive archive "archive-contents"))
56+
(error (message "Failed to download `%s' archive."
57+
(car archive)))))
58+
(package-read-all-archive-contents)))))
4859

4960
(provide 'core-emacs-ext)

0 commit comments

Comments
 (0)