Revision: 2773
http://geany.svn.sourceforge.net/geany/?rev=2773&view=rev
Author: eht16
Date: 2008-07-13 03:52:38 -0700 (Sun, 13 Jul 2008)
Log Message:
-----------
Add support to use template wildcards in snippets.
Modified Paths:
--------------
trunk/ChangeLog
trunk/data/snippets.conf
trunk/doc/geany.html
trunk/doc/geany.txt
trunk/src/editor.c
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2008-07-12 11:46:59 UTC (rev 2772)
+++ trunk/ChangeLog 2008-07-13 10:52:38 UTC (rev 2773)
@@ -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>
* plugins/classbuilder.c:
Modified: trunk/data/snippets.conf
===================================================================
--- trunk/data/snippets.conf 2008-07-12 11:46:59 UTC (rev 2772)
+++ trunk/data/snippets.conf 2008-07-13 10:52:38 UTC (rev 2773)
@@ -6,10 +6,14 @@
# 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
# 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:
-# C, C++, D, Java, Pascal, ASM, Fortran, CAML, Haskell, VHDL, Perl, PHP, Javascript, Python, Ruby,
-# Tcl, Lua, Ferite, Sh, Make, O-Matrix, XML, Docbook, HTML, CSS, SQL, LaTeX, Diff, Conf, None
+# ASM, C, C++, C#, CAML, D, Fortran, FreeBasic, Haskell, Haxe, Java, Pascal, VHDL, Ferite, Javascript,
+# 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]
Modified: trunk/doc/geany.html
===================================================================
--- trunk/doc/geany.html 2008-07-12 11:46:59 UTC (rev 2772)
+++ trunk/doc/geany.html 2008-07-13 10:52:38 UTC (rev 2773)
@@ -6,7 +6,7 @@
<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" />
<title>Geany</title>
<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">
/*
@@ -139,7 +139,7 @@
<br />Nick Treleaven
<br />Frank Lanitz</td></tr>
<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>
<td>0.15</td></tr>
</tbody>
@@ -1098,6 +1098,15 @@
<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
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,
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
@@ -3288,43 +3297,43 @@
<td>The name of the developer.</td>
<td>filetypes, file header, function
description, ChangeLog entry, bsd,
-gpl</td>
+gpl, snippets</td>
</tr>
<tr><td>initial</td>
<td>The developer's initials, e.g. "ET" for
Enrico Tröger or "JFD" for John Foobar Doe.</td>
<td>filetypes, file header, function
description, ChangeLog entry, bsd,
-gpl</td>
+gpl, snippets</td>
</tr>
<tr><td>mail</td>
<td>The email address of the developer.</td>
<td>file header, function description,
-ChangeLog entry, bsd, gpl</td>
+ChangeLog entry, bsd, gpl, snippets</td>
</tr>
<tr><td>company</td>
<td>The company the developer is working for.</td>
<td>filetypes, file header, function
description, ChangeLog entry, bsd,
-gpl</td>
+gpl, snippets</td>
</tr>
<tr><td>year</td>
<td>The current year in the format: YYYY.</td>
<td>filetypes, file header, function
description, ChangeLog entry, bsd,
-gpl</td>
+gpl, snippets</td>
</tr>
<tr><td>version</td>
<td>The initial version of a new file.</td>
<td>filetypes, file header, function
description, ChangeLog entry, bsd,
-gpl</td>
+gpl, snippets</td>
</tr>
<tr><td>date</td>
<td>The current date in the format: YYYY-MM-DD.</td>
<td>filetypes, file header, function
description, ChangeLog entry, bsd,
-gpl</td>
+gpl, snippets</td>
</tr>
<tr><td>untitled</td>
<td>The string "untitled" (this will be
@@ -3332,23 +3341,24 @@
filetype templates.</td>
<td>filetypes, file header, function
description, ChangeLog entry, bsd,
-gpl</td>
+gpl, snippets</td>
</tr>
<tr><td>geanyversion</td>
<td>The actual Geany version, e.g.
"Geany 0.15".</td>
<td>filetypes, file header, function
description, ChangeLog entry, bsd,
-gpl</td>
+gpl, snippets</td>
</tr>
<tr><td>datetime</td>
<td>The current date and time in the format:
DD.MM.YYYY HH:mm:ss ZZZZ.</td>
-<td>file header, function description</td>
+<td>file header, function description,
+snippets</td>
</tr>
<tr><td>filename</td>
<td>The filename of the current file.</td>
-<td>file header</td>
+<td>file header, snippets</td>
</tr>
<tr><td>gpl</td>
<td>This wildcard inserts a short GPL notice.</td>
@@ -4141,7 +4151,7 @@
<div class="footer">
<hr class="footer" />
<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.
</div>
Modified: trunk/doc/geany.txt
===================================================================
--- trunk/doc/geany.txt 2008-07-12 11:46:59 UTC (rev 2772)
+++ trunk/doc/geany.txt 2008-07-13 10:52:38 UTC (rev 2773)
@@ -794,6 +794,16 @@
with "Enrico Tröger". The key to start auto completion can be changed
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,
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
@@ -2994,43 +3004,43 @@
============== ============================================= ==============
developer The name of the developer. filetypes, file header, function
description, ChangeLog entry, bsd,
- gpl
+ gpl, snippets
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,
- gpl
+ gpl, snippets
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
description, ChangeLog entry, bsd,
- gpl
+ gpl, snippets
year The current year in the format: YYYY. filetypes, file header, function
description, ChangeLog entry, bsd,
- gpl
+ gpl, snippets
version The initial version of a new file. filetypes, file header, function
description, ChangeLog entry, bsd,
- gpl
+ gpl, snippets
date The current date in the format: YYYY-MM-DD. filetypes, file header, function
description, ChangeLog entry, bsd,
- gpl
+ gpl, snippets
untitled The string "untitled" (this will be filetypes, file header, function
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
"Geany |(version)|". description, ChangeLog entry, bsd,
- gpl
+ gpl, snippets
-datetime The current date and time in the format: file header, function description
- DD.MM.YYYY HH:mm:ss ZZZZ.
+datetime The current date and time in the format: file header, function description,
+ 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
Modified: trunk/src/editor.c
===================================================================
--- trunk/src/editor.c 2008-07-12 11:46:59 UTC (rev 2772)
+++ trunk/src/editor.c 2008-07-13 10:52:38 UTC (rev 2773)
@@ -48,6 +48,7 @@
#include "symbols.h"
#include "callbacks.h"
#include "geanyobject.h"
+#include "templates.h"
/* holds word under the mouse or keyboard cursor */
@@ -1518,6 +1519,34 @@
}
+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)
{
gchar *str;
@@ -1569,6 +1598,9 @@
pattern = utils_str_replace(pattern, "\t", "%ws%"); /* to avoid endless replacing of \t */
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) */
step = utils_strpos(pattern, "%cursor%");
if (step != -1)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 2770
http://geany.svn.sourceforge.net/geany/?rev=2770&view=rev
Author: ntrel
Date: 2008-07-11 07:49:09 -0700 (Fri, 11 Jul 2008)
Log Message:
-----------
Change plugin API EditorFuncs to use GeanyEditor pointers.
Modified Paths:
--------------
branches/editor-struct/ChangeLog
branches/editor-struct/src/build.c
branches/editor-struct/src/callbacks.c
branches/editor-struct/src/editor.c
branches/editor-struct/src/editor.h
branches/editor-struct/src/msgwindow.c
branches/editor-struct/src/plugindata.h
Modified: branches/editor-struct/ChangeLog
===================================================================
--- branches/editor-struct/ChangeLog 2008-07-11 14:25:26 UTC (rev 2769)
+++ branches/editor-struct/ChangeLog 2008-07-11 14:49:09 UTC (rev 2770)
@@ -7,6 +7,9 @@
instead.
* src/document.c:
Fix segfault in update_type_keywords().
+ * src/build.c, src/plugindata.h, src/msgwindow.c, src/callbacks.c,
+ src/editor.c, src/editor.h:
+ Change plugin API EditorFuncs to use GeanyEditor pointers.
2008-07-08 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
Modified: branches/editor-struct/src/build.c
===================================================================
--- branches/editor-struct/src/build.c 2008-07-11 14:25:26 UTC (rev 2769)
+++ branches/editor-struct/src/build.c 2008-07-11 14:49:09 UTC (rev 2770)
@@ -380,7 +380,8 @@
{
case GBO_COMPILE:
case GBO_MAKE_OBJECT:
- editor_clear_indicators(doc);
+ g_return_if_fail(doc);
+ editor_clear_indicators(doc->editor);
break;
case GBO_BUILD:
@@ -392,7 +393,7 @@
for (i = 0; i < documents_array->len; i++)
{
if (documents[i]->is_valid)
- editor_clear_indicators(documents[i]);
+ editor_clear_indicators(documents[i]->editor);
}
break;
}
@@ -858,7 +859,8 @@
{
GeanyDocument *doc = document_find_by_filename(filename);
- editor_set_indicator_on_line(doc, line - 1); /* will check valid idx */
+ if (doc)
+ editor_set_indicator_on_line(doc->editor, line - 1);
color = COLOR_RED; /* error message parsed on the line */
}
g_free(filename);
Modified: branches/editor-struct/src/callbacks.c
===================================================================
--- branches/editor-struct/src/callbacks.c 2008-07-11 14:25:26 UTC (rev 2769)
+++ branches/editor-struct/src/callbacks.c 2008-07-11 14:49:09 UTC (rev 2770)
@@ -1548,7 +1548,7 @@
GeanyDocument *doc = document_get_current();
if (doc != NULL)
- editor_clear_indicators(doc);
+ editor_clear_indicators(doc->editor);
}
Modified: branches/editor-struct/src/editor.c
===================================================================
--- branches/editor-struct/src/editor.c 2008-07-11 14:25:26 UTC (rev 2769)
+++ branches/editor-struct/src/editor.c 2008-07-11 14:49:09 UTC (rev 2770)
@@ -3074,55 +3074,55 @@
/**
- * Deletes all currently set indicators in the @a document.
+ * Deletes all currently set indicators in the @a editor window.
* Error indicators (red squiggly underlines) and usual line markers are removed.
*
- * @param doc The document to operate on.
+ * @param editor The editor to operate on.
**/
-void editor_clear_indicators(GeanyDocument *doc)
+void editor_clear_indicators(GeanyEditor *editor)
{
glong last_pos;
- g_return_if_fail(doc != NULL);
+ g_return_if_fail(editor != NULL);
- last_pos = sci_get_length(doc->editor->scintilla);
+ last_pos = sci_get_length(editor->scintilla);
if (last_pos > 0)
{
- sci_start_styling(doc->editor->scintilla, 0, INDIC2_MASK);
- sci_set_styling(doc->editor->scintilla, last_pos, 0);
+ sci_start_styling(editor->scintilla, 0, INDIC2_MASK);
+ sci_set_styling(editor->scintilla, last_pos, 0);
}
- sci_marker_delete_all(doc->editor->scintilla, 0); /* remove the yellow error line marker */
+ sci_marker_delete_all(editor->scintilla, 0); /* remove the yellow error line marker */
}
/**
- * This is a convenience function for document_set_indicator(). It sets an error indicator
+ * This is a convenience function for editor_set_indicator(). It sets an error indicator
* (red squiggly underline) on the whole given line.
* Whitespace at the start and the end of the line is not marked.
*
- * @param doc The document to operate on.
+ * @param editor The editor to operate on.
* @param line The line number which should be marked.
**/
-void editor_set_indicator_on_line(GeanyDocument *doc, gint line)
+void editor_set_indicator_on_line(GeanyEditor *editor, gint line)
{
gint start, end;
guint i = 0, len;
gchar *linebuf;
- if (doc == NULL)
+ if (editor == NULL)
return;
- start = sci_get_position_from_line(doc->editor->scintilla, line);
- end = sci_get_position_from_line(doc->editor->scintilla, line + 1);
+ start = sci_get_position_from_line(editor->scintilla, line);
+ end = sci_get_position_from_line(editor->scintilla, line + 1);
/* skip blank lines */
if ((start + 1) == end ||
- sci_get_line_length(doc->editor->scintilla, line) == editor_get_eol_char_len(doc))
+ sci_get_line_length(editor->scintilla, line) == editor_get_eol_char_len(editor->document))
return;
/* don't set the indicator on whitespace */
len = end - start;
- linebuf = sci_get_line(doc->editor->scintilla, line);
+ linebuf = sci_get_line(editor->scintilla, line);
while (isspace(linebuf[i])) i++;
while (len > 1 && len > i && isspace(linebuf[len-1]))
@@ -3132,7 +3132,7 @@
}
g_free(linebuf);
- editor_set_indicator(doc, start + i, end);
+ editor_set_indicator(editor, start + i, end);
}
@@ -3141,23 +3141,23 @@
* No error checking or whitespace removal is performed, this should be done by the calling
* function if necessary.
*
- * @param doc The document to operate on.
+ * @param editor The editor to operate on.
* @param start The starting position for the marker.
* @param end The ending position for the marker.
**/
-void editor_set_indicator(GeanyDocument *doc, gint start, gint end)
+void editor_set_indicator(GeanyEditor *editor, gint start, gint end)
{
gint current_mask;
- if (doc == NULL || start >= end)
+ if (editor == NULL || start >= end)
return;
- current_mask = sci_get_style_at(doc->editor->scintilla, start);
+ current_mask = sci_get_style_at(editor->scintilla, start);
current_mask &= INDICS_MASK;
current_mask |= INDIC2_MASK;
- sci_start_styling(doc->editor->scintilla, start, INDIC2_MASK);
- sci_set_styling(doc->editor->scintilla, end - start, current_mask);
+ sci_start_styling(editor->scintilla, start, INDIC2_MASK);
+ sci_set_styling(editor->scintilla, end - start, current_mask);
}
Modified: branches/editor-struct/src/editor.h
===================================================================
--- branches/editor-struct/src/editor.h 2008-07-11 14:25:26 UTC (rev 2769)
+++ branches/editor-struct/src/editor.h 2008-07-11 14:49:09 UTC (rev 2770)
@@ -186,11 +186,11 @@
void editor_select_paragraph(ScintillaObject *sci);
-void editor_set_indicator_on_line(GeanyDocument *doc, gint line);
+void editor_set_indicator_on_line(GeanyEditor *editor, gint line);
-void editor_set_indicator(GeanyDocument *doc, gint start, gint end);
+void editor_set_indicator(GeanyEditor *editor, gint start, gint end);
-void editor_clear_indicators(GeanyDocument *doc);
+void editor_clear_indicators(GeanyEditor *editor);
void editor_set_font(GeanyDocument *doc, const gchar *font_name, gint size);
Modified: branches/editor-struct/src/msgwindow.c
===================================================================
--- branches/editor-struct/src/msgwindow.c 2008-07-11 14:25:26 UTC (rev 2769)
+++ branches/editor-struct/src/msgwindow.c 2008-07-11 14:49:09 UTC (rev 2770)
@@ -603,7 +603,7 @@
if (doc != NULL)
{
if (! doc->changed) /* if modified, line may be wrong */
- editor_set_indicator_on_line(doc, line - 1);
+ editor_set_indicator_on_line(doc->editor, line - 1);
ret = navqueue_goto_line(old_doc, doc, line);
}
Modified: branches/editor-struct/src/plugindata.h
===================================================================
--- branches/editor-struct/src/plugindata.h 2008-07-11 14:25:26 UTC (rev 2769)
+++ branches/editor-struct/src/plugindata.h 2008-07-11 14:49:09 UTC (rev 2770)
@@ -36,12 +36,12 @@
/* The API version should be incremented whenever any plugin data types below are
* modified or appended to. */
-static const gint api_version = 76;
+static const gint api_version = 77;
/* The ABI version should be incremented whenever existing fields in the plugin
* data types below have to be changed or reordered. It should stay the same if fields
* are only appended, as this doesn't affect existing fields. */
-static const gint abi_version = 41;
+static const gint abi_version = 42;
/** Check the plugin can be loaded by Geany.
* This performs runtime checks that try to ensure:
@@ -425,12 +425,16 @@
NavQueueFuncs;
+struct GeanyEditor;
+
/* See editor.h */
typedef struct EditorFuncs
{
- void (*set_indicator) (struct GeanyDocument *doc, gint start, gint end);
- void (*set_indicator_on_line) (struct GeanyDocument *doc, gint line);
- void (*clear_indicators) (struct GeanyDocument *doc);
+ void (*set_indicator) (struct GeanyEditor *editor, gint start, gint end);
+ void (*set_indicator_on_line) (struct GeanyEditor *editor, gint line);
+ void (*clear_indicators) (struct GeanyEditor *editor);
+ /* Remember to convert any GeanyDocument or ScintillaObject pointers in any
+ * appended functions to GeanyEditor pointers. */
}
EditorFuncs;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.