-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathasdf-vm-plugin.el
More file actions
208 lines (169 loc) · 7.58 KB
/
asdf-vm-plugin.el
File metadata and controls
208 lines (169 loc) · 7.58 KB
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
;;; asdf-vm-plugin.el --- ASDF VM porcelain for Emacs -*- lexical-binding: t -*-
;; Author: Zachary Elliott <contact@zell.io>
;; Maintainer: Zachary Elliott <contact@zell.io>
;; Homepage: https://github.com/zellio/emacs-asdf-vm
;; Keywords: languages asdf
;; 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:
;;
;;; Code:
(require 'cl-lib)
(require 'asdf-vm-config)
(require 'asdf-vm-util)
(require 'asdf-vm-process)
(defgroup asdf-vm-plugin nil
"Configuration subgroup for ASDF-VM plugins."
:prefix "asdf-vm-plugin-"
:group 'asdf-vm)
(defcustom asdf-vm-plugin-github-url "https://github.com/asdf-vm/asdf-plugins"
"Source url for ASDF-VM installation."
:group 'asdf-vm-plugin
:type 'string)
(defcustom asdf-vm-plugin-repository-path asdf-vm--plugin-index-directory
"Source url for ASDF-VM installation."
:group 'asdf-vm-plugin
:type 'string)
(defun asdf-vm-plugin--parse-index-file (path)
"Read and extract the repository value from a plugin repository file at PATH."
(unless (file-readable-p path)
(signal 'asdf-vm-plugin-unreadable-repository-file (list path)))
(with-temp-buffer
(insert-file-contents path)
(goto-char (point-min))
(search-forward "repository = ")
(let* ((plugin-name (file-name-nondirectory path))
(plugin-url (buffer-substring-no-properties (point) (line-end-position))))
(cons plugin-name plugin-url))))
(defvar asdf-vm-plugin--repository-alist nil
"Memoization variable for function `asdf-vm-plugin--repository-alist'.")
(defun asdf-vm-plugin--repository-alist ()
"Alist representation of the on disk plugin repository.
NB. This value gets memoized on first call and may need to be manually
unset if on disk representation changes."
(or asdf-vm-plugin--repository-alist
(setq asdf-vm-plugin--repository-alist
(let* ((plugins-directory (expand-file-name "plugins" asdf-vm-plugin-repository-path))
(plugin-repository-paths (directory-files plugins-directory t (rx line-start (not ?.)))))
(seq-map #'asdf-vm-plugin--parse-index-file plugin-repository-paths)))))
(defun asdf-vm-plugin--plugin-completing-read
(&optional predicate require-match initial-input hist def inherit-input-method)
"Completing read for working with NAME of plugins.
PREDICATE REQUIRE-MATCH INITIAL-INPUT HIST DEF and INHERIT-INPUT-METHOD
are as in `compelting-read'."
(let* ((plugin-names (seq-map #'car (asdf-vm-plugin--repository-alist))))
(completing-read
"Plugin name: " plugin-names predicate require-match
initial-input hist def inherit-input-method)))
(defun asdf-vm-plugin--git-url-read-string
(plugin &optional initial-input history default-value inherit-input-method)
"Completing read for working with GIT-URL of PLUGIN.
INITIAL-INPUT HISTORY DEFAULT-VALUE INHERIT-INPUT-METHOD as in `read-string'"
(let* ((repository-alist (asdf-vm-plugin--repository-alist))
(repository-url
(alist-get plugin repository-alist "" nil #'string-equal))
(initial-input (or initial-input repository-url)))
(read-string
"Plugin git url: " initial-input history
default-value inherit-input-method)))
;;;###autoload
(defun asdf-vm-plugin-add (name git-url &optional interactive-call)
"Add the plugin NAME from GIT-URL to ASDF-VM.
INTERACTIVE-CALL is an internal flag value and should not be used manually."
(interactive
(let* ((plugin (asdf-vm-plugin--plugin-completing-read nil t)))
(list
plugin
(asdf-vm-plugin--git-url-read-string plugin)
(prefix-numeric-value current-prefix-arg))))
(when interactive-call
(asdf-vm-message "Installing plugin: %s" name))
(asdf-vm-call
:command '(plugin add)
:command-arguments (list name git-url)
:blocking interactive-call))
(defun asdf-vm-plugin--installed-plugins ()
"List plugins installed for ASDF-VM based on disk state."
(let* ((plugin-paths (directory-files asdf-vm--plugins-directory t (rx line-start (not ?.)))))
(seq-map #'file-name-base plugin-paths)))
;;;###autoload
(defun asdf-vm-plugin-list (&optional interactive-call)
"List plugins installed for ASDF-VM.
INTERACTIVE-CALL is an internal flag value and should not be used manually."
(interactive "p")
(let ((plugins (asdf-vm-plugin--installed-plugins)))
(when interactive-call
(asdf-vm-message "Installed plugins: %s" (string-join plugins ", ")))
plugins))
;;;###autoload
(defun asdf-vm-plugin-list-all (&optional interactive-call)
"List all plugins for ASDF-VM in the on disk repository.
INTERACTIVE-CALL is an internal flag value and should not be used manually."
(interactive "p")
(cl-labels ((listify-alist (cons) (list (car cons) (cdr cons))))
(let* ((plugins (seq-map #'listify-alist (asdf-vm-plugin--repository-alist))))
(when interactive-call
(asdf-vm-message "Available plugins: %s" (string-join (seq-map #'car plugins) ", ")))
plugins)))
(defun asdf-vm-plugin--installed-plugin-completing-read
(&optional
predicate require-match initial-input hist def inherit-input-method)
"Completing read for installed ASDF-VM plugins.
PREDICATE REQUIRE-MATCH INITIAL-INPUT HIST DEF and INHERIT-INPUT-METHOD
are as in `compelting-read'."
(let* ((plugins (asdf-vm-plugin--installed-plugins)))
(completing-read
"Installed plugin name: " plugins predicate require-match
initial-input hist def inherit-input-method)))
;;;###autoload
(defun asdf-vm-plugin-remove (name &optional interactive-call)
"Remove plugin NAME from asdf.
INTERACTIVE-CALL is an internal flag value and should not be used manually."
(interactive
(list
(asdf-vm-plugin--installed-plugin-completing-read nil t)
(prefix-numeric-value current-prefix-arg)))
(when interactive-call
(asdf-vm-message "Removing plugin: %s" name))
(asdf-vm-call
:command '(plugin remove)
:command-arguments (list name)
:blocking interactive-call))
;;;###autoload
(defun asdf-vm-plugin-update (name &optional git-ref interactive-call)
"Update plugin NAME to optional GIT-REF or current GIT-REF.
INTERACTIVE-CALL is an internal flag value and should not be used manually."
(interactive
(list
(asdf-vm-plugin--installed-plugin-completing-read nil t)
(read-string "Plugin git ref: ")
(prefix-numeric-value current-prefix-arg)))
(let ((command-arguments (if git-ref (list name git-ref) (list name))))
(when interactive-call
(asdf-vm-message "Updating plugin: %s" name))
(asdf-vm-call
:command '(plugin update)
:command-arguments command-arguments
:blocking interactive-call)))
;;;###autoload
(defun asdf-vm-plugin-update-all (&optional interactive-call)
"Update all ASDF-VM plugins based on current git-ref values.
INTERACTIVE-CALL is an internal flag value and should not be used manually."
(interactive "p")
(when interactive-call
(asdf-vm-message "Updating all installed plugins"))
(asdf-vm-call
:command '(plugin update)
:command-arguments '("--all")
:blocking interactive-call))
(provide 'asdf-vm-plugin)
;;; asdf-vm-plugin.el ends here