parley command completetion added by iterrogo on Tue Jun 10 21:28:34 2014

; match (foo or foo
(word-class '($ (: (& (~ (or "(" "[")) (~ whitespace)) (+ (~ whitespace)))))

(define (get-scheme-completions)
  (map (lambda (s)
         (string-append s " "))
       (delete-duplicates!
        (map (lambda (sym)
               (let ((string-sym (symbol->string sym)))
                 (if (not (substring-index "#" string-sym))
                          string-sym
                          (cadr (string-split string-sym "#")))))
             (apropos-list "" macros?: #t)))))

(define (get-shell-completions)
  (let ((paths (string-split (get-environment-variable "PATH") ":")))
    (delete-duplicates!
     (flatten
      (map (lambda (files) (map (cut string-append <> " ") files))
           (map (cut directory <>) paths))))))

(completion-choices (lambda (input position last-word)
                      (let* ((full-line (string-append input last-word))
                             (paren-pos (or (substring-index "(" full-line) -1))
                             (bracket-pos (or (substring-index "[" full-line) -1)))
                        (if (> paren-pos bracket-pos)
                            (get-scheme-completions)
                            (get-shell-completions)))))

(add-key-binding! #\tab auto-completion-handler)