-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy patheasky-package.el
173 lines (142 loc) · 5.08 KB
/
easky-package.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
;;; easky-package.el --- Control Eask's package module -*- lexical-binding: t; -*-
;; Copyright (C) 2022-2025 Shen, Jen-Chieh
;; This file is not part of GNU Emacs.
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; This module simulate most important functionality from `package.el'
;;
;;; Code:
(require 'package)
(require 'easky)
;;
;; (@* "Externals" )
;;
(defvar github-elpa-working-dir)
(defvar github-elpa-archive-dir)
(defvar github-elpa-recipes-dir)
(declare-function package-recompile "ext:package.el")
(declare-function package-recompile-all "ext:package.el")
(declare-function package-upgrade "ext:package.el")
(declare-function package-upgrade-all "ext:package.el")
;;
;; (@* "Compat" )
;;
(defun easky-package--call-safely (ver func)
"Call FUNC interactively safely after checking the Emacs VER."
(if (version< emacs-version ver)
(user-error
(concat (format "`%s' is not supported in your version of Emacs; " func)
(format "consider upgrading it to Emacs %s or later" ver)))
(call-interactively func)))
;;
;; (@* "Core" )
;;
(defmacro easky-package--setup (body &rest unwind)
"Execute BODY without touching the Eask-file global variables.
The form UNWIND is use to revert package information."
(declare (indent 1) (debug t))
`(unwind-protect (easky--setup (package-initialize t) ,body) ,@unwind))
(defun easky-package--revert-info (&rest _)
"Revert package inforamtion after we have displayed in Package Menu."
(package-initialize t))
;;;###autoload
(defun easky-package-refresh-contents ()
"Like command `package-refresh-contents' but in Eask sandbox."
(interactive)
(easky-package--setup
(call-interactively #'package-refresh-contents)
(easky-package--revert-info)))
;;;###autoload
(defun easky-list-packages ()
"List packages."
(interactive)
(easky-package--setup
(package-list-packages t)
;; XXX: We revert information after it's done displaying!
(add-hook 'package-menu-mode-hook #'easky-package--revert-info)))
;;;###autoload
(defalias 'easky-package-list-packages 'easky-list-packages)
;;;###autoload
(defun easky-list-installed-packages ()
"List packages."
(interactive)
(easky-package--setup
(progn
(package-activate-all) ; refresh once!
(if package-activated-list
(package-show-package-list package-activated-list)
(user-error
(concat
"No installed packges, try the following options:\n\n"
" [1] 'M-x easky-package-install'\n"
" [2] Add dependencies to your Eask-file, and 'M-x easky-install-deps'"))))
;; XXX: We revert information after it's done displaying!
(add-hook 'package-menu-mode-hook #'easky-package--revert-info)))
;;;###autoload
(defun easky-package-install ()
"Install a package to Eask sandbox."
(interactive)
(easky-package--setup
(call-interactively #'package-install)
(easky-package--revert-info)))
;;;###autoload
(defun easky-package-delete ()
"Delete a package from Eask sandbox."
(interactive)
(easky-package--setup
(call-interactively #'package-delete)
(easky-package--revert-info)))
;;;###autoload
(defun easky-package-reinstall ()
"Reinstall a package in Eask sandbox."
(interactive)
(easky-package--setup
(call-interactively #'package-reinstall)
(easky-package--revert-info)))
;;;###autoload
(defun easky-package-recompile ()
"Recompile a package in Eask sandbox."
(interactive)
(easky-package--setup
(easky-package--call-safely "29.0.50" #'package-recompile)
(easky-package--revert-info)))
;;;###autoload
(defun easky-package-recompile-all ()
"Recompile all packages in Eask sandbox."
(interactive)
(easky-package--setup
(easky-package--call-safely "29.0.50" #'package-recompile-all)
(easky-package--revert-info)))
;;;###autoload
(defun easky-describe-package ()
"Describe a package from Eask source."
(interactive)
(easky-package--setup
(call-interactively #'describe-package)
(easky-package--revert-info)))
;;;###autoload
(defun easky-package-upgrade ()
"Update a package from Eask sandbox."
(interactive)
(easky-package--setup
(easky-package--call-safely "29.0.50" #'package-upgrade)
(easky-package--revert-info)))
;;;###autoload
(defun easky-package-upgrade-all ()
"Update all packages from Eask sandbox."
(interactive)
(easky-package--setup
(easky-package--call-safely "29.0.50" #'package-upgrade-all)
(easky-package--revert-info)))
(provide 'easky-package)
;;; easky-package.el ends here