This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-01-03
Channels
- # adventofcode (2)
- # announcements (1)
- # asami (35)
- # babashka (67)
- # beginners (97)
- # cherry (3)
- # clj-yaml (3)
- # cljsrn (9)
- # clojure (44)
- # clojure-dev (34)
- # clojure-europe (13)
- # clojure-gamedev (1)
- # clojure-norway (10)
- # clojure-uk (2)
- # clojurescript (24)
- # clr (1)
- # conjure (18)
- # cursive (4)
- # datalevin (3)
- # emacs (6)
- # graalvm (9)
- # graphql (1)
- # introduce-yourself (1)
- # malli (7)
- # nrepl (3)
- # portal (1)
- # quil (2)
- # reagent (1)
- # reitit (21)
- # releases (1)
- # reveal (11)
- # ring (2)
- # shadow-cljs (17)
- # sql (24)
- # vim (4)
I'm trying to write a util function to more easily tap>
function arguments in clojure for use with https://github.com/djblue/portal. Does anybody have any good ways of getting a current clojure function's argument names? Generally when I use tap>
I pass a map of keys/values like so: (tap> {:arg1 arg1 :arg2 arg2 ... })
. It works well, but it's tedious to set up and obviously a little cumbersome when tapping a lot of values
to sprinkle a little inspiration your way: https://gist.github.com/corasaurus-hex/1f0a56b975a223c04901ce73e792e7d9
it removes some of the tediousness of getting all the function args when you can just pass them as-is and it automatically makes them a map of variable name to value
so, with that as inspiration, you could do something like (my-custom-tap arg1 arg2 arg3)
and have it send to the tap (tap> {:arg1 arg1 :arg2 arg2 :arg3 arg3})
?
(defcustom sw1nn/portal-tap-viewers '(":portal.viewer/pprint"
":portal.viewer/table"
":portal.viewer/tree"
":portal.viewer/hiccup"
":portal.viewer/tree")
"List of viewers to be prompted when `C-u M-x sw1nn/cider-tap-last-sexp`")
(defun sw1nn/cider-tap-last-sexp (&optional default-viewer)
"Evaluate and tap the expression preceding point.
If invoked with default-viewer, add this as metadata. If
invoked with a single prefix argument prompt for the
viewer using the values defined in
sw1nn/portal-tap-viewers."
(interactive (list (when (consp current-prefix-arg)
(completing-read "Default Viewer: " sw1nn/portal-tap-viewers))))
(cider-interactive-eval
(if default-viewer
(concat "(tap> (vary-meta "
(apply #'buffer-substring-no-properties (cider-last-sexp 'bounds))
" merge {:portal.viewer/default " default-viewer "}))")
(concat "(tap> " (apply #'buffer-substring-no-properties (cider-last-sexp 'bounds)) ")"))))