summaryrefslogtreecommitdiff
path: root/modules/language/python/completer.scm
diff options
context:
space:
mode:
Diffstat (limited to 'modules/language/python/completer.scm')
-rw-r--r--modules/language/python/completer.scm48
1 files changed, 48 insertions, 0 deletions
diff --git a/modules/language/python/completer.scm b/modules/language/python/completer.scm
new file mode 100644
index 0000000..73f96bd
--- /dev/null
+++ b/modules/language/python/completer.scm
@@ -0,0 +1,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)))
+