inf-clojure

borkdude 2022-03-18T11:57:01.519369Z

Is it possible to interact with a random process via stdin/stdin in inf-clojure? it's a while since I used it

borkdude 2022-03-18T11:57:30.497949Z

I'm trying C-u M-x inf-clojure but I'm not able to enter a random process like npx nbb

dpsutton 2022-03-18T14:08:05.330809Z

it should be. let me try

dpsutton 2022-03-18T14:08:58.967929Z

dpsutton 2022-03-18T14:10:49.239829Z

so you can totally just enter a random process m-x inf-clojure and then instead of choosing something in that list just type npx nbb

dpsutton 2022-03-18T14:11:08.899899Z

unfortunately i'm getting this view:

dpsutton 2022-03-18T14:11:19.678479Z

so i wonder if there's some dumb terminal setting that needs to be set

borkdude 2022-03-18T14:11:44.586279Z

you should just choose y yes, or execute npx nbb from a terminal first

dpsutton 2022-03-18T14:12:18.704559Z

i tried to choose y but i think inf-clojure is trying to display a prompt and it is not working

dpsutton 2022-03-18T14:12:31.223079Z

i executed npx nbb from a terminal afterwards and tried again and still got the same behavior

dpsutton 2022-03-18T14:12:40.465469Z

i might just npm i -g nbb and try that

borkdude 2022-03-18T14:12:50.792899Z

I tried that, but it wants me to choose one of the autocompletions and there's no way for me to get around this

dpsutton 2022-03-18T14:12:53.191049Z

oh, no i keep accidentally using bb

borkdude 2022-03-18T14:13:17.120849Z

dpsutton 2022-03-18T14:13:18.288889Z

dpsutton 2022-03-18T14:16:49.239139Z

you can type whatever you want here. the prefilled are just conveniences. because you'll always need the possibility for aliases

borkdude 2022-03-18T14:17:14.106749Z

yes, but emacs won't allow me to type whatever I want there :)

dpsutton 2022-03-18T14:17:35.388209Z

wow. that's really strange

dpsutton 2022-03-18T14:17:53.683709Z

that's super not good

dpsutton 2022-03-18T14:18:07.533539Z

does nbb offer a socket repl?

borkdude 2022-03-18T14:18:29.282949Z

Here is a screen recording of what I get:

dpsutton 2022-03-18T14:18:30.240569Z

i'd say go with that and i can look into that weirdness

borkdude 2022-03-18T14:18:57.146569Z

Yes, but the socket REPL doesn't offer the completions yet, but they are supported on the console now and I wanted to test if that worked with inf-clojure.

borkdude 2022-03-18T14:20:12.288209Z

The completions are activated when you press TAB (twice) and this works on the console

borkdude 2022-03-18T14:20:16.161559Z

but it didn't work with the socket REPL

dpsutton 2022-03-18T14:20:21.317159Z

ok there's a bug in the use of completing-read

borkdude 2022-03-18T14:20:24.096079Z

so I want to try the console version specifically

dpsutton 2022-03-18T14:20:33.752549Z

have the args in the wrong order so require-match is in the wrong spot

dpsutton 2022-03-18T14:21:08.673129Z

no, that's not true

borkdude 2022-03-18T14:21:10.300579Z

Maybe I can invoke an elisp function from IELM?

borkdude 2022-03-18T14:21:14.010969Z

to work around this

dpsutton 2022-03-18T14:21:15.176659Z

> • ‘confirm-after-completion’ means that the user can exit with any input, but she needs to confirm her choice if she called ‘minibuffer-complete’ right before ‘minibuffer-complete-and-exit’ and the input is not an element of COLLECTION.

dpsutton 2022-03-18T14:22:05.552579Z

if you want to just edit the source a little bit

(completing-read "Select Clojure REPL startup command: "
                                          (mapcar #'cdr inf-clojure-startup-forms)
                                          nil
                                          'confirm-after-completion)
change that confirm-after-competion to be a nil.

dpsutton 2022-03-18T14:23:13.567279Z

also, make sure you've updated to the latest version (a change from a day or two ago) and set (setq inf-clojure-enable-eldoc nil) because it will keep trying to get arglists for eldoc from your cursor position and erroring and adding new prompts to the repl

borkdude 2022-03-18T14:23:16.852959Z

in elpa/inf-clojure?

borkdude 2022-03-18T14:23:29.326769Z

I don't even see elpa/inf-clojure...

dpsutton 2022-03-18T14:25:07.118729Z

Weird. I'm assuming you installed it from elpa

borkdude 2022-03-18T14:25:11.787449Z

it's displaying version 3.2.0-alpha here

borkdude 2022-03-18T14:25:17.608479Z

eh -snapshot

borkdude 2022-03-18T14:26:27.007399Z

but I've also installed it via elpa

dpsutton 2022-03-18T14:28:16.124449Z

i forget how the elpa releases work. you aren't using elpa-stable for it right?

dpsutton 2022-03-18T14:28:23.786249Z

oh maybe melpa? i don't know

borkdude 2022-03-18T14:29:09.182369Z

inf-clojure        20220315.1102 installed             Run an external Clojure process in an Emacs buffer

borkdude 2022-03-18T14:29:22.137049Z

still the same problem

borkdude 2022-03-18T14:29:40.157589Z

I'm going to edit the code

borkdude 2022-03-18T14:30:14.645779Z

The problem is that I cannot type a space

borkdude 2022-03-18T14:30:31.006589Z

I can type npx but not further than that, then it forces me to this list

dpsutton 2022-03-18T14:30:34.836719Z

yeah. edit out that 'confirm-after-completion to a nil. crazy it doesn't work

borkdude 2022-03-18T14:30:40.233329Z

did that already

dpsutton 2022-03-18T14:30:43.519839Z

hmm

borkdude 2022-03-18T14:33:12.096289Z

Running this (inf-clojure "npx nbb") from IELM worked though

borkdude 2022-03-18T14:34:36.606159Z

but completions also don't work there, so I know enough :)

dpsutton 2022-03-18T14:35:05.615989Z

yeah we’d have to tell it how to get completions from nbb. and i thought its not exposed as a function that is callable

borkdude 2022-03-18T14:35:31.350679Z

not yet no, but this is easy to do

borkdude 2022-03-18T14:35:46.857139Z

I've already extracted it a bit from nREPL for the console repl

borkdude 2022-03-18T14:37:30.722639Z

no urgency here, I just wanted to see if it worked. if you go in your terminal and do:

npx nbb@0.2.8
(require '["fs" :as fs])
(fs/ TAB TAB
then you should see some completions

dpsutton 2022-03-18T14:39:36.105509Z

is there a function i can call to get completions?

dpsutton 2022-03-18T14:39:51.437469Z

i might be able to wire it up quickly

borkdude 2022-03-18T14:39:55.367849Z

Not yet, but I can take care of that now

dpsutton 2022-03-18T14:40:01.567119Z

👍

borkdude 2022-03-18T14:40:02.502469Z

what is the format you want to get back?

dpsutton 2022-03-18T14:40:15.549589Z

let me check

dpsutton 2022-03-18T14:40:21.263669Z

i think its just a simple list but not positive

dpsutton 2022-03-18T14:42:42.828749Z

> The easiest possible data passed in input is a list of candidates (e.g.: (\“def\” \“defn\“)) but more complex libraries like `alexander-yakushev/compliment’ can return other things like edn.

borkdude 2022-03-18T14:48:18.508729Z

so I can just return arbitrary edn?

dpsutton 2022-03-18T14:49:16.328319Z

i’d stay with just a list of strings for the moment

dpsutton 2022-03-18T14:49:38.210789Z

there is an edn parser but its not a dep of this project yet. but i’d be happy adding it

borkdude 2022-03-18T14:49:53.868969Z

well, "for the moment" is the problem because when I return a flat list of strings, I don't have the oppurtunity to add more later, a recipe for breaking changes

dpsutton 2022-03-18T14:50:08.364029Z

a new function could return a new shape no?

borkdude 2022-03-18T14:50:49.477539Z

I guess inf-clojure could wrap the function call in some data processing inside of nbb and then get that result, right?

dpsutton 2022-03-18T14:51:29.552139Z

or the function could take an arg indicating the return? (completions :list "set") and later (completions :edn "set"). Or yes we could process inside of nbb. (map :name (completions "set"))

borkdude 2022-03-18T14:53:53.344009Z

the thing, is, I'd like to keep the things relatively the same for nREPL and other stuff. That format is

{"completions" [{"candidate "fs/readFileSync" "ns" nil}]}

borkdude 2022-03-18T14:54:06.339019Z

but given that shape, inf-clojure could just simplify it within nbb I guess

dpsutton 2022-03-18T14:54:14.110599Z

yes that should be fine

borkdude 2022-03-18T15:05:20.044939Z

$ node out/nbb_main.js
Welcome to nbb v0.2.8!
user=> (require '[nbb.repl :refer [get-completions]])
nil
user=> (get-completions "in")
["inst-ms" "inst?" "int-array" "interleave" "into" "int" "int?" "indexed?" "instance?" "integer?" "intern" "inc" "ints" "interpose" "into-array"]
OK, I guess I can just re-use the nREPL format internally and expose the more simple format just for socket REPL/inf-clojure ^

borkdude 2022-03-18T15:05:55.360609Z

user=> (require '["fs" :as fs])
nil
user=> (get-completions "fs/")
["fs/Dir" "fs/Dirent" "fs/F_OK" ...]

borkdude 2022-03-18T15:10:54.005339Z

Publishing v0.2.9 with this function now. Should be there in 3 minutes

borkdude 2022-03-18T15:13:41.670709Z

Published!

borkdude 2022-03-18T15:14:39.011199Z

Welcome to nbb v0.2.9!
user=> (require '[nbb.repl :refer [get-completions]])
nil
user=> (get-completions "co")
("contains?" "cond->>" "comp" "cons" "conj!" "conj" "compare-and-set!" "concat" "counted?" "completer*" "cond->" "condp" "cond" "comment" "count" "comparator" "compare" "complement" "constantly" "completing" "coll?")

borkdude 2022-03-18T15:15:17.909309Z

user=> (require '[clojure.set :as set])
nil
user=> (get-completions "set/")
("set/union" "set/map-invert" "set/join" "set/select" "set/intersection" "set/superset?" "set/index" "set/subset?" "set/rename" "set/rename-keys" "set/project" "set/difference" "set/")

dpsutton 2022-03-18T15:50:42.148689Z

(nbb.repl/get-completions "str/")


("str/ends-with?" "str/capitalize" "str/reverse" "str/join" "str/replace-first" "str/starts-with?" "str/escape" "str/last-index-of" "str/includes?" "str/replace" "str/split-lines" "str/lower-case" "str/trim-newline" "str/upper-case" "str/split" "str/trimr" "str/index-of" "str/trim" "str/triml" "str/blank?" "str/")
it’s close. gonna have to figure out what little assumption needs to be respected somewhere later

dpsutton 2022-03-18T15:51:03.017719Z

that’s in *Inf-Clojure Redirect Buffer*