Download Qedit Scripting Language User Manual

Transcript
Getting the Most Out of Scripting
Coding Tips and Techniques
As with any programming language, there are certain things you should do to write a
script that will compile and run. This section contains a number of simple but
valuable tips and techniques to help you become an expert script developer.
Checking Results of a Search
The Find() document method always returns a value to indicate success or failure.
You should always check this result before doing anything with the found string. If
the search fails i.e. no matched string, the cursor does not move. This means the
LastFoundLength and LastFoundColumn properties are still pointing the last
cursor position or selection. However, LastFoundLine is automatically set 0 after
an unsuccessful search.
Checking the Cursor
The insertion point can take many forms. It can be a simple caret where the cursor
sits between 2 characters in the text. It can be a simple selection where one or more
characters on the same line have been selected. It can be a complex selection where
many characters have been selected on multiple lines. It can also be a complex
selection making up a rectangle.
You can check the Selection document property to determine exactly what the
insertion point looks like. This property is record containing line and column
coordinates and optionally a boolean value in the case of a rectangular selection. The
property can have up to 3 elements:
•
Start: a record containing the starting location coordinates. The coordinates are
stored as Line and Column elements.
•
End: a record containing the end location coordinates. The coordinates are
stored as Line and Column elements.
•
Rectangular: a boolean. If True, indicates a rectangular selection.
Caret Only
If there is no selection, the Selection property contains the Start element only. In
this case, the length of the Selection property is 1.
Qedit Scripting Language User Manual
Getting the Most Out of Scripting • 63