From 31d9a7d8856ae9a3f73a2e6c0cdc7faa8e683269 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Thu, 15 May 2008 15:29:40 +0000 Subject: [PATCH] use-file-text-mode svn: r9847 --- collects/mred/private/editor.ss | 12 +++- collects/scribblings/gui/editor-intf.scrbl | 75 ++++++++++++++-------- 2 files changed, 60 insertions(+), 27 deletions(-) diff --git a/collects/mred/private/editor.ss b/collects/mred/private/editor.ss index 0689ab7810..894dedf7ba 100644 --- a/collects/mred/private/editor.ss +++ b/collects/mred/private/editor.ss @@ -84,6 +84,7 @@ (define canvases null) (define active-canvas #f) (define auto-set-wrap? #f) + (define use-text-mode? #t) (private* [max-view-size (lambda () @@ -121,6 +122,12 @@ (opt-lambda ([file #f] [format 'guess] [show-errors? #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* [do-load-file (lambda (file format load?) @@ -222,13 +229,14 @@ (let* ([actual-format (if (memq f-format '(copy same)) (-get-file-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] [finished? #f]) (dynamic-wind void (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:begin-busy-cursor) (dynamic-wind diff --git a/collects/scribblings/gui/editor-intf.scrbl b/collects/scribblings/gui/editor-intf.scrbl index 12420d726f..4699b6465a 100644 --- a/collects/scribblings/gui/editor-intf.scrbl +++ b/collects/scribblings/gui/editor-intf.scrbl @@ -282,7 +282,8 @@ locked, etc. @defmethod[#:mode pubment (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?]{ @methspec{ @@ -307,7 +308,8 @@ Returns @scheme[#t]. @defmethod[#:mode pubment (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?]{ @methspec{ @@ -922,11 +924,13 @@ inserts the resulting snip into the editor. @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]) boolean?] [(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]) boolean?])]{ @@ -968,7 +972,8 @@ calling } @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]) (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] - [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]) boolean?]{ @@ -1067,32 +1073,35 @@ prompted for a name. The possible values for @scheme[format] are listed below. A single set of @scheme[format] values are used for loading and saving files: + @itemize{ @item{@scheme['guess] --- guess the format based on extension and/or contents; when saving a file, this is the same as @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['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['standard] --- read/write a standard file (binary format)} + +@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 -@method[text% get-file-format] is always one of @scheme['standard], -@scheme['text], or -@scheme['text-force-cr]. +In a @scheme[text%] instance, the format returned from @method[text% + get-file-format] is always one of @scheme['standard], @scheme['text], + or @scheme['text-force-cr]. 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 (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?]{ @methspec{ @@ -1568,7 +1578,8 @@ Does nothing. @defmethod[#:mode pubment (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?]{ @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] - [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]) boolean?]{ @@ -1960,7 +1972,8 @@ The @scheme[show-errors?] argument is no longer used. @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]) 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%)]) boolean?]{