Author Topic: Code Templates Tricks & Tips  (Read 5382 times)

Offline Stefan

  • Administrator
  • Hero Member
  • *****
  • Posts: 775
  • Karma: +6/-0
Code Templates Tricks & Tips
« on: December 04, 2008, 04:29:56 PM »
First one question to Alex:

Code Templates > [Insert Tag...] > %SurroundedText%

....shouldn't this term called  %SelectedText% ?
Or did i miss the point ??? -  Maybe it's my bad english?
Stefan, HippoEDIT beta tester 
HippoEDIT - the editor programmers wants to code thyself when they are dreaming.        -Don't just edit. HippoEDIT!-

Offline Stefan

  • Administrator
  • Hero Member
  • *****
  • Posts: 775
  • Karma: +6/-0
Re: Code Templates Tricks & Tips
« Reply #1 on: December 04, 2008, 04:38:01 PM »
Ask for help:



I want to surround word under cursor by %-sign
I have
Code Templates > [Insert Tag...] > %%%CurrentWord%%%
to get %word% in my document.

But this works for full selected word only, not if i just stand on an word.
Is there an idea to get this done?
I mean - just put corsur over an word like wo|rd - press an shortcut and become %wo|rd% ?
Or could this consider as feature wish?
Or should i wait?

Offline alex

  • Developer
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2219
  • Karma: +37/-3
    • HippoEDIT
Re: Code Templates Tricks & Tips
« Reply #2 on: December 04, 2008, 11:53:51 PM »
First post: I have renamed %SurroundedText% to %SelectedText%. Would be in next beta.
Second post:
Quote
But this works for full selected word only, not if i just stand on an word.
- it is a bug. I would fix it.

Offline Stefan

  • Administrator
  • Hero Member
  • *****
  • Posts: 775
  • Karma: +6/-0
Re: Code Templates Tricks & Tips
« Reply #3 on: December 07, 2008, 12:45:22 AM »
If you want to learn more about "Code Templates"
- open an new *.html file
- and type <fo

You will see an hint for "Auto complied" 'fo' to 'font' (withe on black) , use this too if you want.
But interesting for use is the (black on yellow) hint 'font' which indicates an "Code Templates"  key.
If you press ENTER-key, this "Code Templates" '<font' is executed and you will get '<FONT SIZE=""></FONT>'

An second example is '<!doctype' ..... you will get '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">'

Tip: is this doesn't work for you --then you have waited to long time before pressing ENTER.
As an solution just delete and re-type the last char.
Or perhaps you test this not in an *.html file?


To see where this cames from, and to set your own "Code Templates", open "Tools > Options..."
- on the left chose "[ + ] Syntax settings"
- then chose "+HTML"
- and "Code Templates"
- click on the  right side on '<!doctype'
- and click on [Edit...]

key* [ ] is the keyword to write in the document, f.ex. '<fo' or '<!doctype', followed by ENTER
key* is also the name of this template and required, hence the *-sign
Descriptin [ ] is an explanation what this template does
Shortcut [ ] is to set an keyboard shortcut to execute this template as alternative to 'key*'

In the Code: -box you can add or modify your code.
You can insert some 'place holders' too, see the buttons at the bottom.

Now close the "Code Templates" -window.




Back in your HTML document type '<a' and press ENTER.
Now you are promted for an Link, enter f.ex. 'www.hippoedit.com' and press ENTER.
Now type in the Link test: 'Home page of the best editor' and press ENTER.
You will get '<A HREF="www.hippoedit.com">Home page of the best editor[/url]'

Where does this comes from?
Open again HTML "Code Templates"

Chose on the right '<a'
and take an look on the Code: '<A HREF="%Link%">%Link Text%[/url]%|%'

You see that word between %..% will be used to prompt you
to enter something, which then replaced the %word% place holder
and insert the expanded result into your document.

'%|%' is where the cursor should stand after template execution.


To test this behaviour modify this Code:
from
<A HREF="%Link%">%Link Text%[/url]%|%
to
<A HREF="%Link%" Target="%Target%">%Link Text%[/url]%|%

then you will be promped additionally for 'Target' where you could insert '_blank'
(_blank will open the link in a new browser window, instead overwriting the current window)


---

You can use menu "Format > Extract Template..."
(BTW: which should be called "Extract to Template" or "Template from Block")
to create new templates on the fly.

---

There is no menu entry or window-on-the-side to visible chose an template from an list,
but i am sure this is already on Alex long feature-wish list ;-)

I hope you enjoy HippoEDIT
« Last Edit: December 07, 2008, 12:48:10 AM by Stefan »

Offline Stefan

  • Administrator
  • Hero Member
  • *****
  • Posts: 775
  • Karma: +6/-0
Re: Code Templates Tricks & Tips
« Reply #4 on: December 08, 2008, 10:49:32 PM »
Since beta from 08.12.2008, 1.4 build 550

you can use token %CurrentWord% to surround an word under cursor by an sign, f.ex. by "..." or %...% or....or...

To enclose word under cursor by %...% use an double % on each side of token %CurrentWord%
to get %%%CurrentWord%%% as an template code.

Now add an shortcut to this template, - later use this shortcut while your cursor is over an word, and this word will be enclosed by signs.

For other signs then % you have to add them only once (because %-sign is an meta char of the templates)
f.ex. to enclose words by "..." use "%CurrentWord% " as template code.

This works also for words like 'var_word'.
To enclose strings like   'This is an sentence'  select them before.


If you would like to use one shortcut for different enclosing signs and to be prompted for them,
use this as template: %EncloseWith%%CurrentWord%%EncloseWith% (yes!, use one token twice)
This way you will be prompted once for an input which will be used twice, one time as before-sign and also as after-sign.

If you need different signs in front and after, just create two different place holders like
%EncloseWithBefore%%CurrentWord%%EncloseWithAfter% and you will be prompted twice.
So, f.ex. you could enter '<' as before-sign and '>' as after-sign.


Note that all place holders not found with [Insert Tag...] and [Environment...]
are treated as user-tokens and you will be prompted to type your input in.

.
« Last Edit: December 08, 2008, 10:53:10 PM by Stefan »

Offline Stefan

  • Administrator
  • Hero Member
  • *****
  • Posts: 775
  • Karma: +6/-0
Re: Code Templates Tricks & Tips
« Reply #5 on: December 08, 2008, 11:10:11 PM »
Since beta from 08.12.2008, 1.4 build 550

you can prefix and/or suffix all selected lines by using template code %Prefix%%SelectedLine%%Suffix%


F.ex.
1) select a few lines
2.) execute this template
3.) enter 'MsgBox ' as prefix and ' & var_Test' as suffix

or enter 'Xcopy /M /F /what /ever ' as prefix and '  X:\Backup\TargetFolder' as suffix

or select an block and set '(' as prefix and ')' as suffix.

or just add an prefix like 'REM ' only.

--

Note that all place holders not found with [Insert Tag...] and [Environment...]
are treated as user-tokens and you will be prompted to type your input in.

So you will be prompted for %Prefix% and %Suffix% placeholder.
Of course you could add an template with fixed prefix and/or suffix signs
by using an code like your-prefix-sign%SelectedLine%your-suffix-sign.
f.ex.: [%SelectedLine%] or "%SelectedLine%" or ("%SelectedLine%")
« Last Edit: December 08, 2008, 11:15:56 PM by Stefan »

Offline Stefan

  • Administrator
  • Hero Member
  • *****
  • Posts: 775
  • Karma: +6/-0
HippoEDIT explained: Code Hints
« Reply #6 on: January 24, 2009, 12:52:16 PM »
What are Code Hints? / code templates / snippets

From the HippoEDIT help:
Code hints will help in runtime during typing,
suggest you best guesses examine words statistics, dictionaries and templates.
By pressing Tab or Enter, when Code Hint is shown, you can insert it into your code, not typing rest of chars.
The hint color shows how suggestion relevant.

- - -


For example open an new "C++" file, perhaps with extension  '.c'
Here type 'for' and you will get an code hint like for (int i = 0; i < ; i++) {  }

If you press quick enough Tab or Enter -key, the code is inserted into your document like

for (int i = 0; i < ; i++)
{

}



- - -


Go to ..\HippoEDIT\syntax\ -folder and take an look into c++_user.xml
There you will find all code hints for 'CPP' -files   
(see the <SYNTAX id="cpp"> tag?
In the 'c++_spec.xml' file you will see  '<FilePattern mask="*.c;*.cpp;*.cxx;*.hpp;*.hxx;*.inl;*.h">' 
that says for what file extension this code hints will work )




-----------------------------------------------------------------


You can build your own code hints:

Note:
  - you have to edit an xxx_user.xml file
  - if you want to have this hints in some syntax only, then edit now this special syntax file, like those for 'C++' the 'c++_user.xml'
  - if you want this code hints for all documents, edit now an "default" syntax file like "def_user.xml"


-

Some notes from Alex:
Quote
Default, Default Source, Default Text schemas
As you know syntax schemas in HE can be inherited. 
So schema from which everything starts is Default.
Then comes two schemas as Default Source and Default Text which are the base for two families of syntaxes.
One for source code (c++, php, css etc) and another for text based (Plain text, xml, html etc) documents.
The rest of syntaxes inherit one of them, depending of what is more suitable.
This is done in such way to not copy same styles and properties from schema to schema and make everything ... a little bit "structured"..

-


I want to edit the "def_user.xml"
  - i open them in an editor
  - between <SYNTAX id="def">   and    <SPECIFICATION>
    i write the start and end tag for code templates, that are  <CodeTemplates>   and    </CodeTemplates>    to get:


          <SYNTAX id="def">
          <CodeTemplates>

          </CodeTemplates>   
       <SPECIFICATION>



  - between <CodeTemplates>   and    </CodeTemplates>  i insert an template as like:

       <Template key="trigger  key" descr="text to display as hint"  > code to insert  </Template>


-


For example you could add this to test this feature:
       <Template key="#c" descr="hint, press enter now"  > HippoEDIT is an text editor</Template>



If  you have this code  now in your "def_user.xml" file:

      <SYNTAX id="def">
          <CodeTemplates>

           <Template key="#c" descr="hint, press enter now"  > HippoEDIT is an text editor</Template>   
                </CodeTemplates>
   
      <SPECIFICATION>

...you can save this file and restart HippoEDIT.


Open an new document.
If you press the keys '#c'
you should see an black hint saying:   "hint, press enter now",
if you press Tab or Enter quickly
the text    'HippoEDIT is an text editor'    should be inserted into your current document.



----------------



For example i have made this code template for my own use:


   <CodeTemplates>
       <Template key="#l" descr="insert Lorem ipsum">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nullapariatur.Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</Template>
   </CodeTemplates>   


If i press '#L' i see 'insert Lorem ipsum' and get inserted an Lorem ipsum-text.

-

If this line is too long for you,
you can insert manually line breaks into the template by using '\n' as line break indicator,
like in the following example:

       <Template key="#l" descr="insert Lorem ipsum">Lorem ipsum dolor sit amet, consectetur adipisicing elit,\nsed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,\nquis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\nDuis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nullapariatur.\nExcepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</Template>


Note: this template is still one long line, but will break in several parts at the \n -signs if you insert this template in your document.


- - -


An other example  would be:

<Template key="myAddress" descr="insert my address"  >Sincerely yours,\n\nJohn Doe\n\nBehind the Fences\n12345 Nowhere City\ne-Mail: Jodo@myhost.com</Template>



To create such an line with correct line breaks you may want to do the following:

1.) write your code/text in an normal manner

Sincerly yours,

John Doe

Behind the Fences
12345 Nowhere City
e-Mail: Jodo@myhost.com





2.) then select this lines

3.) open Search-and-Replace dialog
4.)
Find what: $
Replace: \\n
[X] Regular Expression

That means:
$ match an end of line,
\n means insert an line break.
Because HippoEDIT would really insert an line break instead put the signs '\n' in,
we have to escape the backslash by an another backslash, that is why we replace with: '\\n'



So we should get this:
Sincerly yours,\n
\n
John Doe\n
\n
Behind the Fences\n
12345 Nowhere City\n
e-Mail: Jodo@myhost.com






5.) now, the lines are still selected, use "Format > Join Lines" to get:
Sincerly yours,\n\nJohn Doe\n\nBehind the Fences\n12345 Nowhere City\ne-Mail: Jodo@myhost.com


- - -


Tip:
- as trigger keys use some chars or an word that is uncommon for normal writing, f.ex. use ,m or #a or aaddress
- start with your text to insert right after the '>' sign, without any space in between.

- - -


Some questions left:
- the trigger 'myAddress' is not expanded after a few chars, .... i have to write this trigger completely before i get the hint
- why did this hint is yellow instead of black, i didn't still get it?


- - -


I hope i could make myself clear enough and you will enjoy using HippoEDIT even more now.


.
« Last Edit: January 26, 2009, 09:19:00 AM by Stefan »