See also add-editor-keymap-functions.
See also add-editor-keymap-functions.
(append-editor-operation-menu-items menu [ text-only?]) → void? menu : (or/c (is-a?/c menu%) (is-a?/c popup-menu%)) text-only? : any/c = #t
If text-only? is #f, then menu items that insert non-text snips (such as Insert Image...) are appended to the menu.
The initializer takes a keymap object and returns nothing. The default initializer chains the given keymap to an internal keymap that implements standard text editor keyboard and mouse bindings for cut, copy, paste, undo, and select-all. The right mouse button is mapped to popup an edit menu when the button is released. On Unix, start-of-line (Ctl-A) and end-of-line (Ctl-E) are also mapped.
If on? is #t, m: corresponds to the Command key. If on? is #f, then m: corresponds to no key on Mac OS X.
Returns #t if m: corresponds to Command, #f otherwise.
(open-input-text-editor text-editor [ start-position end-position snip-filter port-name expect-to-read-all? #:lock-while-reading? lock-while-reading?]) → input-port text-editor : (is-a?/c text%) start-position : exact-nonnegative-integer? = 0 end-position : (or/c exact-nonnegative-integer? 'end) = 'end snip-filter : ((is-a?/c snip%) . -> . any/c) = (lambda (s) s) port-name : any/c = text-editor expect-to-read-all? : any/c = #f lock-while-reading? : any/c = #f
An instance of string-snip% in text-editor generates a character sequence in the resulting port. All other kinds of snips are passed to snip-filter to obtain a “special” value for the port. If a snip is returned as the first result from snip-filter, and if the snip is an instance of readable-snip<%>, the snip generates a special value for the port through the read-special method. If snip-filter returns any other kind of snip, it is copied for the special result. Finally, a non-snip first result from snip-filter is used directly as the special result.
The port-name argument is used for the input port’s name. The expect-to-read-all? argument is a performance hint; use #t if the entire port’s stream will be read.
The result port must not be used if text-editor changes in any of the following ways: a snip is inserted (see after-insert), a snip is deleted (see after-delete), a snip is split (see after-split-snip), snips are merged (see after-merge-snips), or a snip changes its count (which is rare; see recounted). The get-revision-number method can be used to detect any of these changes.
To help guard against such uses, if lock-while-reading? argument is a true value, then open-input-text-editor will lock the text-editor and call begin-edit-sequence before it returns and unlock it and call end-edit-sequence after it is safe to use the above methods. (In some cases, it will not lock the editor or put it in an edit sequence at all, if using those methods are always safe.)
(open-output-text-editor text-editor [ start-position special-filter port-name]) → output-port text-editor : (is-a?/c text%)
start-position : (or/c exact-nonnegative-integer? (one/of 'end)) = 'end special-filter : (any/c . -> . any/c) = (lambda (x) x) port-name : any/c = text-editor
If special-filter is provided, it is applied to any value written to the port with write-special, and the result is inserted in its place. If a special value is a snip% object, it is inserted into the editor. Otherwise, the special value is displayed into the editor.
If line counting is enabled for the resulting output port, then the port will report the line, offset from the line’s start, and position within the editor at which the port writes data.
One or more editors can be read from the stream by calling the editor’s read-from-file method. (The number of editors to be read must be known by the application beforehand.) When all editors are read, call read-editor-global-footer. Calls to read-editor-global-header and read-editor-global-footer must bracket any call to read-from-file, and only one stream at a time can be read using these methods or written using write-editor-global-header and write-editor-global-footer.
When reading from streams that span Racket versions, use read-editor-version before this procedure.
(read-editor-version in in-base parse-format? [ raise-errors?]) → boolean? in : (is-a?/c editor-stream-in%) in-base : (is-a?/c editor-stream-in-base%) parse-format? : any/c raise-errors? : any/c = #t
If parse-format? is true, then in-base is checked for an initial "WXME" format indicator. Use #f when "WXME" has been consumed already by format-dispatching code.
If raise-errors? is true, then an error in reading triggers an exception, instead of a #f result.
(text-editor-load-handler [ filename] expected-module-name) → any/c filename : path = string expected-module-name : (or/c symbol? #f)
The handler recognizes editor files by the first twelve characters of the file: WXME01‹digit›‹digit› ## . Such a file is opened for loading by creating a text% object, loading the file into the object with insert-file, and then converting the editor content into a port with open-input-text-editor. After obtaining a port in this way, the content is read in essentially the same way as by the default Racket load handler. The difference is that the editor may contain instances of readable-snip<%>, which are “read” though the snips’ read-special method; see open-input-text-editor for details.
One or more editors can be written to the stream by calling the editor’s write-to-file method. When all editors are written, call write-editor-global-footer. Calls to write-editor-global-header and write-editor-global-footer must bracket any call to write-to-file, and only one stream at a time can be written using these methods or read using read-editor-global-header and read-editor-global-footer.
To support streams that span Racket versions, use write-editor-version before this procedure.
See also File Format.
(write-editor-version out out-base) → boolean? out : (is-a?/c editor-stream-out%) out-base : (is-a?/c editor-stream-out-base%)
The out argument is currently not used, but out-base should be the base for out. In the future, out may record information about the version for later version-sensitive output.
The result is #t if the write succeeded, #f otherwise.