Fork me on GitHub
#emacs
<
2022-02-13
>
Drew Verlee17:02:24

I would like some feedback on a hypothetical piece of emacs functionality i'm thinking about building. Imagine your threading some data through a functional pipeline, like any day working with clojure. (-> some-data ...) Now "some-data" is really a hash-map full of keys, it's like a big bag and at times you might need to pull some out. What if you could fire off a command and then select the keys you need? So "*" is the cursor (-> some-data *) will open a tiny window right there with the list of keys [<k_1> <k_2> ... <k_n>] each with a checkbox you can use to select. The selected keys are then available to paste. so you could just pick one (-> some-data :k_1) Of i you picked two you would get (-> some-data [:k_1 :k_2]) And obviously you would have to wrap it. maybe in something like "select keys" or maybe in "juxt". Currently solutions allow you to create a list easily enough, but not quickly select they keys beyond text manipulation. e.g i can print or create the full list but then i have to to remove keys. I'm not suggesting this is a huge win, just that I think this flow would be slightly more economical in a lot of common cases i run into.

vemv17:02:31

It sounds good to me, with the nuance with the cost of building it might be somewhat excessive compared to the cost of (-> some-data (doto pprint)) or such, then copying the interesting keys by hand I have this yasnippet https://raw.githubusercontent.com/zenmacs/.emacs.d/master/snippets/clojure-mode/ppr which I can use while inside a ->, so I'm not interrupted by a require step

👀 1
vemv18:02:08

A really generalized fix would be to make https://github.com/alexander-yakushev/compliment/ able to offer completions based on evaluating the sexp being completed So in this UI, the options would be determined by evaluating (-> x) , and observing that select-keys needs a set of keys, so one then evaluates (-> x keys)

vemv18:02:41

It's probably a lot of work, but also would show well what can be accomplished with the "CIDER approach" (favor eval over static heuristics)

Drew Verlee17:02:48

is there a cider eval option that keeps the surrounding s-expression and produces the result? What would be close to my suggestion is a fn similar to 'cider-eval-last-sexp-and-replace' only without the replace part. e.g (-> {:a 1 :c 2} keys *) 'cider-eval-sexp-and-keep' (this doesn't exist) (-> {:a 1 :c 2} keys *) [:a :b]

vemv18:02:01

Don't know the answer directly but these seem self-contained, probably you can make your own https://github.com/clojure-emacs/cider/blob/83f18a9ad4b97614bf1ec9e65444ebc90dd8bddf/cider-eval.el#L935-L958