fix CDLF conversion when loading a text file into an editor

svn: r14512

original commit: 6082e6a9c385409b11d4240cc311fdcf33ec4727
This commit is contained in:
Matthew Flatt 2009-04-14 16:21:09 +00:00
parent cece9d5dc9
commit cbf7ba42d4

View File

@ -2510,13 +2510,20 @@
(send s-style-list new-named-style "Standard" (send s-style-list basic-style)) (send s-style-list new-named-style "Standard" (send s-style-list basic-style))
(send mf ok?))))))] (send mf ok?))))))]
[(or (eq? format 'text) (eq? format 'text-force-cr)) [(or (eq? format 'text) (eq? format 'text-force-cr))
(let loop () (let loop ([saved-cr? #f])
(let ([l (read-string 256 f)]) (let ([l (read-string 256 f)])
(unless (eof-object? l) (unless (eof-object? l)
(insert l) (let ([l2 (if (equal? l "")
(loop)))) l
(if (equal? #\return (string-ref l (sub1 (string-length l))))
(substring l 0 (sub1 (string-length l)))
l))])
(insert (regexp-replace* #rx"\r\n"
(if saved-cr? (string-append "\r" l2) l2)
"\n"))
(loop (not (eq? l l2)))))))
#f])]) #f])])
(when fileerr? (when fileerr?
(error who "error loading the file")) (error who "error loading the file"))