use-file-text-mode

svn: r9847
This commit is contained in:
Matthew Flatt 2008-05-15 15:29:40 +00:00
parent fb65879c50
commit 31d9a7d885
2 changed files with 60 additions and 27 deletions

View File

@ -84,6 +84,7 @@
(define canvases null) (define canvases null)
(define active-canvas #f) (define active-canvas #f)
(define auto-set-wrap? #f) (define auto-set-wrap? #f)
(define use-text-mode? #t)
(private* (private*
[max-view-size [max-view-size
(lambda () (lambda ()
@ -121,6 +122,12 @@
(opt-lambda ([file #f] [format 'guess] [show-errors? #t]) (opt-lambda ([file #f] [format 'guess] [show-errors? #t])
(do-load-file file format #t))]) (do-load-file file format #t))])
(public*
[use-file-text-mode
(case-lambda
[() use-text-mode?]
[(v?) (set! use-text-mode? (and v? #t))])])
(private* (private*
[do-load-file [do-load-file
(lambda (file format load?) (lambda (file format load?)
@ -222,13 +229,14 @@
(let* ([actual-format (if (memq f-format '(copy same)) (let* ([actual-format (if (memq f-format '(copy same))
(-get-file-format) (-get-file-format)
f-format)] f-format)]
[text? (memq actual-format '(text text-force-cr))]) [text? (memq actual-format '(text text-force-cr))]
[text-mode? (and text? use-text-mode?)])
(let ([port #f] (let ([port #f]
[finished? #f]) [finished? #f])
(dynamic-wind (dynamic-wind
void void
(lambda () (lambda ()
(set! port (open-output-file file (if text? 'text 'binary) 'truncate/replace)) (set! port (open-output-file file (if text-mode? 'text 'binary) 'truncate/replace))
(wx:file-creator-and-type file #"mReD" (if text? #"TEXT" #"WXME")) (wx:file-creator-and-type file #"mReD" (if text? #"TEXT" #"WXME"))
(wx:begin-busy-cursor) (wx:begin-busy-cursor)
(dynamic-wind (dynamic-wind

View File

@ -282,7 +282,8 @@ locked, etc.
@defmethod[#:mode pubment @defmethod[#:mode pubment
(can-load-file? [filename path?] (can-load-file? [filename path?]
[format (one-of/c 'guess 'standard 'text 'text-force-cr 'same 'copy)]) [format (one-of/c 'guess 'same 'copy 'standard
'text 'text-force-cr)])
boolean?]{ boolean?]{
@methspec{ @methspec{
@ -307,7 +308,8 @@ Returns @scheme[#t].
@defmethod[#:mode pubment @defmethod[#:mode pubment
(can-save-file? [filename path?] (can-save-file? [filename path?]
[format (one-of/c 'guess 'standard 'text 'text-force-cr 'same 'copy)]) [format (one-of/c 'guess 'same 'copy 'standard
'text 'text-force-cr)])
boolean?]{ boolean?]{
@methspec{ @methspec{
@ -922,11 +924,13 @@ inserts the resulting snip into the editor.
@defmethod*[([(insert-file [filename path-string?] @defmethod*[([(insert-file [filename path-string?]
[format (one-of/c 'guess 'standard 'text 'text-force-cr 'same 'copy) 'guess] [format (one-of/c 'guess 'same 'copy 'standard
'text 'text-force-cr) 'guess]
[show-errors? any/c #t]) [show-errors? any/c #t])
boolean?] boolean?]
[(insert-file [port input-port] [(insert-file [port input-port]
[format (one-of/c 'guess 'standard 'text 'text-force-cr 'same 'copy) 'guess] [format (one-of/c 'guess 'same 'copy 'standard
'text 'text-force-cr) 'guess]
[show-errors? any/c #t]) [show-errors? any/c #t])
boolean?])]{ boolean?])]{
@ -968,7 +972,8 @@ calling
} }
@defmethod[(insert-port [port input-port] @defmethod[(insert-port [port input-port]
[format (one-of/c 'guess 'standard 'text 'text-force-cr 'same 'copy) 'guess] [format (one-of/c 'guess 'same 'copy 'standard
'text 'text-force-cr) 'guess]
[show-errors? any/c #t]) [show-errors? any/c #t])
(one-of/c 'standard 'text 'text-force-cr)]{ (one-of/c 'standard 'text 'text-force-cr)]{
@ -1052,7 +1057,8 @@ See also @method[editor<%> cut].
@defmethod[(load-file [filename (or/c path-string? false/c) #f] @defmethod[(load-file [filename (or/c path-string? false/c) #f]
[format (one-of/c 'guess 'standard 'text 'text-force-cr 'same 'copy) 'guess] [format (one-of/c 'guess 'same 'copy 'standard
'text 'text-force-cr) 'guess]
[show-errors? any/c #t]) [show-errors? any/c #t])
boolean?]{ boolean?]{
@ -1067,32 +1073,35 @@ prompted for a name.
The possible values for @scheme[format] are listed below. A single set of The possible values for @scheme[format] are listed below. A single set of
@scheme[format] values are used for loading and saving files: @scheme[format] values are used for loading and saving files:
@itemize{ @itemize{
@item{@scheme['guess] --- guess the format based on @item{@scheme['guess] --- guess the format based on
extension and/or contents; when saving a file, this is the same as extension and/or contents; when saving a file, this is the same as
@scheme['standard]} @scheme['standard]}
@item{@scheme['standard] --- read/write a standard file (binary format)}
@item{@scheme['text] --- read/write a text file (@scheme[text%] only)}
@item{@scheme['text-force-cr] --- read/write a text
file (@scheme[text%] only); when writing, change automatic
newlines (from word-wrapping) into real carriage returns}
@item{@scheme['same] --- read in whatever format was last loaded or saved} @item{@scheme['same] --- read in whatever format was last loaded or saved}
@item{@scheme['copy] --- write using whatever @item{@scheme['standard] --- read/write a standard file (binary format)}
format was last loaded or saved, but do not change the modification
flag or remember @scheme[filename] (saving only)} @item{@scheme['copy] --- write using whatever format was last loaded
or saved, but do not change the modification flag or remember
@scheme[filename] (saving only)}
@item{@scheme['text] --- read/write a text file (@scheme[text%] only);
file writing uses the platform's text-mode conventions
(e.g., newlines as return--linefeed combinations under Windows) when
not specifically disabled via @method[editor<%> use-file-text-mode]}
@item{@scheme['text-force-cr] --- read/write a text file
(@scheme[text%] only); when writing, change automatic newlines (from
word-wrapping) into real carriage returns}
} }
In a @scheme[text%] instance, the format returned from In a @scheme[text%] instance, the format returned from @method[text%
@method[text% get-file-format] is always one of @scheme['standard], get-file-format] is always one of @scheme['standard], @scheme['text],
@scheme['text], or or @scheme['text-force-cr].
@scheme['text-force-cr].
The @scheme[show-errors?] argument is no longer used. The @scheme[show-errors?] argument is no longer used.
@ -1409,7 +1418,8 @@ Either passes this event on to a caret-owning snip, selects a new
@defmethod[#:mode pubment @defmethod[#:mode pubment
(on-load-file [filename path?] (on-load-file [filename path?]
[format (one-of/c 'guess 'standard 'text 'text-force-cr 'same 'copy)]) [format (one-of/c 'guess 'same 'copy 'standard
'text 'text-force-cr)])
void?]{ void?]{
@methspec{ @methspec{
@ -1568,7 +1578,8 @@ Does nothing.
@defmethod[#:mode pubment @defmethod[#:mode pubment
(on-save-file [filename path?] (on-save-file [filename path?]
[format (one-of/c 'guess 'standard 'text 'text-force-cr 'same 'copy)]) [format (one-of/c 'guess 'same 'copy 'standard
'text 'text-force-cr)])
void?]{ void?]{
@methspec{ @methspec{
@ -1930,7 +1941,8 @@ If @scheme[redraw-now?] is @scheme[#f], the editor will require
@defmethod[(save-file [filename (or/c path-string? false/c) #f] @defmethod[(save-file [filename (or/c path-string? false/c) #f]
[format (one-of/c 'guess 'standard 'text 'text-force-cr 'same 'copy) 'same] [format (one-of/c 'guess 'same 'copy 'standard
'text 'text-force-cr) 'same]
[show-errors? any/c #t]) [show-errors? any/c #t])
boolean?]{ boolean?]{
@ -1960,7 +1972,8 @@ The @scheme[show-errors?] argument is no longer used.
@defmethod[(save-port [port output-port] @defmethod[(save-port [port output-port]
[format (one-of/c 'guess 'standard 'text 'text-force-cr 'same 'copy) 'same] [format (one-of/c 'guess 'same 'copy 'standard
'text 'text-force-cr) 'same]
[show-errors? any/c #t]) [show-errors? any/c #t])
boolean?]{ boolean?]{
@ -2317,6 +2330,18 @@ See also @method[editor<%> add-undo] .
} }
@defmethod*[([(use-file-text-mode) boolean?]
[(use-file-text-mode [on? any/c]) void?])]{
Gets or sets whether the current platform's text mode is used for
writing files in @scheme['text] or @scheme['text-force-cr] mode, which
affects the way that newlines are written. The setting is consulted by
@method[editor<%> save-file] after @method[editor<%> on-save-file] is
called. See also @method[editor<%> load-file] for information on file
modes.
}
@defmethod[(write-footers-to-file [stream (is-a?/c editor-stream-out%)]) @defmethod[(write-footers-to-file [stream (is-a?/c editor-stream-out%)])
boolean?]{ boolean?]{