Skip to content

Instantly share code, notes, and snippets.

@wandersoncferreira
Last active March 20, 2021 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wandersoncferreira/ff4751ca465ce05ae7ea85aeb972a43e to your computer and use it in GitHub Desktop.
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
;; 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