Bring back the programmable completion

This commit is contained in:
eknauel 2005-08-18 09:23:59 +00:00
parent dcfe19b989
commit ca2baa2c56
3 changed files with 32 additions and 15 deletions

View File

@ -76,6 +76,7 @@
;; completion functions for arguments and redirection
(define (find-completions-for-arg cmd to-complete)
(debug-message "find-completions-for-arg " cmd "," to-complete)
(let ((prefix (to-complete-prefix to-complete)))
(if prefix
(complete-files/path (expand-file-name prefix (cwd)))
@ -87,6 +88,7 @@
;; completion functions for commands
(define (find-completions-for-command cmd to-complete)
(debug-message "find-completions-for-command " cmd "," to-complete)
(let ((prefix (or (to-complete-prefix to-complete) "")))
(cond
((command-contains-path? prefix)
@ -191,13 +193,27 @@
;; the main part
(define (find-completer type)
(case type
((arg) find-completions-for-arg)
((command) find-completions-for-command)
((redir-dest) find-completions-for-redir)
(else
(error "Unknown completion type" type))))
(define (find-plugin-completer cmd)
(let ((cmd-name (command-executable cmd)))
(cond
((find (lambda (p)
(string=? (command-plugin-command p) cmd-name))
(command-plugin-list))
=> command-plugin-completer)
(else find-completions-for-arg))))
(define (find-completer type . args)
(let-optionals args
((cmd #f))
(debug-message "find-completer " type "," cmd)
(case type
((command) find-completions-for-command)
((redir-dest) find-completions-for-redir)
((arg) (if cmd
(find-plugin-completer cmd)
find-completions-for-arg))
(else
(error "Unknown completion type" type)))))
(define (calculate-cursor-index to-complete completion)
(+ (to-complete-pos to-complete) (string-length completion)))
@ -211,7 +227,7 @@
(debug-message "complete " completion-info)
(and completion-info
(destructure (((type cmd to-complete) completion-info))
(let ((completions ((find-completer type) cmd to-complete)))
(let ((completions ((find-completer type cmd) cmd to-complete)))
(cond
((= (length completions) 1)
(list (unparse-command-line

View File

@ -237,6 +237,7 @@
command-line-parser
command-line-absyn
command-line-compiler
completion-sets
joblist
jobs
run-jobs-internals
@ -483,7 +484,8 @@
handle
conditions
destructuring
(subset srfi-1 (filter-map))
let-opt
(subset srfi-1 (filter-map find))
srfi-13
srfi-14

View File

@ -245,12 +245,11 @@
(register-plugin!
(make-command-plugin
"ftp"
(lambda (command prefix args args-pos)
(cond
((getenv "FTPHOSTS")
=> string-tokenize)
(else
'("ftp.gnu.org" "ftp.x.org"))))
(let* ((hosts '("ftp.gnu.org" "ftp.x.org"))
(cs (make-completion-set hosts)))
(lambda (command to-complete)
(debug-message "ftp completer " command "," to-complete)
(completions-for cs (or (to-complete-prefix to-complete) ""))))
(lambda (command args)
(run/fg (,command ,@args)))))