TheIDE macros
TheIDE macros are written in Esc scripting language and placed in .usc files. .usc files can be either part of regular packages or are placed in Common or Local directory.
Macro definition in .usc file starts with header in form
macro Macro_menu:Macro_item Key
where Macro_menu and Macro_item are text literals (with C syntax) and Key is key description similar to those shown in menus. Macro_menu with : and Key can be omitted. Macro header is followed by Esc body.
Examples:
macro "Navigation":"Find next \"TopWindow\"" Ctrl+T {
.Find("TopWindow");
}
macro "Insert current date" {
s = [];
tm = GetSysTime();
s << to_string(tm.year) << "-" << to_string(tm.month) << "-" << to_string(tm.day);
.Insert(s);
}
Formally, from Esc perspective, macro is a "method" of editor - all editor commands are written in "method" notation (starting with dot).
Most of editor methods are provided in two ("overloaded") forms - implicit that works with cursor and selection or explicit with given positions.
Set of editor methods:
|
Method
|
Description
|
GetLength()
|
Length of text.
|
GetLineCount()
|
Number of lines in text.
|
GetLinePos(line)
|
Position (offset from the beginning of the file) of the first character of line.
|
GetCursor()
|
Cursor offset.
|
GetLine(position)
|
Line for given position.
|
GetColumn(position)
|
Position in line for given position.
|
GetSelBegin()
|
Start of selection.
|
GetSelCount()
|
Number of characters in selection. If zero, GetSelBegin() is equal to GetCursor().
|
SetCursor(position)
|
Sets cursor to given position.
|
SetSelection(position, count)
|
Sets selection starting with position with count characters.
|
ClearSelection()
|
Cancels selection.
|
Get(position, count)
|
Returns array of count characters, starting at position.
|
Get(position)
|
Same as Get(position, 1).
|
Remove(position, count)
|
Removes count characters at position.
|
Remove(count)
|
Same as Remove(GetCursor(), count) - removes count characters at cursor position.
|
Remove()
|
Same as Remove(GetSelBegin(), GetSelCount()) - removes selection.
|
Insert(position, text)
|
Inserts array of characters text at the position.
|
Insert(text)
|
Same as Insert(GetCursor(), text) - inserts text at cursor position.
|
Find(text, down, whole_word, ignore_case, wildcards)
|
Finds text, using give options. Options can be omitted - in that case down is considered true and rest of options false. If text is found, function returns 1, otherwise 0.
|
Replace(text, replace_with, whole_word, ignore_case, widcards)
|
Block replace, using given options. Options ca be omitted - in that case they are considered false. Returns number of strings replaced.
|
MoveLeft(...)
MoveRight(...)
MoveWordLeft(...)
MoveWordRight(...)
MoveUp(...)
MoveDown(...)
MoveHome(...)
MoveEnd(...)
MovePageUp(...)
MovePageDown(...)
MoveTextBegin(...)
MoveTextEnd(...)
MoveLeft(sel)
MoveRight(sel)
MoveWordLeft(sel)
MoveWordRight(sel)
MoveUp(sel)
MoveDown(sel)
MoveHome(sel)
MoveEnd(sel)
MovePageUp(sel)
MovePageDown(sel)
MoveTextBegin(sel)
MoveTextEnd(sel)
|
Moves cursor in given direction. Variant with sel makes selection (like when corresponding movement while pressing Shift key) if sel is 1.
|
Input(label, ....)
|
Simple input dialog. Provides as many input text fields as is number of parameters specifying labels for these fields. If user chooses Cancel, returns void, otherwise returns single string if there is just one edit field or array of strings for multiple edit fields.
|
Execute(cmdline)
|
Executes cmdline, capturing the output to the console.
|
Launch(cmdline)
|
Launches the application.
|
ClearConsole()
|
Clear the output console.
|
|
|
|