3 ms·
I tried writing Bash completion handlers for a Lisp dialect. I couldn't figure out how to get Bash to stop closing quotes, so I gave up on it. Concretely, here
by kazinator 8y ago
I tried writing Bash completion handlers for a Lisp dialect. I couldn't figure out how to get Bash to stop closing quotes, so I gave up on it.
Concretely, here is the behavior:
$ ./txr -e '(list[Tab]
(list (list-carray (list-str (list-vector
(list* (listp (list-vec
0:[0924:142129]:zelenka:~/txr$ ./txr -e '(list-vector'
I continued with -e '(list-v[Tab] and it then produced -vector' including the closing quote!
Clearly, it is oriented toward the idea that each token of the language being completed is a separate command line argument, such as a path name or whatever; it is not clear how to get it to complete syntax that is packaged as a single argument in a quote.
The bash code is:
txr_complete()
{
local target=$2
local context=$3
COMPREPLY=($(txr ./txr-bash.tl "$target" "$context"))
}
complete -F txr_complete txr
The ./txr-bash.tl file is:
(tree-bind (target context) *args*
(cond
((m^$ #/-[etpP]/ context)
(iflet ((match-rng (r$ #/[^ ()\[\]]+/ target)))
(let* ((pref [target 0..(from match-rng)])
(suff [target match-rng])
(funs (if (plusp (len pref)) (find [pref -1] "[(")))
(boundfn (if funs (fun fboundp) (fun boundp))))
(mapdo (op pprinl `@pref@1`)
(keep-if
[andf boundfn
(opip symbol-name
(starts-with suff))]
(package-symbols :usr))))))))