Fork me on GitHub
#inf-clojure
<
2022-03-18
>
borkdude11:03:01

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

borkdude11:03:30

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

dpsutton14:03:05

it should be. let me try

dpsutton14:03:49

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

dpsutton14:03:08

unfortunately i'm getting this view:

dpsutton14:03:19

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

borkdude14:03:44

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

dpsutton14:03:18

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

dpsutton14:03:31

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

dpsutton14:03:40

i might just npm i -g nbb and try that

borkdude14:03:50

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

dpsutton14:03:53

oh, no i keep accidentally using bb

dpsutton14:03:49

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

borkdude14:03:14

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

dpsutton14:03:35

wow. that's really strange

dpsutton14:03:53

that's super not good

dpsutton14:03:07

does nbb offer a socket repl?

borkdude14:03:29

Here is a screen recording of what I get:

dpsutton14:03:30

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

borkdude14:03:57

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.

borkdude14:03:12

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

borkdude14:03:16

but it didn't work with the socket REPL

dpsutton14:03:21

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

borkdude14:03:24

so I want to try the console version specifically

dpsutton14:03:33

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

dpsutton14:03:08

no, that's not true

borkdude14:03:10

Maybe I can invoke an elisp function from IELM?

borkdude14:03:14

to work around this

dpsutton14:03:15

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

dpsutton14:03:05

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.

dpsutton14:03:13

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

borkdude14:03:16

in elpa/inf-clojure?

borkdude14:03:29

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

dpsutton14:03:07

Weird. I'm assuming you installed it from elpa

borkdude14:03:11

it's displaying version 3.2.0-alpha here

borkdude14:03:17

eh -snapshot

borkdude14:03:27

but I've also installed it via elpa

dpsutton14:03:16

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

dpsutton14:03:23

oh maybe melpa? i don't know

borkdude14:03:09

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

borkdude14:03:22

still the same problem

borkdude14:03:40

I'm going to edit the code

borkdude14:03:14

The problem is that I cannot type a space

borkdude14:03:31

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

dpsutton14:03:34

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

borkdude14:03:40

did that already

borkdude14:03:12

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

borkdude14:03:36

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

dpsutton14:03:05

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

borkdude14:03:31

not yet no, but this is easy to do

borkdude14:03:46

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

borkdude14:03:30

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

npx [email protected]
(require '["fs" :as fs])
(fs/ TAB TAB
then you should see some completions

dpsutton14:03:36

is there a function i can call to get completions?

dpsutton14:03:51

i might be able to wire it up quickly

borkdude14:03:55

Not yet, but I can take care of that now

borkdude14:03:02

what is the format you want to get back?

dpsutton14:03:15

let me check

dpsutton14:03:21

i think its just a simple list but not positive

dpsutton14:03:42

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

borkdude14:03:18

so I can just return arbitrary edn?

dpsutton14:03:16

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

dpsutton14:03:38

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

borkdude14:03:53

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

dpsutton14:03:08

a new function could return a new shape no?

borkdude14:03:49

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

dpsutton14:03:29

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

borkdude14:03:53

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

borkdude14:03:06

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

dpsutton14:03:14

yes that should be fine

borkdude15:03:20

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

borkdude15:03:55

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

borkdude15:03:54

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

borkdude15:03:39

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

borkdude15:03:17

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

dpsutton15:03:42

(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

dpsutton15:03:03

that’s in *Inf-Clojure Redirect Buffer*