title:: Document Autocompletion
categories:: Platform>OSX, Frontends
summary:: SuperCollider autocompletion on OSX

The autocompletion feature described in this document is available in the OSX version only. It uses the keyDownAction feature of link::Classes/CocoaDocument:: to intercept keystrokes and open the autocompletion interface when specific characters are typed. That feature is not available in all platforms.

The SCEL interface in Linux has its own autocompletion function, accessed by typing <ESC> <TAB>.

Autocompletion is not available in the Windows version as of this writing.

Another way to get information about classes and methods is the class browser, accessed by calling code::.browse:: on a class, e.g. code::Object.browse::. The browser is available in the OSX version, as well as any platform where SwingOSC (http://www.sciss.de/swingOSC) is installed.

section:: Usage

To open a text window with the auto-complete feature enabled, execute the following in SuperCollider:
code::
Document.autoComplete
::

(ac is a shortcut for Auto-complete, to make it easier to type.)

To open a file by pathname:
code::
Document.openFileAutoComplete("myPath.rtf");
Document.openFileAutoComplete("*.sc");	// wildcards are supported
::

To bring up an open-file dialog:
code::
Document.openAutoComplete
::

Autocompletion will be integrated more tightly into the code editor.



section:: Summary

While editing code in an auto-complete code window, the following keystrokes initiate special actions:

table::
## ( || Attempt to match the preceding identifier to method names containing that string, and display a list of methods with their defining classes. Making a selection will insert a method template into your document. "(" Will also match classnames, with the code::.new:: method: code::Rect(:: will show you a method template for Rect-*new.

## . || Attempt to match the preceding identifier to an exact class name, and present a list of class methods (not instance methods). Your selection will insert a method template into the document.

## CTRL-. || attempt to match the preceding identifier to class names containing the identifier, and present a list of those class names. Your selection will open a class browser. You can navigate through the class tree to find the method you want, and press enter in the method list to insert a method template.

## Shortcut in the class browser || Type "^" in the method list to go to the superclass. This allows speedier location of methods inherited from superclasses.

## Special behavior for CTRL-. || When you choose a method in a class browser, its class will be compared to the class you chose in the opening list. If the initial class responds to the method, the initial class will be put into the document; otherwise, the class from the class browser.
::



section:: Feature description

When you type a dot, SuperCollider will to check the previous text to see if it refers to a valid class. If so, a window will be presented with all the class methods (not instance methods) of the class.

So, for example, if you type:
code::
SinOsc.
::

the window will display the options:
code::
ar(freq, phase, mul, add)
buildSynthDef()
buildSynthDef_()
....
::

If you type the first few letters into the text box, the list will reduce itself to the matching entries. If you type 'a', then the list will contain only:
code::
ar(freq, phase, mul, add)
::

Press enter or return, and the method name with all its arguments will be added to your document, leaving the text:
code::
SinOsc.ar(freq, phase, mul, add)
::

You can also click on the item you want in the list (or move through the list with the up and down arrow keys), and then press return.

Pressing escape or closing the window will cancel the auto-complete. Text typed into the text box prior to canceling will be added to the document--so, if you keep typing while the box comes up and you want to ignore it, your text will not be lost.

Similar behavior for method names: when you type an open parenthesis '(', SuperCollider will display a list of all classes that define this method. Type the first few letters of the class name (don't forget to capitalize) to choose the right one.

This treatment is necessary because variables in SuperCollider are not typed. If you enter 'func.value(', the text editor has no way to know what kind of object will be contained in func at the time of execution. So, it presents you with all possible options and allows you to choose.

note::
strong::New::: The autocompleter now supports partial string matching for methods (triggered by typing open-paren) and classes (not by typing dot, but by typing ctrl-dot). In the case of classes, you will be given a list of classes matching the string typed. After you choose from the list, a full class browser will be opened. When you select a method and press enter, a method template will be dropped into the current document.
::

Because the class browser does not show methods defined by superclasses, you may press ^ to go to the superclass.



section:: Further configuration

Use the startup file (see link::Reference/StartupFile::) to define class names and method names to be excluded from the browsers. I like to exclude the most common flow of control mechanisms (code::while::, code::do::, code::if::, etc.).
code::
AutoCompMethodBrowser.exclude([\if, \do, \while, \loop, \collect, \select, \reject, \detect, \add, \put, \at]);
AutoCompClassBrowser.exclude([... list of classes ...]);
::



section:: Quirks and caveats

The auto complete features will be lost from all documents when recompiling the class library.

The method browser does not handle inheritance. If you're browsing a method like code::add::, you won't find link::Classes/Array:: in the list (but you will find its superclass link::Classes/ArrayedCollection::).
