Difference between revisions of "Editor Macros PascalScript"

From Lazarus wiki
Jump to navigationJump to search
Line 38: Line 38:
 
     property SelText: string;
 
     property SelText: string;
 
     property SelectionMode: TSynSelectionMode;
 
     property SelectionMode: TSynSelectionMode;
 +
    procedure ClearSelection;
 +
    procedure SelectAll;
 +
    procedure SelectToBrace;
 +
    procedure SelectWord;
 +
    procedure SelectLine(WithLeadSpaces: Boolean);
 +
    procedure SelectParagraph;
 +
  
 
;Search/Replace:
 
;Search/Replace:
Line 65: Line 72:
 
     property LineAtCaret: string;  // read only
 
     property LineAtCaret: string;  // read only
 
     procedure InsertTextAtCaret(aText: String; aCaretMode : TSynCaretAdjustMode);
 
     procedure InsertTextAtCaret(aText: String; aCaretMode : TSynCaretAdjustMode);
 +
    property TextBetweenPoints[aStartPoint, aEndPoint: TPoint]: String              // Logical Points
 +
    procedure SetTextBetweenPoints(aStartPoint, aEndPoint: TPoint;
 +
                                  const AValue: String;
 +
                                  aFlags: TSynEditTextFlags = [];
 +
                                  aCaretMode: TSynCaretAdjustMode;
 +
                                  aMarksMode: TSynMarksAdjustMode;
 +
                                  aSelectionMode: TSynSelectionMode
 +
                                  );
 +
 +
;Clipboard:
 +
    procedure CopyToClipboard;
 +
    procedure CutToClipboard;
 +
    procedure PasteFromClipboard;
 +
    property CanPaste: Boolean    // read only
 +
 +
;Logigal / Physical:
 +
    function LogicalToPhysicalPos(const p: TPoint): TPoint;
 +
    function LogicalToPhysicalCol(const Line: String; Index, LogicalPos
 +
                              : integer): integer;
 +
    function PhysicalToLogicalPos(const p: TPoint): TPoint;
 +
    function PhysicalToLogicalCol(const Line: string;
 +
                                  Index, PhysicalPos: integer): integer;
 +
    function PhysicalLineLength(Line: String; Index: integer): integer;
  
 
== ClipBoard: TClipBoard ==
 
== ClipBoard: TClipBoard ==
  
 
     property AsText: String;
 
     property AsText: String;

Revision as of 02:38, 29 August 2012

General

This feature is available in Lazarus 1.1. To use the feature the package EditorMacroScript must be installed.

This includes the PascalScript package. PascalScript is provided by REM Objects. A minimum package is provided with the Lazarus 1.1 distribution.

See also IDE_Window:_Editor_Macros

Simple actions

All simple Keyboard actions are represented as follows.

ecLeft;
Move Caret one to the left (in the editor that invoked the macro)
ecChar('a');
Inserts an 'a'

See the unit SynEditKeyCmds in pacckage SynEdit, and IDECommands in IDEIntf for a full list. Or use the Recorder to get the names of actions.

Objects provided

Scripts can refer to the invoking SynEdit via the identifier "Caller".

Caller: TSynEdit

The following methods and properties are available:

Caret
   property CaretX: Integer;
   property CaretY: Integer;
   property CaretXY: TPoint;
   property LogicalCaretXY: TPoint;
   property LogicalCaretX: TPoint;
   procedure MoveCaretIgnoreEOL(const NewCaret: TPoint);
   procedure MoveLogicalCaretIgnoreEOL(const NewLogCaret: TPoint);
Selection
   property BlockBegin: TPoint;
   property BlockEnd: TPoint;
   property SelAvail: Boolean; // read only
   property SelText: string;
   property SelectionMode: TSynSelectionMode;
   procedure ClearSelection;
   procedure SelectAll;
   procedure SelectToBrace;
   procedure SelectWord;
   procedure SelectLine(WithLeadSpaces: Boolean);
   procedure SelectParagraph;


Search/Replace
   function SearchReplace(const ASearch, AReplace: string; AOptions: TSynSearchOptions): integer;
   function SearchReplaceEx(const ASearch, AReplace: string; AOptions: TSynSearchOptions; AStart: TPoint): integer;
   TSynSearchOptions = set of
   ( ssoMatchCase, ssoWholeWord,
     ssoBackwards,
     ssoEntireScope, ssoSelectedOnly,  // Default is From Caret to End-of-text (or begin-of-text if backward) 
     ssoReplace, ssoReplaceAll,        // Otherwise the function does a search only
     ssoPrompt,                        // Show the prompt, before replacing
     ssoSearchInReplacement,           // continue search-replace in replacement (with ssoReplaceAll) // replace recursive
     ssoRegExpr, ssoRegExprMultiLine,
     ssoFindContinue                   // Assume the current selection is the last match, and start search behind selection
                                       // (before if ssoBackward) // Default is to start at caret (Only SearchReplace / SearchReplaceEx has start/end param)
   );

Returns the number of replacements done. When Searching, returns 1 if found, 0 if not found. If found the match will be selected (use BlockBegin/End).

 if Caller.SearchReplace('FindMe', ' ', []) > 0 then begin
   // Selection is set to the first occurrence of FindMe (searched from position of caret)
 end;
Text
   property Lines[Index: Integer]: string; // read only
   property LineAtCaret: string;  // read only
   procedure InsertTextAtCaret(aText: String; aCaretMode : TSynCaretAdjustMode);
   property TextBetweenPoints[aStartPoint, aEndPoint: TPoint]: String              // Logical Points
   procedure SetTextBetweenPoints(aStartPoint, aEndPoint: TPoint;
                                  const AValue: String;
                                  aFlags: TSynEditTextFlags = [];
                                  aCaretMode: TSynCaretAdjustMode;
                                  aMarksMode: TSynMarksAdjustMode;
                                  aSelectionMode: TSynSelectionMode
                                 );
Clipboard
   procedure CopyToClipboard;
   procedure CutToClipboard;
   procedure PasteFromClipboard;
   property CanPaste: Boolean     // read only
Logigal / Physical
   function LogicalToPhysicalPos(const p: TPoint): TPoint;
   function LogicalToPhysicalCol(const Line: String; Index, LogicalPos
                             : integer): integer;
   function PhysicalToLogicalPos(const p: TPoint): TPoint;
   function PhysicalToLogicalCol(const Line: string;
                                 Index, PhysicalPos: integer): integer;
   function PhysicalLineLength(Line: String; Index: integer): integer;

ClipBoard: TClipBoard

   property AsText: String;