This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-07-31
Channels
- # announcements (7)
- # asami (2)
- # babashka (47)
- # beginners (8)
- # calva (42)
- # clj-kondo (58)
- # cljdoc (1)
- # clojure (88)
- # clojure-europe (11)
- # clojurescript (6)
- # conjure (7)
- # data-science (5)
- # emacs (9)
- # events (1)
- # holy-lambda (3)
- # introduce-yourself (5)
- # meander (3)
- # missionary (4)
- # nbb (18)
- # obb (5)
- # off-topic (1)
- # other-languages (10)
- # pathom (2)
- # reagent (6)
- # releases (3)
- # ring (3)
- # scittle (1)
- # shadow-cljs (1)
- # spacemacs (2)
- # xtdb (6)
Is there any chance that someone wants to pair on trying to add some cider functionality? I think it would be cool if there a way to select a key from a hashmap. e.g Let's say your cursor is *
in this expression:
(-> {:user "..." :account-id "..." :age "..."} * ...)
after hitting some set of keys it would eval the last result (a hashmap) and then give you a list of those keys you could tap through to select one.
[:user :account-id :age]
Just think, no longer would you have to type call the clojure.core/keys fn, then print the keywords, then select one and put it as next position as a function. π . This comes up all the time for me, and while there are an arbitrary number of things you might want to do with a hashamp, this one seems common enough to warrant a special function imo. I mentioned this idea like a couple months back and it still feels useful to me after all that time so i'm willing to commit.
The downside to this pairing arrangement, is that i know next to nothing about programming emacs. But i'm willing to learn with someone if anyone else is a newbie and wants to start with me. Or if someone is like really excited to teach, this seems like a good example. I'm sure we can come to some mutually agreeable arrangement.I'm travelling right now, if you don't do this in a week DM me and we can arrange something βΊοΈ
@UA7E6DU04 I'll do that, thanks!
I submitted a cider feature request, hopefully this is the right place to start. https://github.com/clojure-emacs/cider/issues/3231
This is what i have so far:
(defun cider-eval-sexp-up-to-point-with-clojure-keys (&optional output-to-current-buffer)
"Evaluate the current sexp form up to point.
If invoked with OUTPUT-TO-CURRENT-BUFFER, print the result in the current
buffer. It constructs an expression to eval in the following manner:
- It finds the code between the point and the start of the sexp expression;
- It balances this bit of code by closing the expression;
- It evaluates the resulting code using `cider-interactive-eval'."
(interactive "P")
(let* ((beg-of-sexp (save-excursion (up-list) (backward-list) (point)))
(beg-delimiter (save-excursion (up-list) (backward-list) (char-after)))
(beg-set? (save-excursion (up-list) (backward-list) (char-before)))
(code (buffer-substring-no-properties beg-of-sexp (point)))
(code (if (= beg-set? ?#) (concat (list beg-set?) code) code))
(keys-code (concat code "keys"))
(keys-code (concat keys-code (list (cider--matching-delimiter beg-delimiter))))
(code (concat code (list (cider--matching-delimiter beg-delimiter))))
)
(cider-interactive-eval keys-code
(let* ((result (cider-eval-print-handler))) <--- cider-eval-print-handlder isn't correct
(print result)
;; (completing-read "Choose:" result)
)
(list beg-of-sexp (point))
(cider--nrepl-pr-request-map))
;; (cider-interactive-eval code
;; (when output-to-current-buffer
;; (cider-eval-print-handler))
;; (list beg-of-sexp (point))
;; (cider--nrepl-pr-request-map))
))
(defun cider-insert-select-key-dwim ()
"Insert a key selection from the sexp before point."
(interactive)
(let* ((form (cider-last-sexp))
(ks (cider-nrepl-sync-request:eval
(format "(keys %s)" form)))
(ks (car
(read-from-string
(nrepl-dict-get ks "value"))))
(ks
(completing-read-multiple "Key: " ks)))
(insert
(pcase ks
(`(,k) k)
(_ (format
"(select-keys [%s])"
(mapconcat
#'identity
(mapcar (lambda (k) (with-output-to-string (princ k))) myks)
" ")))))))
π 1
I am thinking the next elaboration of this auto inserts (map :key)
, if the thing before point is a seq
Thanks, I'll try to devote time to this on the weekend.