Last active
March 20, 2021 12:05
-
-
Save wandersoncferreira/ff4751ca465ce05ae7ea85aeb972a43e to your computer and use it in GitHub Desktop.
Integration of Pomegranate with clj-refactor to bring back hot-reload of new dependencies
This file contains 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
;; Experimental configuration to hotload refactor | |
;; using Pomegranate from Cemerick | |
;; From https://www.eigenbahn.com/2020/05/06/fast-clojure-deps-auto-reload | |
;; and integrated into clj-refactor. | |
(defun bk/send-to-repl (sexp eval ns) | |
(cider-switch-to-repl-buffer ns) | |
(goto-char cider-repl-input-start-mark) | |
(delete-region (point) (point-max)) | |
(save-excursion | |
(insert sexp) | |
(when (equal (char-before) ?\n) | |
(delete-char -1)) | |
(cider-repl--send-input t)) | |
(delete-region (point) (point-max))) | |
(defun bk/pomegranate-dep (dep) | |
(concat | |
(format | |
"%s" | |
`(use '[cemerick.pomegranate :only (add-dependencies)])) | |
(s-replace-all | |
`(("\\." . ".") | |
("mydep" . ,dep)) | |
(format | |
"%S" | |
`(add-dependencies :coordinates '[mydep] | |
:repositories (merge cemerick.pomegranate.aether/maven-central | |
{"clojars" "https://clojars.org/repo"})))))) | |
(setq cljr-hotload-dependencies t) | |
(defun cljr-hotload-dependency (artifact version &optional dep ns) | |
(bk/send-to-repl | |
(bk/pomegranate-dep (format "[%s \"%s\"]" artifact version)) | |
t ns)) | |
(defun cljr--add-project-dependency (artifact version) | |
(let* ((project-file (cljr--project-file)) | |
(deps (cljr--project-with-deps-p project-file))) | |
(cljr--update-file project-file | |
(goto-char (point-min)) | |
(if deps | |
(cljr--insert-into-clj-dependencies artifact version) | |
(cljr--insert-into-leiningen-dependencies artifact version)) | |
(cljr--post-command-message "Added %s version %s as a project dependency" artifact version)) | |
(when cljr-hotload-dependencies | |
(if deps | |
(back-to-indentation) | |
(paredit-backward-down)) | |
(cljr-hotload-dependency artifact version)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment