better completion in emacs mode

Ignore-this: f6e41bcae10c422366b72296e6040086

darcs-hash:20110731163946-c41ad-1b75259fd6523bf3e06f39a9b716a3a0b86a93f5
This commit is contained in:
Jeremie Dimino 2011-07-31 18:39:46 +02:00
parent 11da27db51
commit ca976c49c8
2 changed files with 13 additions and 3 deletions

View File

@ -136,9 +136,16 @@ and process prompt buffer length command argument =
| "complete" ->
let input = read_data ~final_newline:false () in
let start, words = UTop_complete.complete input in
send "completion-start" "";
List.iter (fun (word, suffix) -> send "completion" word) words;
send "completion-stop" "";
let words = List.map fst words in
let prefix = LTerm_read_line.common_prefix words in
let index = String.length input - start in
let suffix = String.sub prefix index (String.length prefix - index) in
if suffix = "" then begin
send "completion-start" "";
List.iter (fun word -> send "completion" word) words;
send "completion-stop" "";
end else
send "completion-word" suffix;
loop prompt buffer length
| command ->
Printf.ksprintf (send "stderr") "unrecognized command %S!" command;

View File

@ -236,6 +236,9 @@ non-sticky mode."
(setq utop-history-next nil)
;; Insert the last prompt
(utop-insert-prompt utop-last-prompt))
;; Complete with a word
((string= command "completion-word")
(insert argument))
;; Start of completion
((string= command "completion-start")
(setq utop-completion nil))