Sfoglia il codice sorgente

~/.bin/rly: Now with completion (kind of working)

Lucas Stadler 14 anni fa
parent
commit
a52f002b96
1 ha cambiato i file con 33 aggiunte e 2 eliminazioni
  1. 33 2
      .bin/rly

+ 33 - 2
.bin/rly

@ -21,9 +21,40 @@ send_to_repl = (str) ->
21 21
	child.stdin.write str
22 22
	child.stdin.end()
23 23
24
get_completion_for = (str, cb) ->
25
	relevant_match = str.match(/[a-zA-Z][a-zA-Z0-9\-\?]+$/)
26
	if relevant_match
27
		relevant = relevant_match[0]
28
	else
29
		cb null, [[], str]
30
		return
31
32
	exec "/home/lu/t/vim/clojure/client/ng vimclojure.Nail Complete --base #{relevant}",
33
		(err, stdout, stderr) ->
34
			if(err)
35
				console.log err
36
				exit 1
37
38
			answer = JSON.parse stdout
39
			matches = (m.word for m in answer.value)
40
			cb null, [matches, str]
41
42
is_balanced = (str) ->
43
	n = 0
44
	for c in str
45
		n += 1 if c in "([\""
46
		n -= 1 if c in ")]\""
47
	n == 0
48
24 49
console.log "o'rly 0.x (clojure repl with a nailgun)"
25
rl = readline.createInterface process.stdin, process.stdout
50
rl = readline.createInterface process.stdin, process.stdout, get_completion_for
26 51
rl.setPrompt "> "
27 52
rl.prompt()
53
cmplt = ""
28 54
rl.on 'line', (cmd) ->
29
	send_to_repl cmd
55
	cmd = cmplt + cmd
56
	if is_balanced cmd
57
		send_to_repl cmd
58
	else
59
		cmplt = cmd
60
		rl.write("  ")