Fork me on GitHub
#emacs
<
2023-01-03
>
mschmele21:01:49

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

Cora (she/her)23:01:04

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

Cora (she/her)23:01:37

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}) ?

elken09:01:31

(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)) ")"))))

mschmele15:01:12

Oooh thanks, y'all! I think what I end up with will be somewhat of a combination of the two

🎉 4