The Document class represents a text document within the context of your text editing environment. You can use the class to programmatically create, modify, and query these documents.
Document used to be an abstract class, meaning it didn't provide all the functionality itself, but instead relied on subclasses to complete the functionality. One such subclass was CocoaDocument. Although CocoaDocument was available only to macOS and had an ad hoc interface, it possessed many additional features like code animation and rich text.
In SuperCollider 3.6, Document changed a bit and now the "abstract class" descriptor is only partially true. The SuperCollider IDE provides its own version of the Document class. The Emacs editor still supplies ScelDocument (which links to EmacsDocument) as a subclass of Document. As an unfortunate byproduct of the history of Document, there are inconsistencies in the APIs of SCIDE's Document and Emacs' ScelDocument. This help file describes that of SCIDE.
Future versions of SuperCollider will aim to fix these API inconsistencies and restore the functionality of CocoaDocument.
By default envir
it is set to the current Environment. However, you can make it use its own Environment also. Thus, e.g., if you were to set the Environment variable ~myVar = 12
in the current Environment, you can create a new Document window in which that Environment variable is not set.
title | |
string |
An instance of String. The contents of the document. |
envir |
An instance of Environment. The Environment to be used by the interpreter of the document window. By default, it is set to the current Environment. |
Open a document from a path.
path |
The file system path to the document. An instance of String. |
selectionStart |
The beginning of the cursor selection of the file content. |
selectionLength |
The length of the cursor selection of the file content. |
envir |
An instance of Environment. The Environment to be used by the interpreter of the document window. By default, it is set to the current Environment. |
Returns an Array of all open documents.
Returns true if there are edited Documents.
leavePostWindowOpen |
An instance of Boolean. |
Gets/sets the current Document.
value |
A Document. |
Returns all documents.
Get/set A global action to be performed when a key is pressed.
action |
An instance of Function or FunctionList. |
Get/set A global action to be performed when a key is released.
action |
An instance of Function or FunctionList. |
Get/set A an action to be performed up opening or creating a Document.
action |
An instance of Function or FunctionList. |
If autoRun is set to true, documents beginning with the comment /*RUN*/
will be executed immediately after being opened, and also when the class library is recompiled with the document already open in the IDE.
value |
An instance of Boolean. Default value is |
The editor implementation specific class which will handle Documents.
value |
A class for implementing Document. |
Utilities and settings for dealing with documents such as SuperCollider code files. By default the document directory is SuperCollider's application directory.
Get/set the default document directory. The default is dependent on Document: implementationClass.
path |
The file system path to the directory. An instance of String. |
In Main-startUp you can set this to a more practical directory:
p |
The file system path to the directory. An instance of String. |
If it is a relative path, expand it to an absolute path relative to your document directory. Expand tildes in path (your home directory), resolve symbolic links (but not aliases). Also converts from Mac OS 9 path format. See PathName for more complex needs.
Returns a path relative to Document.dir, if the path is inside Document.dir.
path |
The file system path to the directory. An instance of String. |
Get / set the Document's path.
apath |
An instance of String. A files system path. |
Returns the directory of a Document.
A binary operator.
that |
An instance of Document. |
Get/set whether a document is prompts to save if it has been changed. Use this with caution.
bool |
An instance of Boolean. |
Returns true
if the document has been closed.
Returns true
if the document has been edited.
Returns true
if the document is in front.
Saves the current Environment, makes the document current, and performs its Document: toFrontAction.
Performs the Document's Document: endFrontAction and restores the current Environment.
Close a document.
Bring a document to the front.
Get/set the action to be performed on closing the document.
value |
An instance of Function or FunctionList. |
Get/set the action to be performed when the document becomes no longer the front document.
value |
An instance of Function or FunctionList. |
Get / set the action to be performed when the document become the front document.
value |
An instance of Function or FunctionList. |
Get/set the action to be performed on Document: mouseDown.
action |
An instance of Function or FunctionList. The arguments passed to the function are: |
Get/set the action to be performed on Document: mouseUp.
action |
An instance of Function or FunctionList. The arguments passed to the function are: |
Test here and click in front of the numbers: 17 and 23.
Get/set the action to be performed on Document: keyDown.
action |
An instance of Function or FunctionList. The arguments passed to the function are: |
Get/set the action to be performed on Document: keyUp.
action |
An instance of Function or FunctionList. The arguments passed to the function are: |
Select a text range in the string of the document.
start |
The start index. |
length |
The length of the selection. |
Returns the start of a current selection.
Returns the size of a current selection.
Returns the current line as a String.
Returns all full lines from before rangestart
to after rangestart + rangesize
as a String.
Gets or sets the string within a certain range.
string |
A String. |
rangestart |
An Integer. |
rangesize |
An Integer. |
Get a range of text from the document. Synchronous. The text is directly returned.
start |
An Integer for the starting position to access. |
range |
An Integer for the number of characters to retrieve. -1 retrieves to the end of the document. |
Get a range of text from the document. Asynchronous. The text is passed to the action
function as an argument.
action |
A function to evaluate after the request is complete. It is passed one argument, a String, for the retrieved contents. |
start |
An Integer for the starting position to access. |
range |
An Integer for the number of characters to retrieve. -1 retrieves to the end of the document. |
The following methods are usually not used directly or are called by a primitive. Programmers can still call or override these as needed.
A simple implementation of TBT (time based text) http://tbt.dyne.org/?info=download
Changing the default look of documents can be done with the help of the *initAction method. Run the following example once. Afterwards all newly created documents will have a dark grey background. To make this change happen every time you start SuperCollider, put the code inside your startup.scd file (and optionally wrap it in a {}.defer(0.1)
).