GMCodeEditor Class Reference
Inherits from | GMAutoCompleteTextView : NSTextView |
Declared in | GMCodeEditor.h |
Overview
GMCodeEditor is a code editing component. In general it is designed to work as a drop in replacement for NSTextView with very little furhter configuration necessary. However you can tweak it into a fairly complex code editing component.
Configuration notes
Since the exact configuration of a code editor mostly depends on the language being edited, the bulk of the configuration goes into the language file, that GMLanguage is responsible for loading. Therefore the easiest way how to change the behavior of this class is simply to modify these files and then load them with setLanguage:.
Subclassing notes
Notice that this class inherits from GMAutoCompleteTextView since it has autocompletion based on language files. Therefore you can also override any of those methods, although be aware that GMCodeEditor provides a custom implementation of all the methods from the “Methods to consider overriding in subclasses” section. Furthermore the class overrides many NSTextView methods as well as many NSTextStorageDelegate methods.
Despite these warnings, the class is intended to be subclassed.
Tasks
Configuration of the editor
-
– language
The language definition that is currently being edited.
-
– setLanguage:
Set the language to use for editing and syntax highlighting.
-
tabWidth
The number of spaces a tab press will insert and also the amount by which the indent: command will indent the code.
property
Text Editing Commands
-
– indent:
Indents the selected section of text or the current line.
-
– dedent:
Dedents the selected section of text or the current line by one level.
-
– toggleComments:
Inspects the current selection and toggles comments.
-
– scrollToLine:
Scrolls the completion view to the line given and sets the insertion point to the begening of that line.
Properties
tabWidth
The number of spaces a tab press will insert and also the amount by which the indent: command will indent the code.
@property NSUInteger tabWidth
Declared In
GMCodeEditor.h
Instance Methods
dedent:
Dedents the selected section of text or the current line by one level.
- (IBAction)dedent:(id)sender
Declared In
GMCodeEditor.h
indent:
Indents the selected section of text or the current line.
- (IBAction)indent:(id)sender
Declared In
GMCodeEditor.h
language
The language definition that is currently being edited.
- (NSDictionary *)language
Return Value
A dictionary of a language definition.
See Also
Declared In
GMCodeEditor.h
scrollToLine:
Scrolls the completion view to the line given and sets the insertion point to the begening of that line.
- (void)scrollToLine:(NSUInteger)num
Parameters
- num
The line number to scroll to.
Declared In
GMCodeEditor.h
setLanguage:
Set the language to use for editing and syntax highlighting.
- (void)setLanguage:(id)lang
Parameters
- lang
Either a string in which case [GMLanguage languageFromBundleWithName:] will be called, otherwise a dictionary which should be the language representation itself (prefferably constructed with GMLanguage class methods).
Declared In
GMCodeEditor.h
toggleComments:
Inspects the current selection and toggles comments.
- (IBAction)toggleComments:(id)sender
Discussion
If all of the lines selected are commented, then the comments will be removed, otherwise comments will be added.
If the selection is zero length, then the current line is considered the selection.
Declared In
GMCodeEditor.h