Created
June 9, 2020 13:30
-
-
Save siassaj/ecdb8030c771e9fd2a2baabf6889d9fc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; BEFORE | |
(defun lsp-docker--with-plist-keys (plist &rest required-keys happy-fn) | |
"apply required-keys' values to happy-fn, or make an error " | |
(let* ((existing-keys (loop for (key value . rest) on plist by 'cddr collect key)) | |
(difference (seq-difference required-keys existing-keys))) | |
(if (> 0 (length difference)) | |
(funcall happy-fn (--map (plist-get plist it) required-keys)) | |
(error "list is missing %s" difference)))) | |
(defun lsp-docker--docker-command (config) | |
"Return the exact docker command to run to turn on the LSP server" | |
(lsp-docker--with-plist-keys config '(:docker-image-name | |
:container-name | |
:container-command | |
:host-work-dir | |
:container-work-dir) | |
(lambda (docker-image-name | |
container-name | |
container-command | |
host-work-dir | |
container-work-dir) | |
(split-string | |
(format "docker run --name %s --rm -v %s:%s -i %s %s" | |
container-name | |
host-work-dir | |
container-work-dir | |
docker-image-name | |
container-command))))) | |
;; AFTER | |
(defmacro lsp---docker-with-plist-keys (plist required-keys form) | |
"execute form with required-keys' replaced by values, or make an error " | |
(let* ((existing-keys (loop for (key value . rest) on plist by 'cddr collect key)) | |
(difference (seq-difference required-keys existing-keys))) | |
(if (not difference) | |
(let ((arg-names (--map (intern (replace-regexp-in-string ":" "" (symbol-name it))) required-keys)) | |
(values (--map (plist-get plist it) required-keys))) | |
`(apply (lambda ,arg-names ,form) ',values)) | |
(error "list is missing %s" difference)))) | |
(defun lsp-docker--docker-command (config) | |
"Return the exact docker command to run to turn on the LSP server" | |
(lsp-docker--with-plist-keys | |
config | |
'(:docker-image-name | |
:container-name | |
:container-command | |
:host-work-dir | |
:container-work-dir) | |
(split-string | |
(format "docker run --name %s --rm -v %s:%s -i %s %s" | |
container-name | |
host-work-dir | |
container-work-dir | |
docker-image-name | |
ncontainer-command)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment