-
-
Notifications
You must be signed in to change notification settings - Fork 902
/
Copy pathlsp-use-package.el
75 lines (59 loc) · 2.42 KB
/
lsp-use-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
;;; lsp-use-package.el --- Integration with `use-package' -*- lexical-binding: t; -*-
;; Copyright (C) 2021 Ivan Yonchovski
;; Author: Ivan Yonchovski <[email protected]>
;; Keywords: convenience
;; Package-Requires: ((use-package "2.4.1") (emacs "26.1") (lsp-mode "7.0"))
;; Version: 0.0.1
;; URL: https://github.com/emacs-lsp/lsp-mode
;; 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:
;; Provides `:ensure-servers' keyword for `use-package'
;; Example:
;; (use-package lsp-mode
;; :ensure-servers (jdtls ts-ls))
;;; Code:
(require 'use-package)
(defun use-package-handler/:ensure-servers (name _keyword arg rest state)
"The `:ensure-servers' handler.
NAME of the section.
ARG - the value in that section
STATE - current state of the `use-package' expansion.
REST - the remaining content."
(let ((body (use-package-process-keywords name rest state)))
(use-package-concat
(mapcar (lambda (var)
`(lsp-ensure-server (quote ,var)))
arg)
body)))
;;;###autoload
(defun use-package-normalize-ensure-servers (_name label arg &optional _recursed)
"Normalize the arguments to diminish down to a list of symbols.
LABEL - the label for the section.
ARG - keyword value to normalize."
(cond
((use-package-non-nil-symbolp arg)
(list arg))
((-all? #'symbolp arg)
arg)
(t
(use-package-error
(concat label " wants a symbol, or list of symbols")))))
;;;###autoload
(defun use-package-normalize/:ensure-servers (name keyword args)
"Normalize ARGS under KEYWORD section.
NAME is the name of the section."
(use-package-as-one (symbol-name keyword) args
(apply-partially #'use-package-normalize-ensure-servers name) t))
;;;###autoload
(with-eval-after-load 'use-package (add-to-list 'use-package-keywords :ensure-servers t))
(provide 'lsp-use-package)
;;; lsp-use-package.el ends here