Skip to content

Instantly share code, notes, and snippets.

@behrica
Last active December 4, 2022 15:06
Show Gist options
  • Save behrica/099c5a9c85526633c235f971badac4cf to your computer and use it in GitHub Desktop.
Save behrica/099c5a9c85526633c235f971badac4cf to your computer and use it in GitHub Desktop.
(setq clerk-viewer-list '("default"
":html"
":latex"
"nextjournal.clerk.viewer/html-viewer"
"nextjournal.clerk.viewer/vl-viewer"
"nextjournal.clerk.viewer/map-viewer"
"nextjournal.clerk.viewer/markdown-viewer"
"nextjournal.clerk.viewer/katex-viewer"
"nextjournal.clerk.viewer/fallback-viewer"
"nextjournal.clerk.viewer/string-viewer"))
(defun clerk-tap-last-sexp-with-viewer (viewer)
(interactive
(list (completing-read "Choose viewer: " clerk-viewer-list nil t)))
(let ((tapped-form (concat "(clojure.core/->> "
(cider-last-sexp)
(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))))
(defun clerk-tap-sexp-at-point-with-viewer (viewer)
(interactive
(list (completing-read "Choose viewer: " clerk-viewer-list nil t)))
(save-excursion
(goto-char (cadr (cider-sexp-at-point 'bounds)))
(clerk-tap-last-sexp-with-viewer viewer)))
(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)")
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment