Recent

Author Topic: [SOLVED] Problem with commands and options (eoAutoIdent, eoTrailingSpaces)  (Read 1400 times)

guest58172

  • Guest
I find very inapropiate to use the editor commands (ecXXX) to execute macros.

Depending on the editor options (auto identation, auto trim trailing spaces), the result change. Is there a better way to handle the problem than to save and restore the options before and after the macro execution ?

Example:

Code: Pascal  [Select][+][-]
  1. procedure curlyBraceCloseAndIndent(editor: TSynEdit);
  2. var
  3.   beg: string;
  4.   i: integer = 1;
  5.   j: integer;
  6.   opts: TSynEditorOptions;
  7. const
  8.   blk = [' ', #9];
  9. begin
  10.   beg := editor.LineText;
  11.   if beg.isEmpty then exit;
  12.   beg := beg[1..editor.CaretX];
  13.   if beg.isEmpty then exit;
  14.   while true do
  15.   begin
  16.     if (i > beg.length) or not (beg[i] in blk) then
  17.       break;
  18.     i += 1;
  19.   end;
  20.   i -= 1;
  21.   opts := editor.Options;
  22.   editor.Options := opts - [eoAutoIndent, eoTrimTrailingSpaces];
  23.   editor.BeginUndoBlock;
  24.   editor.CommandProcessor(ecInsertLine, '', nil);
  25.   editor.CommandProcessor(ecDown, '', nil);
  26.   editor.CommandProcessor(ecInsertLine, '', nil);
  27.   editor.CommandProcessor(ecDown, '', nil);
  28.   for j := 1 to i do editor.CommandProcessor(ecChar, beg[j], nil);
  29.   editor.CommandProcessor(ecChar, '}', nil);
  30.   editor.CommandProcessor(ecUp, '', nil);
  31.   for j := 1 to i do editor.CommandProcessor(ecChar, beg[j], nil);
  32.   editor.CommandProcessor(ecTab, '', nil);
  33.   editor.EndUndoBlock;
  34.   editor.Options := opts;
  35. end;

If I don't save-deactivate-restore the options I have to handle a lot of special cases.

I could use the .Lines but the problem is they don't work with the editor history.
Do I miss a better to do these kind of stuff ?

 

TinyPortal © 2005-2018