Bring back the programmable completion
This commit is contained in:
parent
dcfe19b989
commit
ca2baa2c56
|
@ -76,6 +76,7 @@
|
||||||
;; completion functions for arguments and redirection
|
;; completion functions for arguments and redirection
|
||||||
|
|
||||||
(define (find-completions-for-arg cmd to-complete)
|
(define (find-completions-for-arg cmd to-complete)
|
||||||
|
(debug-message "find-completions-for-arg " cmd "," to-complete)
|
||||||
(let ((prefix (to-complete-prefix to-complete)))
|
(let ((prefix (to-complete-prefix to-complete)))
|
||||||
(if prefix
|
(if prefix
|
||||||
(complete-files/path (expand-file-name prefix (cwd)))
|
(complete-files/path (expand-file-name prefix (cwd)))
|
||||||
|
@ -87,6 +88,7 @@
|
||||||
;; completion functions for commands
|
;; completion functions for commands
|
||||||
|
|
||||||
(define (find-completions-for-command cmd to-complete)
|
(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) "")))
|
(let ((prefix (or (to-complete-prefix to-complete) "")))
|
||||||
(cond
|
(cond
|
||||||
((command-contains-path? prefix)
|
((command-contains-path? prefix)
|
||||||
|
@ -191,13 +193,27 @@
|
||||||
|
|
||||||
;; the main part
|
;; the main part
|
||||||
|
|
||||||
(define (find-completer type)
|
(define (find-plugin-completer cmd)
|
||||||
(case type
|
(let ((cmd-name (command-executable cmd)))
|
||||||
((arg) find-completions-for-arg)
|
(cond
|
||||||
((command) find-completions-for-command)
|
((find (lambda (p)
|
||||||
((redir-dest) find-completions-for-redir)
|
(string=? (command-plugin-command p) cmd-name))
|
||||||
(else
|
(command-plugin-list))
|
||||||
(error "Unknown completion type" type))))
|
=> 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)
|
(define (calculate-cursor-index to-complete completion)
|
||||||
(+ (to-complete-pos to-complete) (string-length completion)))
|
(+ (to-complete-pos to-complete) (string-length completion)))
|
||||||
|
@ -211,7 +227,7 @@
|
||||||
(debug-message "complete " completion-info)
|
(debug-message "complete " completion-info)
|
||||||
(and completion-info
|
(and completion-info
|
||||||
(destructure (((type cmd to-complete) 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
|
(cond
|
||||||
((= (length completions) 1)
|
((= (length completions) 1)
|
||||||
(list (unparse-command-line
|
(list (unparse-command-line
|
||||||
|
|
|
@ -237,6 +237,7 @@
|
||||||
command-line-parser
|
command-line-parser
|
||||||
command-line-absyn
|
command-line-absyn
|
||||||
command-line-compiler
|
command-line-compiler
|
||||||
|
completion-sets
|
||||||
joblist
|
joblist
|
||||||
jobs
|
jobs
|
||||||
run-jobs-internals
|
run-jobs-internals
|
||||||
|
@ -483,7 +484,8 @@
|
||||||
handle
|
handle
|
||||||
conditions
|
conditions
|
||||||
destructuring
|
destructuring
|
||||||
(subset srfi-1 (filter-map))
|
let-opt
|
||||||
|
(subset srfi-1 (filter-map find))
|
||||||
srfi-13
|
srfi-13
|
||||||
srfi-14
|
srfi-14
|
||||||
|
|
||||||
|
|
|
@ -245,12 +245,11 @@
|
||||||
(register-plugin!
|
(register-plugin!
|
||||||
(make-command-plugin
|
(make-command-plugin
|
||||||
"ftp"
|
"ftp"
|
||||||
(lambda (command prefix args args-pos)
|
(let* ((hosts '("ftp.gnu.org" "ftp.x.org"))
|
||||||
(cond
|
(cs (make-completion-set hosts)))
|
||||||
((getenv "FTPHOSTS")
|
(lambda (command to-complete)
|
||||||
=> string-tokenize)
|
(debug-message "ftp completer " command "," to-complete)
|
||||||
(else
|
(completions-for cs (or (to-complete-prefix to-complete) ""))))
|
||||||
'("ftp.gnu.org" "ftp.x.org"))))
|
|
||||||
(lambda (command args)
|
(lambda (command args)
|
||||||
(run/fg (,command ,@args)))))
|
(run/fg (,command ,@args)))))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue