branch: elpa/geiser-gauche commit 8e737d2dc7cd663c9357996daf36590f3387657e Author: András Simonyi <andras.simo...@gmail.com> Commit: András Simonyi <andras.simo...@gmail.com>
Improve completion --- geiser-gauche.el | 2 +- geiser-gauche.scm | 35 ++++++++++++++++++++++++++--------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/geiser-gauche.el b/geiser-gauche.el index 601bba3..2ac4e59 100644 --- a/geiser-gauche.el +++ b/geiser-gauche.el @@ -212,7 +212,7 @@ (cl-case proc ;; Autodoc and symbol-location makes use of the {{cur-module}} cookie to ;; pass current module information - ((autodoc symbol-location) + ((autodoc symbol-location completions) (format "(eval '(geiser:%s %s {{cur-module}}) (find-module 'geiser))" proc (mapconcat 'identity args " "))) ;; Eval and compile are (module) context sensitive diff --git a/geiser-gauche.scm b/geiser-gauche.scm index 56f73d7..0f1b959 100644 --- a/geiser-gauche.scm +++ b/geiser-gauche.scm @@ -93,15 +93,29 @@ ;;;; Completions -(define (geiser:completions prefix . rest) - (delete-duplicates - (remove - (^x (or (string=? x "") - (string-prefix? "(" x))) - (string-split - (with-output-to-string - (cut apropos (string->regexp (string-append "^" prefix)))) - #/\s+/)))) +(define (geiser:completions prefix m . rest) + (let* ((module (or (and (symbol? m ) + (find-module m)) + (find-module 'user))) + (symbols (module-visible-symbols module)) + (strings (map symbol->string symbols))) + (filter! (cut string-prefix? prefix <>) strings))) + +;;; Return the list of symbols defined by MODULE +(define (module-symbols module) + (hash-table-keys (module-table module))) + +;;; Return the list of symbols visible from MODULE +(define (module-visible-symbols module) + (let* ((imports (module-imports module)) + (inherits (module-precedence-list module)) + (imported-syms (concatenate! + (map module-exports imports))) + (inherited-syms (concatenate! + (map module-symbols inherits))) + (own-syms (module-symbols module))) + (delete-duplicates! (concatenate! + (list imported-syms inherited-syms own-syms))))) (define (geiser:module-completions prefix . rest) (filter @@ -265,3 +279,6 @@ `(("file" . ,(car paths)) ("line") ("column")) '(("file") ("line") ("column")))))) + + +