blob: 73f96bd9fc73ea945d6ff491591e1f4a0b26cc37 (
about) (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
(define-module (language python completer)
#:use-module (language python list)
#:use-module (language python dir)
#:use-module (system base language)
#:use-module (ice-9 regex)
#:export (complete-fkn))
(define-syntax-rule (aif it p x y) (let ((it p)) (if it x y)))
(define (old) (@@ (ice-9 readline) *readline-completion-function*))
(define reg "(\\w+(\\.\\w+)*)\\.(\\w*)$")
(define (complete-fkn eval)
(let ((old (old))
(strs '() )
(pp "" )
(regexp #f ))
(letrec
((compl
(lambda (text continue?)
(if continue?
(if (null? strs)
#f
(let ((str (car strs)))
(set! strs (cdr strs))
(if (string-match regexp str)
(string-append pp "." str)
(compl text #t))))
(if (and (equal? (language-name (current-language)) 'python)
(in "." text))
(aif it (string-match reg text)
(let* ((n (match:count it))
(p (match:substring it 1))
(t (match:substring it (- n 1)))
(d (to-list (dir (eval p)))))
(begin
(set! strs d)
(set! pp p)
(set! regexp (string-append
"^" (if (equal? t "")
"[^_]"
(regexp-quote t))))
(compl text #t)))
#f)
(old text continue?))))))
compl)))
|