General Add-ons Plug-ins Scripting Syntax Files Dictionaries (External)

Scripting API

Twistpad includes scriptable macros (distinct from keyboard macros) that let users program repetitive tasks, store reusable text snippets, and extend the editor beyond its built-in text management tools.

VBScript and Pascal Script are supported, each with complete language features and additional Application and Document objects for editor and document automation.

Application object

The Application object provides high-level document lifecycle management for the script engine, including creation, opening, saving, and closing of multiple Document instances, as well as access to the active document and indexed document collection.

Methods

function NewDocument: Document;
Creates a new, untitled document and adds it to the managed collection, returning the created Document instance.
function OpenDocument(const AFileName: string): Document;
Opens an existing file specified by AFileName as a Document, adds it to the collection, and returns the loaded instance.
function CloseAll(ADiscardChanges: Boolean): Boolean;
Attempts to close all open documents; when ADiscardChanges is true, unsaved changes are discarded, otherwise implementations may prompt or cancel. Returns true on success.
procedure SaveAll;
Saves all open documents that have unsaved modifications.
procedure AddOutputLine(aLine: string);
Adds a line to the output window.

Properties

property ActiveDocument: Document read GetActiveDoc;
Returns the currently active Document, which typically reflects the focused tab or window in the UI. May be nil if no document is open.
property Documents[AIndex: Integer]: Document read GetDocuments;
Indexed access to the managed documents collection by zero-based index. Raises an error if AIndex is out of bounds.
property DocumentCount: Integer read GetDocumentCount;
Returns the number of documents currently opened by the application.

Document object

The Document object centralizes text editing, selection, navigation, search, clipboard, and file I/O for loaded documents.

Functions

function CanRedo: Boolean;
Returns true if there are actions in the redo stack that can be performed, allowing the user to redo previously undone actions.
function CanUndo: Boolean;
Returns true if there are actions in the undo history, meaning the user can revert the last modifications.
function QuickFind(sText: string; bForward: Boolean; bWrap: Boolean): Boolean;
Searches for the specified text (sText) in the document.
  • bForward: If true, search moves forward; else, backward.
  • bWrap: If true, search wraps around the document.
Returns true if the text is found.
function Find(sText: string; bForward, bMatchCase: Boolean; bWholeWordsOnly, bGlobal, bRe, bMoveSelection, bWrap: Boolean): Boolean;
Searches for the specified text (sText) in the document.
  • bForward: If true, search moves forward; else, backward.
  • bMatchCase: If true, the case is matched with the find text.
  • bWholeWordsOnly: If true, only considers whole words only.
  • bGlobal: If true, start the search from the start document, else from the current cursor position.
  • bRe: If true, sText is a regular expression.
  • bMoveSelection: If true, the current selection is moved to the found position.
  • bWrap: If true, search wraps around the document.
Returns true if the text is found.
function Replace(sText, sReplacetext: string; bForward, bMatchCase: Boolean; bWholeWordsOnly, bGlobal, bReplaceAll, bRe, bWrap: Boolean): integer;
Searches for the specified text (sText) in the document and replaces with (sReplacetext).
  • bForward: If true, search moves forward; else, backward.
  • bMatchCase: If true, the case is matched with the find text.
  • bWholeWordsOnly: If true, only considers whole words only.
  • bGlobal: If true, start the search from the start document, else from the current cursor position.
  • bReplaceAll: If true, replaces in all document in one go.
  • bRe: If true, sText is a regular expression.
  • bWrap: If true, search wraps around the document.
Returns the number of replacements made.
function GetEditorCursorPos: TPoint;
Returns the current caret position within the editor as a TPoint structure (X for column, Y for line).
function SaveAs(const AFileName: string): Boolean;
Saves the document under a new file name (AFileName). Returns true on success.
function Close: Boolean;
Closes the current document. Returns true if successful, false otherwise.

Procedures

procedure Cut;
Removes the selected text and copies it to the clipboard.
procedure Copy;
Copies the selected text to the clipboard, keeping the selection intact.
procedure Paste;
Inserts text from the clipboard at the caret position, replacing the current selection if any.
procedure SelectAll;
Selects all the text in the editor.
procedure SelectWord;
Selects the word at the current caret position.
procedure SelectFunction;
Selects the entire function or method block that contains the caret position.
procedure LockDisplay;
Temporarily suspends redraws and display updates. Use to batch multiple changes for performance.
procedure UnlockDisplay;
Resumes display updates after a call to LockDisplay.
procedure AddLine(aLine: string);
Adds the specified string (aLine) as a new line to the document.
procedure Load(const AFileName: string);
Replaces the current document contents by loading from the specified file name.
procedure Save(const AFileName: string);
Saves the document to the given file name. Overwrites existing data if present.

Properties

property SelStart: longint
Gets or sets the position (character offset) where the current selection begins.
property SelLength: longint
Length (in characters) of the current text selection. Setting this property alters the selection size.
property SelPar: longint
Gets or sets the paragraph index of the start of the current selection.
property SelLine: longint
Gets or sets the line number of the start of the current selection.
property SelCol: Integer
Gets or sets the column number at the start of the current selection.
property SelText: string
Gets or replaces the currently selected text.
property Lines: TStrings
Gets the collection of all lines in the document as a TStrings object.
property Text: string
Gets or sets the entire text of the document as a single string.
property IsModified: Boolean
Indicates whether the document has unsaved changes.
property CurrentWord: string
Returns the word at the caret position.
property FileName: string
Gets the file name currently associated with the document.
property index: Integer
Returns the unique index or identifier of the editor instance or document.