Recent

Author Topic: Template Params edit simultanously  (Read 8694 times)

staratel20

  • Full Member
  • ***
  • Posts: 206
Template Params edit simultanously
« on: February 08, 2016, 02:26:07 pm »
Is it possible to simultaneously replacement parameter of code template? For example I define code template something like this:

Code: Pascal  [Select][+][-]
  1. $Param(0):=0;
  2. while($Param(1)<Count)do
  3. begin
  4.  
  5. inc($Param(2));
  6. end;


and when template inserted I type a (0) parameter as 'i' and at once 'i' appear on place of Param(1) and Param(2). So by typing one symbol I have code:

Code: Pascal  [Select][+][-]
  1. i:=0;
  2. while(i<Count)do
  3. begin
  4.  
  5. inc(i);
  6. end;


I try this definition:

Code: Pascal  [Select][+][-]
  1. $Param(0):=0;
  2. while($Param(0)<Count)do
  3. begin
  4.  
  5. inc($Param(0));
  6. end;

and it works not as I expect.


P/s: also it'll be nice if Code templates can be accessed as a sub-tree node of Editor in Options.
« Last Edit: February 08, 2016, 02:32:52 pm by staratel20 »
Windows 7 SP1 x64, FPC 3.0.0, Lazarus from trunk: http://svn.freepascal.org/svn/lazarus/trunk

CountIdentity, ModeClassName - good property naming
IdentityCount,  ClassNameMode  - bad property naming

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9867
  • Debugger - SynEdit - and more
    • wiki
Re: Template Params edit simultanously
« Reply #1 on: February 08, 2016, 04:05:37 pm »
There are some templates that do that. e.g. trycf (try with create and free)

Code: Pascal  [Select][+][-]
  1. $param(variable) := $param(typename).Create;
  2. try
  3.   |
  4. finally
  5.   $param(variable,sync=1).Free;
  6. end;

"sync=1" keep in sync

staratel20

  • Full Member
  • ***
  • Posts: 206
Re: Template Params edit simultanously
« Reply #2 on: February 08, 2016, 06:03:53 pm »
it's just a WOW ! thank's a lot!
Windows 7 SP1 x64, FPC 3.0.0, Lazarus from trunk: http://svn.freepascal.org/svn/lazarus/trunk

CountIdentity, ModeClassName - good property naming
IdentityCount,  ClassNameMode  - bad property naming

staratel20

  • Full Member
  • ***
  • Posts: 206
Re: Template Params edit simultanously
« Reply #3 on: February 08, 2016, 06:30:24 pm »
No limit for perfection). Is exists the way to change normal tab order? If I create a template:

Code: Pascal  [Select][+][-]
  1. $Param(i):=0;
  2. while($Param(i,Sync=1)<$Param(Count))do
  3. begin
  4.  
  5. inc($Param(i,Sync=1));
  6. end;

and after that type name of my counter - logically I don't need tab to 2nd $Param(i,Sync=1) , but want jump to $Param(Count). Is it can be realized?
Windows 7 SP1 x64, FPC 3.0.0, Lazarus from trunk: http://svn.freepascal.org/svn/lazarus/trunk

CountIdentity, ModeClassName - good property naming
IdentityCount,  ClassNameMode  - bad property naming

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9867
  • Debugger - SynEdit - and more
    • wiki
Re: Template Params edit simultanously
« Reply #4 on: February 08, 2016, 07:51:53 pm »
No limit for perfection). Is exists the way to change normal tab order? If I create a template:
Quote
and after that type name of my counter - logically I don't need tab to 2nd $Param(i,Sync=1) , but want jump to $Param(Count). Is it can be realized?

Not in the templates, and not per template. But globally yes (I think / not tested).

Basically the cells are "syncro edit".

Open Tools/Options go to Editor/Keymap, find the tree for "synron editing"

Normally Tab is assigned to "Next Cell (all selected)", change that and assign it to "Next Cell (all selected / first only)"

all selected = when the cell is activated its content is selected and will be overwritten.
first = only go to cells, were a word had it's first occurrence when syncro was activated.

staratel20

  • Full Member
  • ***
  • Posts: 206
Re: Template Params edit simultanously
« Reply #5 on: February 08, 2016, 08:56:54 pm »
I try to set setting as you describe, but in template above it has no effect. But thank you anyway.

Also I have an idea, that I was realized for the Notepad++ in PythonScript plugin - very useful. The main difference from current realization is that token can be duplicated. When I write a token and press Ctrl+Shift+Right token replace with his text. When I press combination again - if no exists duplicated name of this token - instead of inserted text again appear token(so it cyclic process) and caret stay exact where it was before replacement; if exists duplicated name - instead of just inserted text(of 1st token) now inserts text respective to 2nd token.

Simple example:

Code: Pascal  [Select][+][-]
  1. token   text
  2. i           int
  3. i           integer

I type 'i' and press Ctrl+Shift+Right and see:

Code: Pascal  [Select][+][-]
  1. int|
  2.  
press Ctrl+Shift+Right again and see:

Code: Pascal  [Select][+][-]
  1. integer|

press Ctrl+Shift+Right again and see:

Code: Pascal  [Select][+][-]
  1. i|

if I'm press Ctrl+Shift+Left now I'll see:

Code: Pascal  [Select][+][-]
  1. integer|

It's very-very useful thing. I develop it for HTML to not keep in mind all HTML constructions while learning HTML, but it useful everywhere.
Windows 7 SP1 x64, FPC 3.0.0, Lazarus from trunk: http://svn.freepascal.org/svn/lazarus/trunk

CountIdentity, ModeClassName - good property naming
IdentityCount,  ClassNameMode  - bad property naming

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9867
  • Debugger - SynEdit - and more
    • wiki
Re: Template Params edit simultanously
« Reply #6 on: February 08, 2016, 09:59:34 pm »
Quote
I try to set setting as you describe, but in template above it has no effect. But thank you anyway.
My bad....

in the keymap options go to "Template Editing" (just above syncro)

"rotate" means that pressing tab in the last cell would go back to the firs cell, rather than ending the editing.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9867
  • Debugger - SynEdit - and more
    • wiki
Re: Template Params edit simultanously
« Reply #7 on: February 08, 2016, 10:07:24 pm »
Not sure how that python example works, it takes content from another cell into the current cell ? Or from the current to the next.

As in copy current cell, go to next, paste, go back to current?

You can solve this with an editor macro.

Also you can use code (ctrl space) and word (ctrl w) completion.

staratel20

  • Full Member
  • ***
  • Posts: 206
Re: Template Params edit simultanously
« Reply #8 on: February 08, 2016, 11:46:31 pm »
No, "cells" in context of my Python realization just confusing explanation. There I don't use cells, I mean simple "circular replacement" while you don't see what you are expect. And the variants of text, what appears every time you press Ctrl+Shift+Right can be "assigned" to one token(in brackets - because it's definition with duplication of token names).

>>You can solve this with an editor macro.

Yes, that's what I'm plan to do and that's why I create topic about macros to read file - token definitions are comfortable to save separately from macros code.
Windows 7 SP1 x64, FPC 3.0.0, Lazarus from trunk: http://svn.freepascal.org/svn/lazarus/trunk

CountIdentity, ModeClassName - good property naming
IdentityCount,  ClassNameMode  - bad property naming

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9867
  • Debugger - SynEdit - and more
    • wiki
Re: Template Params edit simultanously
« Reply #9 on: February 09, 2016, 12:53:48 am »
But then its much more than reading the word from a conf file.

You need to keep state, and ideally also know if the caret was moved.

In detail:

* A)

If you start with an "i", then you go to "integer", now your macro can find the list, which contains "integer" and it can go to "int", but now it must go back to "i". Where is that stored?

Macros have no memory between calls.

That also means that the list will need to be loaded each time (slow).

You would need to add some storage for this.
1) per editor, since several editors in different windows can all be in different rotations at the same time.
2) global, to store the file you loaded.

* B)

Ideally but not 100% necessary you want to know if the caret was moved.
If it was the current word surely should become permanent?



The caret movement callback I do not see happening in macros (not anytime  soon).
The rest I am happy to answer question, and possibilities for acceptable patches can be found.

However I think there is an easier route for you.

Write a SynEditPlugin.

You can write your own package. Use the API provided by IDEIntf.
If I am right it has a unit SourceEditorIntf, where you can register a callback that tells you about each SynEdit created. And there you can add your plugin to it. (No need to destroy, SynEdit can do that if it is destroyed)

The plugin can register new commands for the keystrokes. And you can get callbacks from SynEdit on caret moves.

You can write any code you want inside.

There are already a few plugins that can serve as sample. Just search for the class name.


staratel20

  • Full Member
  • ***
  • Posts: 206
Re: Template Params edit simultanously
« Reply #10 on: February 09, 2016, 08:52:09 pm »
Quote
... "integer" and it can go to "int", but now it must go back to "i". Where is that stored?

In PythonScript plugin for Notepad++ it stored in a global variables(defined in file startup.py) - where I was store also the caret pos after replacement. But after your answer I understand, that this will not working because of:

Quote
Macros have no memory between calls.

I read your suggest:

Quote
However I think there is an easier route for you.
...

But it'll takes time to analyze it step by step, and read more thoughtfully and cross-code. Thank you.
Windows 7 SP1 x64, FPC 3.0.0, Lazarus from trunk: http://svn.freepascal.org/svn/lazarus/trunk

CountIdentity, ModeClassName - good property naming
IdentityCount,  ClassNameMode  - bad property naming

staratel20

  • Full Member
  • ***
  • Posts: 206
Re: Template Params edit simultanously
« Reply #11 on: February 16, 2016, 11:29:55 am »
Martin_fr: to avoid same question in future, I register on wiki and add this macros to wiki as Example 3:

http://wiki.freepascal.org/index.php?title=IDE_Window:_Code_Templates&action=submit#Example_3_-_Macros_with_simultaneously_editable_parameters
Windows 7 SP1 x64, FPC 3.0.0, Lazarus from trunk: http://svn.freepascal.org/svn/lazarus/trunk

CountIdentity, ModeClassName - good property naming
IdentityCount,  ClassNameMode  - bad property naming

staratel20

  • Full Member
  • ***
  • Posts: 206
Re: Template Params edit simultanously
« Reply #12 on: February 17, 2016, 12:00:49 am »
Martin_fr: at this time I don't see the Example 3 added by me. Why it was cutted? It was bad idea? Or I have to ask someone to add something to wiki and add only after?
Windows 7 SP1 x64, FPC 3.0.0, Lazarus from trunk: http://svn.freepascal.org/svn/lazarus/trunk

CountIdentity, ModeClassName - good property naming
IdentityCount,  ClassNameMode  - bad property naming

staratel20

  • Full Member
  • ***
  • Posts: 206
Re: Template Params edit simultanously
« Reply #13 on: February 18, 2016, 06:38:56 pm »
Someone can explain me what the rules to add something to wiki correct?
Windows 7 SP1 x64, FPC 3.0.0, Lazarus from trunk: http://svn.freepascal.org/svn/lazarus/trunk

CountIdentity, ModeClassName - good property naming
IdentityCount,  ClassNameMode  - bad property naming

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9867
  • Debugger - SynEdit - and more
    • wiki
Re: Template Params edit simultanously
« Reply #14 on: February 18, 2016, 06:57:23 pm »
I dont see it being added or removed at all.
http://wiki.freepascal.org/index.php?title=IDE_Window:_Code_Templates&action=history

So something must have gone wrong when you tried.

Anyone should be able to register and edit the wiki.
Rules are basic, so long as your content is related to the topic, and not copyrighted by others, then it should be fine.

If you add something it should be visible immediately, so you can check for success. And it will also be listed in the history.

If your text contains links, a captcha will be displayed, and must be solved.

-- EDIT
with regards to adding links.
that is to other pages in the wiki, to the forum, or the bug tracker.
Other external links should not be added.
« Last Edit: February 18, 2016, 08:53:24 pm by Martin_fr »

 

TinyPortal © 2005-2018