Recent

Author Topic: Macro key identifier list  (Read 1053 times)

440bx

  • Hero Member
  • *****
  • Posts: 5805
Macro key identifier list
« on: June 01, 2025, 05:06:17 am »
Hello,

I've been looking for a list of identifiers that can be used in a macro, for instance,

Quote
ecLineStart;
ecChar(<acharacter>);
ecLineBreak;

are some of the available key identifiers, is there a complete list somewhere ?  (searched for it but couldn't find it.) 

I suppose I can look in Synedit's source code if that's the only way of getting a complete list but, I believe they should be documented somewhere.

Thank you for your help.

ETA:

Particularly convenient would be a way to declare an entire string instead of making a string one character at a time using ecChar, something along the lines of ecString(<somestring>) would be great.  if there is no such facility then, consider it a suggestion/feature request.  That would make editing macros a lot easier.

Thanks again.


« Last Edit: June 01, 2025, 05:17:04 am by 440bx »
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

DomingoGP

  • Full Member
  • ***
  • Posts: 106
Re: Macro key identifier list
« Reply #1 on: June 01, 2025, 09:22:48 am »
You can get this list in the source code:

components\synedit\syneditkeycmds.pp

Particularly convenient would be a way to declare an entire string instead of making a string one character at a time using ecChar, something along the lines of ecString(<somestring>) would be great.  if there is no such facility then, consider it a suggestion/feature request.  That would make editing macros a lot easier.

This can be easily achieved by using macros with PascalScript using    procedure InsertTextAtCaret(aText: String; aCaretMode : TSynCaretAdjustMode);

links to the wiki

https://wiki.lazarus.freepascal.org/Editor_Macros_PascalScript
https://wiki.lazarus.freepascal.org/IDE_Window:_Editor_Macros




Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11793
  • Debugger - SynEdit - and more
    • wiki
Re: Macro key identifier list
« Reply #2 on: June 01, 2025, 09:27:34 am »
There is indeed no doc, except for the source.
Usually the easiest way is to record a macro to get the codes, and then edit.

Even I do it that way, since despite working a lot with SynEdit, I can't remember them all.
If I already have a macro, I record into a 2nd (temporary) macro, and copy the command from there.


The list of PascalScript commands is documented: https://wiki.freepascal.org/Editor_Macros_PascalScript



If you want to harvest the "ec..." list, the description of each is in the ide folder, something like *keycommand*.pas and the resourcestring unit...?

You will have to keep out an eye, for when new commands get added. Since the extension of the macro list is just a side effect, and will most likely be forgotten to be documented....

Maybe it be easier if the IDE shows a help window, with a generated list....

What may need to be documented is the exclusion list.

E.g. you can use "single step" (debug) as a macro. But it wont work as you like => well, it will once. But if you have 2 single step, the 2nd is ignored. It does not wait for the step to finish, and the 2nd is "virtually pressed" when the first still runs, so the debugger ignores it. (just like when you press F8 while the debugger already runs)

And also switching editors wont work....

440bx

  • Hero Member
  • *****
  • Posts: 5805
Re: Macro key identifier list
« Reply #3 on: June 01, 2025, 09:35:23 am »
Thank you @DomingoGP and @Martin_fr

That's probably all I needed to know.  Got a couple of macros to write.  I might have additional questions later ;)

Thanks again.

Quote
Maybe it be easier if the IDE shows a help window, with a generated list....
That would be very convenient.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

DomingoGP

  • Full Member
  • ***
  • Posts: 106
Re: Macro key identifier list
« Reply #4 on: June 01, 2025, 09:37:48 am »
You can get this list in the source code:

components\synedit\syneditkeycmds.pp

Particularly convenient would be a way to declare an entire string instead of making a string one character at a time using ecChar, something along the lines of ecString(<somestring>) would be great.  if there is no such facility then, consider it a suggestion/feature request.  That would make editing macros a lot easier.

This can be easily achieved by using macros with PascalScript using    procedure InsertTextAtCaret(aText: String; aCaretMode : TSynCaretAdjustMode);

Edited:
  see ecString  in the command list

links to the wiki

https://wiki.lazarus.freepascal.org/Editor_Macros_PascalScript
https://wiki.lazarus.freepascal.org/IDE_Window:_Editor_Macros


440bx

  • Hero Member
  • *****
  • Posts: 5805
Re: Macro key identifier list
« Reply #5 on: June 01, 2025, 09:51:46 am »
I just tried this and, it didn't work.  Quite likely a complete noobie mistake.

Code: Pascal  [Select][+][-]
  1. begin
  2. ecChar('{');
  3. ecChar('$');
  4. ecChar('i');
  5. ecChar('n');
  6. ecChar('c');
  7. ecChar('l');
  8. ecChar('u');
  9. ecChar('d');
  10. ecChar('e');
  11. ecChar(' ');
  12. ecChar('u');
  13. ecChar('t');
  14. ecChar('i');
  15. ecChar('l');
  16. ecChar('s');
  17. ecChar('.');
  18. ecChar('i');
  19. ecChar('n');
  20. ecChar('c');
  21. ecChar('}');
  22. Synedit.InsertTextAtCaret('test text');
  23. end.                                                
  24.  
I know the ecChar(...) stuff works because the macro worked until I added the Synedit.InsertTextAtCaret(...)

How do I use InsertTextAtCaret ?
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

DomingoGP

  • Full Member
  • ***
  • Posts: 106
Re: Macro key identifier list
« Reply #6 on: June 01, 2025, 10:08:04 am »
You must have the package EditorMacroScript installed.


Note: I have tested the ecString and gives me Error: [Error] (23:1): Unknown identifier 'ecString'  so forget it.


This code works for me.

Code: Pascal  [Select][+][-]
  1. begin
  2. ecChar('{');
  3. ecChar('$');
  4. ecChar('i');
  5. ecChar('n');
  6. ecChar('c');
  7. ecChar('l');
  8. ecChar('u');
  9. ecChar('d');
  10. ecChar('e');
  11. ecChar(' ');
  12. ecChar('u');
  13. ecChar('t');
  14. ecChar('i');
  15. ecChar('l');
  16. ecChar('s');
  17. ecChar('.');
  18. ecChar('i');
  19. ecChar('n');
  20. ecChar('c');
  21. ecChar('}');
  22. Caller.InsertTextAtCaret('test text',scamEnd);
  23. end.

440bx

  • Hero Member
  • *****
  • Posts: 5805
Re: Macro key identifier list
« Reply #7 on: June 01, 2025, 01:26:21 pm »
Thank you @DomingoGP, the "Caller.InsertTextAtCaret(...) works great.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

440bx

  • Hero Member
  • *****
  • Posts: 5805
Re: Macro key identifier list
« Reply #8 on: June 01, 2025, 01:26:33 pm »

There is one thing I'm curious about, ecLineStart, ecChar, ecLineBreak don't need to be prefixed with "Caller", why does InsertTextAtCaret need the prefix ?
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11793
  • Debugger - SynEdit - and more
    • wiki
Re: Macro key identifier list
« Reply #9 on: June 01, 2025, 03:16:50 pm »

There is one thing I'm curious about, ecLineStart, ecChar, ecLineBreak don't need to be prefixed with "Caller", why does InsertTextAtCaret need the prefix ?

I don't recall why I decided to pass the current synedit as object (rather than to add plain methods).

Though it may come in handy, if macros one day in the future can access more than one editor...

440bx

  • Hero Member
  • *****
  • Posts: 5805
Re: Macro key identifier list
« Reply #10 on: June 01, 2025, 03:18:21 pm »
Fair enough!

Thank you Martin.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

n7800

  • Hero Member
  • *****
  • Posts: 542
Re: Macro key identifier list
« Reply #11 on: June 01, 2025, 06:40:04 pm »
Quote
Maybe it be easier if the IDE shows a help window, with a generated list....
That would be very convenient.

In general, it would be wise not to create a separate window, but simply add them to the Completion Window.

As far as I can see, it's not there at all now? It could at least complete the words that appear in the text.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11793
  • Debugger - SynEdit - and more
    • wiki
Re: Macro key identifier list
« Reply #12 on: June 01, 2025, 06:49:30 pm »
In general, it would be wise not to create a separate window, but simply add them to the Completion Window.

That needs a special edition of codetools...  Extending codetools... If anyone feels up to it. I would suggest some sort of callback, so codetools doesn't need to know about the details of macros.

Or maybe codetools can be feed a dummy source that defines them... But only for macro files.

I don't know codetools that well. Despite several excursions into it.

n7800

  • Hero Member
  • *****
  • Posts: 542
Re: Macro key identifier list
« Reply #13 on: June 01, 2025, 08:01:06 pm »
I don't know anything about CodeTools, so I can only add FR to the bug tracker.

 

TinyPortal © 2005-2018