Skip to content

Instantly share code, notes, and snippets.

@behrica
Last active January 26, 2023 23:27
Show Gist options
  • Save behrica/7bacf8a59021336f17027009a46eff9c to your computer and use it in GitHub Desktop.
Save behrica/7bacf8a59021336f17027009a46eff9c to your computer and use it in GitHub Desktop.
(defun clerk-open-tap-inspector ()
(interactive)
(cider-nrepl-sync-request:eval
(concat "(require '[nextjournal.clerk :as clerk])"
"(clerk/serve! {:browse true})"
"(Thread/sleep 1000)"
"(nextjournal.clerk/show! 'nextjournal.clerk.tap)")
))
(defun def-clerk-viewers ()
(nrepl-sync-request:eval
"
(require 'nextjournal.clerk)
(intern 'user 'curren-clerk-viewer
(->>
(nextjournal.clerk/get-default-viewers)
(map :name)
(remove nil?)))"
(cider-current-connection)))
;; Call this once after Clerk is running
(defun clerk-set-current-viewers ()
(interactive)
(def-clerk-viewers)
(setq clerk-current-viewers
(read
(nrepl-dict-get
(nrepl-sync-request:eval "(user/get-current-clerk-viewer)" (cider-current-connection))
"value"))))
;; Call while in `cider-inspector` to show current value in Cler after a viewer is selected
(defun cider-inspector-tap-current-val-with-clerk-viewer (viewer)
(interactive
(list (completing-read "Choose viewer: " clerk-current-viewers nil t)))
(setq cider-inspector--current-repl (cider-current-repl))
;; pick some random name, which hopeuflly is never used...
(when-let* ((ns "user")
(var-name "cider-inspector-temp-hdhsad-hbjdbasjd842342")
(value (cider-sync-request:inspect-def-current-val ns var-name)))
(let ((tapped-form (concat "(clojure.core/->> "
(concat ns "/" var-name)
(if (equal ":default" viewer)
(concat " (nextjournal.clerk/with-viewer {:transform-fn identity})")
(if (string-prefix-p ":" viewer)
(concat " (nextjournal.clerk/with-viewer " "(keyword \"" (substring viewer 1) "\")" ")")
(concat " (nextjournal.clerk/with-viewer " "(symbol \"" viewer "\")" ")"))
)
" (clojure.core/tap>))")))
(cider-interactive-eval tapped-form
nil
nil
(cider--nrepl-pr-request-map)))
(message "%s#'%s/%s = %s" cider-eval-result-prefix ns var-name value)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment