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.xmlThere 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:
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.com2.) 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.com5.) 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.
.