Add support to use template wildcards in snippets.
git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@2773 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
parent
4ef9af9c6f
commit
d3adc32c19
@ -1,3 +1,9 @@
|
|||||||
|
2008-07-13 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
|
||||||
|
|
||||||
|
* data/snippets.conf, doc/geany.html, doc/geany.txt, src/editor.c:
|
||||||
|
Add support to use template wildcards in snippets.
|
||||||
|
|
||||||
|
|
||||||
2008-07-12 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
|
2008-07-12 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
|
||||||
|
|
||||||
* plugins/classbuilder.c:
|
* plugins/classbuilder.c:
|
||||||
|
@ -6,10 +6,14 @@
|
|||||||
# use %key% for all keys defined in the [Special] section
|
# use %key% for all keys defined in the [Special] section
|
||||||
# you can define a section for each supported filetype to overwrite default settings, the section
|
# you can define a section for each supported filetype to overwrite default settings, the section
|
||||||
# name must match exactly the internal filetype name, run 'geany --ft-names' for a full list
|
# name must match exactly the internal filetype name, run 'geany --ft-names' for a full list
|
||||||
|
#
|
||||||
|
# Additionally, you can use most of the template wildcards like {developer} or {date} in the snippets.
|
||||||
|
# See the documentation for details.
|
||||||
|
|
||||||
# filetype names:
|
# filetype names:
|
||||||
# C, C++, D, Java, Pascal, ASM, Fortran, CAML, Haskell, VHDL, Perl, PHP, Javascript, Python, Ruby,
|
# ASM, C, C++, C#, CAML, D, Fortran, FreeBasic, Haskell, Haxe, Java, Pascal, VHDL, Ferite, Javascript,
|
||||||
# Tcl, Lua, Ferite, Sh, Make, O-Matrix, XML, Docbook, HTML, CSS, SQL, LaTeX, Diff, Conf, None
|
# Lua, Make, O-Matrix, Perl, PHP, Python, Ruby, Sh, Tcl, CSS, Docbook, HTML, XML, Conf, Diff, LaTeX,
|
||||||
|
# reStructuredText, SQL, None
|
||||||
|
|
||||||
# Default is used for all filetypes and keys can be overwritten by [filetype] sections
|
# Default is used for all filetypes and keys can be overwritten by [filetype] sections
|
||||||
[Default]
|
[Default]
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" />
|
<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" />
|
||||||
<title>Geany</title>
|
<title>Geany</title>
|
||||||
<meta name="authors" content="Enrico Tröger Nick Treleaven Frank Lanitz" />
|
<meta name="authors" content="Enrico Tröger Nick Treleaven Frank Lanitz" />
|
||||||
<meta name="date" content="2008-06-19" />
|
<meta name="date" content="2008-06-24" />
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -139,7 +139,7 @@ Stylesheet for Geany's documentation based on a version of John Gabriele.
|
|||||||
<br />Nick Treleaven
|
<br />Nick Treleaven
|
||||||
<br />Frank Lanitz</td></tr>
|
<br />Frank Lanitz</td></tr>
|
||||||
<tr><th class="docinfo-name">Date:</th>
|
<tr><th class="docinfo-name">Date:</th>
|
||||||
<td>2008-06-19</td></tr>
|
<td>2008-06-24</td></tr>
|
||||||
<tr><th class="docinfo-name">Version:</th>
|
<tr><th class="docinfo-name">Version:</th>
|
||||||
<td>0.15</td></tr>
|
<td>0.15</td></tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
@ -1098,6 +1098,15 @@ myname=Enrico Tröger
|
|||||||
<p>Everytime you write <tt class="docutils literal"><span class="pre">myname</span></tt> <TAB> in Geany, it will replace "myname"
|
<p>Everytime you write <tt class="docutils literal"><span class="pre">myname</span></tt> <TAB> in Geany, it will replace "myname"
|
||||||
with "Enrico Tröger". The key to start auto completion can be changed
|
with "Enrico Tröger". The key to start auto completion can be changed
|
||||||
in the preferences dialog, by default it is TAB.</p>
|
in the preferences dialog, by default it is TAB.</p>
|
||||||
|
<p>Since Geany 0.15 you can also use most of the available templates wildcards
|
||||||
|
listed in <a class="reference" href="#template-wildcards">Template wildcards</a>. All wildcards which are listed as
|
||||||
|
<cite>available in snippets</cite> can be used. For instance to improve the above example:</p>
|
||||||
|
<pre class="literal-block">
|
||||||
|
[Default]
|
||||||
|
myname=My name is {developer}
|
||||||
|
</pre>
|
||||||
|
<p>this will replace <tt class="docutils literal"><span class="pre">myname</span></tt> with "My name is " and the value of the template
|
||||||
|
preference <tt class="docutils literal"><span class="pre">developer</span></tt>.</p>
|
||||||
<p>You may change the behaviour Geany recognizes the word to complete,
|
<p>You may change the behaviour Geany recognizes the word to complete,
|
||||||
i.e. where define the start and end of a word. The section "Special" may
|
i.e. where define the start and end of a word. The section "Special" may
|
||||||
contain a key "wordchars" which lists all characters a string may contain
|
contain a key "wordchars" which lists all characters a string may contain
|
||||||
@ -3288,43 +3297,43 @@ wildcards which will be automatically replaced by Geany at startup.</p>
|
|||||||
<td>The name of the developer.</td>
|
<td>The name of the developer.</td>
|
||||||
<td>filetypes, file header, function
|
<td>filetypes, file header, function
|
||||||
description, ChangeLog entry, bsd,
|
description, ChangeLog entry, bsd,
|
||||||
gpl</td>
|
gpl, snippets</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr><td>initial</td>
|
<tr><td>initial</td>
|
||||||
<td>The developer's initials, e.g. "ET" for
|
<td>The developer's initials, e.g. "ET" for
|
||||||
Enrico Tröger or "JFD" for John Foobar Doe.</td>
|
Enrico Tröger or "JFD" for John Foobar Doe.</td>
|
||||||
<td>filetypes, file header, function
|
<td>filetypes, file header, function
|
||||||
description, ChangeLog entry, bsd,
|
description, ChangeLog entry, bsd,
|
||||||
gpl</td>
|
gpl, snippets</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr><td>mail</td>
|
<tr><td>mail</td>
|
||||||
<td>The email address of the developer.</td>
|
<td>The email address of the developer.</td>
|
||||||
<td>file header, function description,
|
<td>file header, function description,
|
||||||
ChangeLog entry, bsd, gpl</td>
|
ChangeLog entry, bsd, gpl, snippets</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr><td>company</td>
|
<tr><td>company</td>
|
||||||
<td>The company the developer is working for.</td>
|
<td>The company the developer is working for.</td>
|
||||||
<td>filetypes, file header, function
|
<td>filetypes, file header, function
|
||||||
description, ChangeLog entry, bsd,
|
description, ChangeLog entry, bsd,
|
||||||
gpl</td>
|
gpl, snippets</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr><td>year</td>
|
<tr><td>year</td>
|
||||||
<td>The current year in the format: YYYY.</td>
|
<td>The current year in the format: YYYY.</td>
|
||||||
<td>filetypes, file header, function
|
<td>filetypes, file header, function
|
||||||
description, ChangeLog entry, bsd,
|
description, ChangeLog entry, bsd,
|
||||||
gpl</td>
|
gpl, snippets</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr><td>version</td>
|
<tr><td>version</td>
|
||||||
<td>The initial version of a new file.</td>
|
<td>The initial version of a new file.</td>
|
||||||
<td>filetypes, file header, function
|
<td>filetypes, file header, function
|
||||||
description, ChangeLog entry, bsd,
|
description, ChangeLog entry, bsd,
|
||||||
gpl</td>
|
gpl, snippets</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr><td>date</td>
|
<tr><td>date</td>
|
||||||
<td>The current date in the format: YYYY-MM-DD.</td>
|
<td>The current date in the format: YYYY-MM-DD.</td>
|
||||||
<td>filetypes, file header, function
|
<td>filetypes, file header, function
|
||||||
description, ChangeLog entry, bsd,
|
description, ChangeLog entry, bsd,
|
||||||
gpl</td>
|
gpl, snippets</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr><td>untitled</td>
|
<tr><td>untitled</td>
|
||||||
<td>The string "untitled" (this will be
|
<td>The string "untitled" (this will be
|
||||||
@ -3332,23 +3341,24 @@ translated to your locale), used in
|
|||||||
filetype templates.</td>
|
filetype templates.</td>
|
||||||
<td>filetypes, file header, function
|
<td>filetypes, file header, function
|
||||||
description, ChangeLog entry, bsd,
|
description, ChangeLog entry, bsd,
|
||||||
gpl</td>
|
gpl, snippets</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr><td>geanyversion</td>
|
<tr><td>geanyversion</td>
|
||||||
<td>The actual Geany version, e.g.
|
<td>The actual Geany version, e.g.
|
||||||
"Geany 0.15".</td>
|
"Geany 0.15".</td>
|
||||||
<td>filetypes, file header, function
|
<td>filetypes, file header, function
|
||||||
description, ChangeLog entry, bsd,
|
description, ChangeLog entry, bsd,
|
||||||
gpl</td>
|
gpl, snippets</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr><td>datetime</td>
|
<tr><td>datetime</td>
|
||||||
<td>The current date and time in the format:
|
<td>The current date and time in the format:
|
||||||
DD.MM.YYYY HH:mm:ss ZZZZ.</td>
|
DD.MM.YYYY HH:mm:ss ZZZZ.</td>
|
||||||
<td>file header, function description</td>
|
<td>file header, function description,
|
||||||
|
snippets</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr><td>filename</td>
|
<tr><td>filename</td>
|
||||||
<td>The filename of the current file.</td>
|
<td>The filename of the current file.</td>
|
||||||
<td>file header</td>
|
<td>file header, snippets</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr><td>gpl</td>
|
<tr><td>gpl</td>
|
||||||
<td>This wildcard inserts a short GPL notice.</td>
|
<td>This wildcard inserts a short GPL notice.</td>
|
||||||
@ -4141,7 +4151,7 @@ USE OR PERFORMANCE OF THIS SOFTWARE.</p>
|
|||||||
<div class="footer">
|
<div class="footer">
|
||||||
<hr class="footer" />
|
<hr class="footer" />
|
||||||
<a class="reference" href="geany.txt">View document source</a>.
|
<a class="reference" href="geany.txt">View document source</a>.
|
||||||
Generated on: 2008-06-24 14:28 UTC.
|
Generated on: 2008-07-13 10:38 UTC.
|
||||||
Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
|
Generated by <a class="reference" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -794,6 +794,16 @@ Everytime you write ``myname`` <TAB> in Geany, it will replace "myname"
|
|||||||
with "Enrico Tröger". The key to start auto completion can be changed
|
with "Enrico Tröger". The key to start auto completion can be changed
|
||||||
in the preferences dialog, by default it is TAB.
|
in the preferences dialog, by default it is TAB.
|
||||||
|
|
||||||
|
Since Geany 0.15 you can also use most of the available templates wildcards
|
||||||
|
listed in `Template wildcards`_. All wildcards which are listed as
|
||||||
|
`available in snippets` can be used. For instance to improve the above example::
|
||||||
|
|
||||||
|
[Default]
|
||||||
|
myname=My name is {developer}
|
||||||
|
|
||||||
|
this will replace ``myname`` with "My name is " and the value of the template
|
||||||
|
preference ``developer``.
|
||||||
|
|
||||||
You may change the behaviour Geany recognizes the word to complete,
|
You may change the behaviour Geany recognizes the word to complete,
|
||||||
i.e. where define the start and end of a word. The section "Special" may
|
i.e. where define the start and end of a word. The section "Special" may
|
||||||
contain a key "wordchars" which lists all characters a string may contain
|
contain a key "wordchars" which lists all characters a string may contain
|
||||||
@ -2994,43 +3004,43 @@ Wildcard Description Available in
|
|||||||
============== ============================================= ==============
|
============== ============================================= ==============
|
||||||
developer The name of the developer. filetypes, file header, function
|
developer The name of the developer. filetypes, file header, function
|
||||||
description, ChangeLog entry, bsd,
|
description, ChangeLog entry, bsd,
|
||||||
gpl
|
gpl, snippets
|
||||||
|
|
||||||
initial The developer's initials, e.g. "ET" for filetypes, file header, function
|
initial The developer's initials, e.g. "ET" for filetypes, file header, function
|
||||||
Enrico Tröger or "JFD" for John Foobar Doe. description, ChangeLog entry, bsd,
|
Enrico Tröger or "JFD" for John Foobar Doe. description, ChangeLog entry, bsd,
|
||||||
gpl
|
gpl, snippets
|
||||||
|
|
||||||
mail The email address of the developer. file header, function description,
|
mail The email address of the developer. file header, function description,
|
||||||
ChangeLog entry, bsd, gpl
|
ChangeLog entry, bsd, gpl, snippets
|
||||||
|
|
||||||
company The company the developer is working for. filetypes, file header, function
|
company The company the developer is working for. filetypes, file header, function
|
||||||
description, ChangeLog entry, bsd,
|
description, ChangeLog entry, bsd,
|
||||||
gpl
|
gpl, snippets
|
||||||
|
|
||||||
year The current year in the format: YYYY. filetypes, file header, function
|
year The current year in the format: YYYY. filetypes, file header, function
|
||||||
description, ChangeLog entry, bsd,
|
description, ChangeLog entry, bsd,
|
||||||
gpl
|
gpl, snippets
|
||||||
|
|
||||||
version The initial version of a new file. filetypes, file header, function
|
version The initial version of a new file. filetypes, file header, function
|
||||||
description, ChangeLog entry, bsd,
|
description, ChangeLog entry, bsd,
|
||||||
gpl
|
gpl, snippets
|
||||||
|
|
||||||
date The current date in the format: YYYY-MM-DD. filetypes, file header, function
|
date The current date in the format: YYYY-MM-DD. filetypes, file header, function
|
||||||
description, ChangeLog entry, bsd,
|
description, ChangeLog entry, bsd,
|
||||||
gpl
|
gpl, snippets
|
||||||
|
|
||||||
untitled The string "untitled" (this will be filetypes, file header, function
|
untitled The string "untitled" (this will be filetypes, file header, function
|
||||||
translated to your locale), used in description, ChangeLog entry, bsd,
|
translated to your locale), used in description, ChangeLog entry, bsd,
|
||||||
filetype templates. gpl
|
filetype templates. gpl, snippets
|
||||||
|
|
||||||
geanyversion The actual Geany version, e.g. filetypes, file header, function
|
geanyversion The actual Geany version, e.g. filetypes, file header, function
|
||||||
"Geany |(version)|". description, ChangeLog entry, bsd,
|
"Geany |(version)|". description, ChangeLog entry, bsd,
|
||||||
gpl
|
gpl, snippets
|
||||||
|
|
||||||
datetime The current date and time in the format: file header, function description
|
datetime The current date and time in the format: file header, function description,
|
||||||
DD.MM.YYYY HH:mm:ss ZZZZ.
|
DD.MM.YYYY HH:mm:ss ZZZZ. snippets
|
||||||
|
|
||||||
filename The filename of the current file. file header
|
filename The filename of the current file. file header, snippets
|
||||||
|
|
||||||
gpl This wildcard inserts a short GPL notice. file header
|
gpl This wildcard inserts a short GPL notice. file header
|
||||||
|
|
||||||
|
32
src/editor.c
32
src/editor.c
@ -48,6 +48,7 @@
|
|||||||
#include "symbols.h"
|
#include "symbols.h"
|
||||||
#include "callbacks.h"
|
#include "callbacks.h"
|
||||||
#include "geanyobject.h"
|
#include "geanyobject.h"
|
||||||
|
#include "templates.h"
|
||||||
|
|
||||||
|
|
||||||
/* holds word under the mouse or keyboard cursor */
|
/* holds word under the mouse or keyboard cursor */
|
||||||
@ -1518,6 +1519,34 @@ void snippets_replace_specials(gpointer key, gpointer value, gpointer user_data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static gchar *snippets_replace_wildcards(GeanyDocument *doc, gchar *text)
|
||||||
|
{
|
||||||
|
gchar *year = utils_get_date_time("%Y", NULL);
|
||||||
|
gchar *date = utils_get_date_time("%Y-%m-%d", NULL);
|
||||||
|
gchar *datetime = utils_get_date_time("%d.%m.%Y %H:%M:%S %Z", NULL);
|
||||||
|
gchar *basename = g_path_get_basename(DOC_FILENAME(doc));
|
||||||
|
|
||||||
|
text = utils_str_replace(text, "{year}", year);
|
||||||
|
text = utils_str_replace(text, "{date}", date);
|
||||||
|
text = utils_str_replace(text, "{datetime}", datetime);
|
||||||
|
text = utils_str_replace(text, "{version}", template_prefs.version);
|
||||||
|
text = utils_str_replace(text, "{initial}", template_prefs.initials);
|
||||||
|
text = utils_str_replace(text, "{developer}", template_prefs.developer);
|
||||||
|
text = utils_str_replace(text, "{mail}", template_prefs.mail);
|
||||||
|
text = utils_str_replace(text, "{company}", template_prefs.company);
|
||||||
|
text = utils_str_replace(text, "{untitled}", GEANY_STRING_UNTITLED);
|
||||||
|
text = utils_str_replace(text, "{geanyversion}", "Geany " VERSION);
|
||||||
|
text = utils_str_replace(text, "{filename}", basename);
|
||||||
|
|
||||||
|
g_free(year);
|
||||||
|
g_free(date);
|
||||||
|
g_free(datetime);
|
||||||
|
g_free(basename);
|
||||||
|
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static gboolean snippets_complete_constructs(GeanyDocument *doc, gint pos, const gchar *word)
|
static gboolean snippets_complete_constructs(GeanyDocument *doc, gint pos, const gchar *word)
|
||||||
{
|
{
|
||||||
gchar *str;
|
gchar *str;
|
||||||
@ -1569,6 +1598,9 @@ static gboolean snippets_complete_constructs(GeanyDocument *doc, gint pos, const
|
|||||||
pattern = utils_str_replace(pattern, "\t", "%ws%"); /* to avoid endless replacing of \t */
|
pattern = utils_str_replace(pattern, "\t", "%ws%"); /* to avoid endless replacing of \t */
|
||||||
pattern = utils_str_replace(pattern, "%ws%", whitespace);
|
pattern = utils_str_replace(pattern, "%ws%", whitespace);
|
||||||
|
|
||||||
|
/* replace any %template% wildcards */
|
||||||
|
pattern = snippets_replace_wildcards(doc, pattern);
|
||||||
|
|
||||||
/* find the %cursor% pos (has to be done after all other operations) */
|
/* find the %cursor% pos (has to be done after all other operations) */
|
||||||
step = utils_strpos(pattern, "%cursor%");
|
step = utils_strpos(pattern, "%cursor%");
|
||||||
if (step != -1)
|
if (step != -1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user