From b61f1789c703b67cd23bc18e7c5f7ab08575075a Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Mon, 22 Oct 2012 11:49:14 -0500 Subject: [PATCH] fix bug in detecting the name of the language (encoding problems) Also, Rackety --- collects/drracket/private/module-language.rkt | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/collects/drracket/private/module-language.rkt b/collects/drracket/private/module-language.rkt index 4adb99cc4b..da97d9f9e1 100644 --- a/collects/drracket/private/module-language.rkt +++ b/collects/drracket/private/module-language.rkt @@ -145,29 +145,31 @@ (inherit get-language-name) (define/public (get-users-language-name defs-text) - (let* ([defs-port (open-input-text-editor defs-text)] - [read-successfully? - (with-handlers ((exn:fail? (λ (x) #f))) - (read-language defs-port (λ () #f)) - #t)]) - (cond - [read-successfully? - (let* ([str (send defs-text get-text 0 (file-position defs-port))] - [pos (regexp-match-positions #rx"#(?:!|lang )" str)]) - (cond - [(not pos) - (get-language-name)] - [else - ;; newlines can break things (ie the language text won't - ;; be in the right place in the interactions window, which - ;; at least makes the test suites unhappy), so get rid of - ;; them from the name. Otherwise, if there is some weird formatting, - ;; so be it. - (regexp-replace* #rx"[\r\n]+" - (substring str (cdr (car pos)) (string-length str)) - " ")]))] - [else - (get-language-name)]))) + (define defs-port (open-input-text-editor defs-text)) + (port-count-lines! defs-port) + (define read-successfully? + (with-handlers ((exn:fail? (λ (x) #f))) + (read-language defs-port (λ () #f)) + #t)) + (cond + [read-successfully? + (define-values (_line _col port-pos) (port-next-location defs-port)) + (define str (send defs-text get-text 0 (- port-pos 1))) + (define pos (regexp-match-positions #rx"#(?:!|lang )" str)) + (cond + [(not pos) + (get-language-name)] + [else + ;; newlines can break things (ie the language text won't + ;; be in the right place in the interactions window, which + ;; at least makes the test suites unhappy), so get rid of + ;; them from the name. Otherwise, if there is some weird formatting, + ;; so be it. + (regexp-replace* #rx"[\r\n]+" + (substring str (cdr (car pos)) (string-length str)) + " ")])] + [else + (get-language-name)])) (define/override (use-namespace-require/copy?) #f)