Skip to content

Commit

Permalink
Restore language on retrieval
Browse files Browse the repository at this point in the history
This uses many internal APIs, but I don't see how to do that otherwise.
I already simplified significantly the code (as done elsewhere in the
handin-client), removing various calls to internal APIs in the process.
  • Loading branch information
Blaisorblade committed Oct 4, 2015
1 parent 9bc3bc7 commit 638aba2
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions handin-client/client-gui.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

(require racket/class racket/unit racket/file racket/gui/base net/sendurl
mrlib/switchable-button mrlib/bitmap-label drracket/tool framework
drracket/private/auto-language
"info.rkt" "client.rkt" "this-collection.rkt")

(provide tool@)
Expand Down Expand Up @@ -743,14 +744,30 @@
(write-editor-global-footer stream)
(send base get-bytes)))

; Adapted from
; https://github.com/racket/drracket/blob/a2f8efc910ffd5e0992279ff59bfe7145598d5ba/drracket/drracket/private/unit.rkt#L619-L643
(define (guess-language defs)
(let-values ([(matching-language settings)
(pick-new-language
defs
(drracket:language-configuration:get-languages)
#f #f)])
(when matching-language
(send defs set-next-settings
(drracket:language-configuration:language-settings
matching-language
settings)
#f))))

(define (string->editor! str defs)
(let* ([base (make-object editor-stream-in-bytes-base% str)]
[stream (make-object editor-stream-in% base)])
(read-editor-version stream base #t)
(read-editor-global-header stream)
(send* defs (begin-edit-sequence #f)
(erase) (read-from-file stream)
(end-edit-sequence))
(erase) (read-from-file stream))
(guess-language defs)
(send defs end-edit-sequence)
(read-editor-global-footer stream)))

(define tool-button-label (bitmap-label-maker button-label/h handin-icon))
Expand Down

0 comments on commit 638aba2

Please sign in to comment.