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