mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-08 13:37:35 +02:00
Making repl completion insert the longest common prefix before
showing candidates.
This commit is contained in:
parent
028a260247
commit
78734b806d
2 changed files with 25 additions and 8 deletions
|
@ -42,16 +42,32 @@
|
||||||
res
|
res
|
||||||
(lp (environment-parent env) (append (env-exports env) res)))))
|
(lp (environment-parent env) (append (env-exports env) res)))))
|
||||||
|
|
||||||
|
(define (string-common-prefix-length strings)
|
||||||
|
(if (null? strings)
|
||||||
|
0
|
||||||
|
(let lp ((len (string-length (car strings)))
|
||||||
|
(prev (car strings))
|
||||||
|
(ls (cdr strings)))
|
||||||
|
(if (or (null? ls) (zero? len))
|
||||||
|
len
|
||||||
|
(lp (min len (string-mismatch prev (car ls)))
|
||||||
|
(car ls)
|
||||||
|
(cdr ls))))))
|
||||||
|
|
||||||
(define (make-sexp-buffer-completer)
|
(define (make-sexp-buffer-completer)
|
||||||
(buffer-make-completer
|
(buffer-make-completer
|
||||||
(lambda (buf word)
|
(lambda (buf word)
|
||||||
(let ((len (string-length word)))
|
(let* ((len (string-length word))
|
||||||
(sort
|
(candidates
|
||||||
(filter
|
(filter
|
||||||
(lambda (w)
|
(lambda (w)
|
||||||
(and (>= (string-length w) len)
|
(and (>= (string-length w) len)
|
||||||
(equal? word (substring w 0 len))))
|
(equal? word (substring w 0 len))))
|
||||||
(map symbol->string (all-exports (interaction-environment)))))))))
|
(map symbol->string (all-exports (interaction-environment)))))
|
||||||
|
(prefix-len (string-common-prefix-length candidates)))
|
||||||
|
(if (> prefix-len len)
|
||||||
|
(list (substring (car candidates) 0 prefix-len))
|
||||||
|
(sort candidates))))))
|
||||||
|
|
||||||
;;> Runs an interactive REPL. Repeatedly displays a prompt,
|
;;> Runs an interactive REPL. Repeatedly displays a prompt,
|
||||||
;;> then Reads an expression, Evaluates the expression, Prints
|
;;> then Reads an expression, Evaluates the expression, Prints
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
(define-library (chibi repl)
|
(define-library (chibi repl)
|
||||||
(export repl)
|
(export repl)
|
||||||
(import (scheme) (only (meta) load-module)
|
(import (scheme) (only (meta) load-module)
|
||||||
(chibi ast) (chibi io) (chibi process) (chibi term edit-line)
|
(chibi ast) (chibi strings) (chibi io)
|
||||||
|
(chibi process) (chibi term edit-line)
|
||||||
(srfi 1) (srfi 18) (srfi 38) (srfi 95) (srfi 98))
|
(srfi 1) (srfi 18) (srfi 38) (srfi 95) (srfi 98))
|
||||||
(include "repl.scm"))
|
(include "repl.scm"))
|
||||||
|
|
Loading…
Add table
Reference in a new issue