Recent

Author Topic: Code Templates - Single letter shortcut, alphabetical ordering, semicolon, slow  (Read 1096 times)

741

  • New Member
  • *
  • Posts: 17
Lazarus 2.2.6 (rev lazarus_2_2_6) FPC 3.2.2 x86_64-win64-win32/win64

Code Templates readily allow me to add (for example) a template with a single-character shortcut like "a" or "b".

So far this is like Delphi.

I want to define a begin...else statement without an 'else', and my desired shortcut is "b".

So I add a token "b" - that is because it is faster to type "b" than typing in a longer string. Then the template is defined.

begin
   |
end;

The template is saved OK (it can be seen in the Code Template editor) - but it does not (seem to) appear in the list when I use CTRL+J...
...Further slow, manual scrolling reveals that the "b" template has been added in-between "withb" and "withs".

Next I do the same thing, with the token "bb". This time, the entry gets appended to the very end of the list.

I'd expect the pop-up list to sort alphabetically... in fact I have to scroll all over the list to find what I want.

All these things mean that it is not the "great time saver" (https://wiki.freepascal.org/IDE_Window:_Code_Templates) it was in Delphi.

It used to be I typed CTRL+J b and that produced the template I added for "b". That was a time-saver.  No longer.

I type CTRL+J b, then scroll through the entire list.

BTW: I notice that the default entries use $AddSemicolon()  rather than ';', I am not sure if that matters?

jamie

  • Hero Member
  • *****
  • Posts: 6580
Most likely due to the fact its a text file and must be searched each time.

That system should be a compiled bin file with an index header that points to the complete definition or the complete result string.
The only true wisdom is knowing you know nothing

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10310
  • Debugger - SynEdit - and more
    • wiki
Indeed if you open the list (ctrl-j) before typing any letter (that is the cursor is after a space or at BOL) then
- the full list pops up
- it seems not sorted
- it does not filter if you start typing.

That probably could be improved => report it as an issue (it still happens in 3.99)

You can however: type b and then ctrl-j  => as be is a 100% match, the list will not even open, it will complete directly.


Until then, you can enable code templates to be shown with ctrl-space among the completion proposals. And that makes them easier to access.

J-G

  • Hero Member
  • *****
  • Posts: 953
I want to define a begin...else statement without an 'else', and my desired shortcut is "b".

So I add a token "b" - that is because it is faster to type "b" than typing in a longer string. Then the template is defined.

I regularly use this facility, have never 'added a token'  so don't understand your difficulty.

Typing 'b' [Ctrl]+J  creates the Begin - End; already but typing 'be' {Ctrl]+J creates Begin - End Else Begin - End;

FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

741

  • New Member
  • *
  • Posts: 17
The thing is, when I do not want the else statement, then I need to remove it.
So it would be faster to have a distinct shortcut for when I want only

begin
   |
end;

- which is the more common situation in my own experience.

741

  • New Member
  • *
  • Posts: 17

 

TinyPortal © 2005-2018