inf-clojure 2022-03-18

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

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

it should be. let me try

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

unfortunately i'm getting this view:

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

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

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

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

i might just npm i -g nbb and try that

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

oh, no i keep accidentally using bb

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

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

wow. that's really strange

that's super not good

does nbb offer a socket repl?

Here is a screen recording of what I get:

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

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.

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

but it didn't work with the socket REPL

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

so I want to try the console version specifically

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

no, that's not true

Maybe I can invoke an elisp function from IELM?

to work around this

> • ‘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.

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.

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

in elpa/inf-clojure?

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

Weird. I'm assuming you installed it from elpa

it's displaying version 3.2.0-alpha here

eh -snapshot

but I've also installed it via elpa

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

oh maybe melpa? i don't know

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

still the same problem

I'm going to edit the code

The problem is that I cannot type a space

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

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

did that already

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

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

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

not yet no, but this is easy to do

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

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

is there a function i can call to get completions?

i might be able to wire it up quickly

Not yet, but I can take care of that now

what is the format you want to get back?

let me check

i think its just a simple list but not positive

> 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.

so I can just return arbitrary edn?

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

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

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

a new function could return a new shape no?

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

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

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}]}

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

yes that should be fine

$ 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 ^

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

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

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

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

(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

that’s in *Inf-Clojure Redirect Buffer*