[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/geiser-chicken bc3f877 049/102: Fuzzy matching for Chicken
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/geiser-chicken bc3f877 049/102: Fuzzy matching for Chicken AutoDoc and Completions |
Date: |
Sun, 1 Aug 2021 18:26:53 -0400 (EDT) |
branch: elpa/geiser-chicken
commit bc3f877abd346ed3f8419ab5a06d36b03ead31a6
Author: Dan Leslie <dan@ironoxide.ca>
Commit: Dan Leslie <dan@ironoxide.ca>
Fuzzy matching for Chicken AutoDoc and Completions
Because Chicken allows symbols to be imported with prefixes, and because
'apropos' does not provide any utility to match with the loaded
prefixes, it is difficult to acquire information about prefixed symbols.
This solution hacks around the issue by providing naive
fuzzy-matching. If no match for a symbol can be found then the first
character is dropped and matching is attempted again; the process is
repeated until matches are found or the entire symbol is consumed.
Also removes the (now redundant and slow) geiser-chicken-prefix-delimiters.
---
geiser/emacs.scm | 73 +++++++++++++++++++++++++++++++++-----------------------
1 file changed, 43 insertions(+), 30 deletions(-)
diff --git a/geiser/emacs.scm b/geiser/emacs.scm
index d5bddf5..8ec3440 100644
--- a/geiser/emacs.scm
+++ b/geiser/emacs.scm
@@ -242,13 +242,18 @@
(apropos-information-list "" #:macros? #t)))))
(define (find-symbol-information prefix)
+ (define (find-symbol-information* prefix skipped)
+ (let ((found (filter
+ (lambda (info)
+ (string-has-prefix? (car info) prefix))
+ (symbol-information-list))))
+ (if (and (null? found) (< 1 (string-length prefix)))
+ (find-symbol-information* (substring/shared prefix 1)
(string-append skipped (substring prefix 0 1)))
+ (cons found skipped))))
(memoize
`(find-symbol-information ,prefix)
(lambda ()
- (filter
- (lambda (info)
- (string-has-prefix? (car info) (->string prefix)))
- (symbol-information-list)))))
+ (find-symbol-information* (->string prefix) ""))))
(define debug-log (make-parameter #f))
(define (write-to-log form)
@@ -387,37 +392,42 @@
(any (cut eq? type <>) types)))
(match-nodes sym)))))
- (define (make-module-list sym module-sym)
- (if (not module-sym)
- (find-standards-with-symbol sym)
- (cons module-sym (find-standards-with-symbol sym))))
+ (define (make-module-list sym module-sym prefix-exists)
+ (append
+ (if prefix-exists '(fuzzy-match) '())
+ (if (not module-sym)
+ (find-standards-with-symbol sym)
+ (cons module-sym (find-standards-with-symbol sym)))))
- (define (fmt node)
+ (define (fmt node prefix)
(memoize
- `(fmt ,node)
+ `(fmt ,node ,prefix)
(lambda ()
- (let* ((entry (string->symbol (car node)))
+ (let* ((original-entry (string->symbol (car node)))
+ (fuzzy-entry (string->symbol (string-append prefix (car node))))
+ (prefix-exists (not (= 0 (string-length prefix))))
(module (cadr node))
(module (if module (string->symbol module) #f))
(rest (cddr node))
- (type (if (or (list? rest) (pair? rest)) (car rest) rest)))
+ (type (if (or (list? rest) (pair? rest)) (car rest) rest))
+ (module-list (make-module-list fuzzy-entry module prefix-exists)))
(cond
((equal? 'macro type)
- `(,entry ("args" (("required" <macro>)
- ("optional" ...)
- ("key")))
- ("module" ,@(make-module-list entry module))))
+ `(,fuzzy-entry ("args" (("required" <macro>)
+ ("optional" ...)
+ ("key")))
+ ("module" ,@module-list)))
((or (equal? 'variable type)
(equal? 'constant type))
(if (not module)
- `(,entry ("value" . ,(eval entry)))
+ `(,fuzzy-entry ("value" . ,(eval original-entry)))
(let* ((original-module (current-module))
(desired-module (find-module module))
(value (begin (switch-module desired-module)
- (eval entry))))
+ (eval original-entry))))
(switch-module original-module)
- `(,entry ("value" . ,value)
- ("module" ,@(make-module-list entry module))))))
+ `(,fuzzy-entry ("value" . ,value)
+ ("module" ,@module-list)))))
(else
(let ((reqs '())
(opts '())
@@ -452,22 +462,20 @@
(collect-args args)
- `(,entry ("args" (("required" ,@reqs)
- ("optional" ,@opts)
- ("key" ,@keys)))
- ("module" ,@(make-module-list entry module))))))))))
+ `(,fuzzy-entry ("args" (("required" ,@reqs)
+ ("optional" ,@opts)
+ ("key" ,@keys)))
+ ("module" ,@module-list)))))))))
;; Builds a signature list from an identifier
(define (find-signatures sym)
(memoize
`(find-signatures ,sym)
(lambda ()
- (let ((str (symbol->string sym)))
+ (let ((result (find-symbol-information sym)))
(map
- (cut fmt <>)
- (filter
- (lambda (lst) (string=? (car lst) str))
- (find-symbol-information sym)))))))
+ (cut fmt <> (cdr result))
+ (car result))))))
;; Builds the documentation from Chicken Doc for a specific symbol
(define (make-doc symbol #!optional (filter-for-type #f))
@@ -584,7 +592,12 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (geiser-completions prefix . rest)
- (map car (find-symbol-information prefix)))
+ (let* ((result (find-symbol-information prefix))
+ (prefix (cdr result))
+ (result-list (car result)))
+ (map
+ (cut string-append prefix <>)
+ (map car result-list))))
(define (geiser-module-completions prefix . rest)
(let ((prefix (->string prefix)))
- [nongnu] elpa/geiser-chicken 6370805 088/102: add geiser# prefix to geiser calls, (continued)
- [nongnu] elpa/geiser-chicken 6370805 088/102: add geiser# prefix to geiser calls, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken 2127c37 097/102: Fix error when compiling define-library form in Chicken, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken b9b12e0 099/102: version update, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken d7d4445 029/102: Refactored to reduce the reliance on regex., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken 0efe613 026/102: Limits search to the line beginning, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken 6743d36 036/102: Stopped over-aggressive memoization, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken e9bebe2 032/102: Adds memoization, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken bfccf97 038/102: Fixes for Literals, Errors and Modules, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken 2481dfc 041/102: Right-most character of arguments was being cut, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken c3731bf 047/102: Oops: shell-quote-binary -> shell-quote-argument, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken bc3f877 049/102: Fuzzy matching for Chicken AutoDoc and Completions,
Philip Kaludercic <=
- [nongnu] elpa/geiser-chicken d3743db 051/102: Fixes a potential endless loop., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken 1d3e6de 023/102: Add general font-lock keywords for all implementations, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken c1f5959 053/102: Remove compilation of chicken module, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken 975fca9 001/102: Initial Chicken support, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken 0e84bba 013/102: The issue arose with numerics, as well., Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken 6adf5fd 018/102: Adds recognition of the 'crunch' R5RS subset, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken 67a7bd5 015/102: Merge remote-tracking branch 'dleslie/proper-windows-loading', Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken c77a8d3 021/102: Adds the ability to have sub-word delimiters, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken 39e128e 030/102: Converts toplevel methods to prefixed methods, Philip Kaludercic, 2021/08/01
- [nongnu] elpa/geiser-chicken 752b9b2 035/102: Minor improvements, Philip Kaludercic, 2021/08/01