SF.net SVN: geany:[4539] trunk

eht16 at users.sourceforge.net eht16 at xxxxx
Sun Jan 24 14:52:46 UTC 2010


Revision: 4539
          http://geany.svn.sourceforge.net/geany/?rev=4539&view=rev
Author:   eht16
Date:     2010-01-24 14:52:46 +0000 (Sun, 24 Jan 2010)

Log Message:
-----------
Add new special template wildcard "{command:...}" to use the output of a command in templates.
Adjust template functions to mostly work with GeanyDocuments.
Minor cleanups in the template code.

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/data/snippets.conf
    trunk/doc/geany.html
    trunk/doc/geany.txt
    trunk/src/callbacks.c
    trunk/src/editor.c
    trunk/src/templates.c
    trunk/src/templates.h

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2010-01-24 14:18:00 UTC (rev 4538)
+++ trunk/ChangeLog	2010-01-24 14:52:46 UTC (rev 4539)
@@ -2,6 +2,12 @@
 
  * src/utils.c, src/utils.h, src/vte.c:
    Add utils_copy_environment() and make use of it.
+ * data/snippets.conf, doc/geany.html, doc/geany.txt, src/callbacks.c,
+   src/editor.c, src/templates.c, src/templates.h:
+   Add new special template wildcard "{command:...}" to use the
+   output of a command in templates.
+   Adjust template functions to mostly work with GeanyDocuments.
+   Minor cleanups in the template code.
 
 
 2010-01-22  Nick Treleaven  <nick(dot)treleaven(at)btinternet(dot)com>

Modified: trunk/data/snippets.conf
===================================================================
--- trunk/data/snippets.conf	2010-01-24 14:18:00 UTC (rev 4538)
+++ trunk/data/snippets.conf	2010-01-24 14:52:46 UTC (rev 4539)
@@ -10,13 +10,12 @@
 # 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.
+# Additionally, you can use most of the template wildcards like {developer}, {command:...},
+# or {date} in the snippets.
 # See the documentation for details.
 
-# filetype names:
-# 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
+# For a list of available filetype names, execute:
+# geany --ft-names
 
 # Default is used for all filetypes and keys can be overwritten by [filetype] sections
 [Default]

Modified: trunk/doc/geany.html
===================================================================
--- trunk/doc/geany.html	2010-01-24 14:18:00 UTC (rev 4538)
+++ trunk/doc/geany.html	2010-01-24 14:52:46 UTC (rev 4539)
@@ -6,7 +6,7 @@
 <meta name="generator" content="Docutils 0.6: http://docutils.sourceforge.net/" />
 <title>Geany</title>
 <meta name="authors" content="Enrico Tröger  Nick Treleaven  Frank Lanitz" />
-<meta name="date" content="2010-01-01" />
+<meta name="date" content="2010-01-02" />
 <style type="text/css">
 
 /*
@@ -139,7 +139,7 @@
 <br />Nick Treleaven
 <br />Frank Lanitz</td></tr>
 <tr><th class="docinfo-name">Date:</th>
-<td>2010-01-01</td></tr>
+<td>2010-01-02</td></tr>
 <tr><th class="docinfo-name">Version:</th>
 <td>0.19</td></tr>
 </tbody>
@@ -433,50 +433,53 @@
 </ul>
 </li>
 <li><a class="reference internal" href="#customizing-templates" id="id199">Customizing templates</a><ul>
-<li><a class="reference internal" href="#template-wildcards" id="id200">Template wildcards</a></li>
+<li><a class="reference internal" href="#template-wildcards" id="id200">Template wildcards</a><ul>
+<li><a class="reference internal" href="#special-command-wilcard" id="id201">Special {command:} wilcard</a></li>
 </ul>
 </li>
 </ul>
 </li>
-<li><a class="reference internal" href="#customizing-the-toolbar" id="id201">Customizing the toolbar</a><ul>
-<li><a class="reference internal" href="#manually-editing-of-the-toolbar-layout" id="id202">Manually editing of the toolbar layout</a></li>
-<li><a class="reference internal" href="#available-toolbar-elements" id="id203">Available toolbar elements</a></li>
 </ul>
 </li>
+<li><a class="reference internal" href="#customizing-the-toolbar" id="id202">Customizing the toolbar</a><ul>
+<li><a class="reference internal" href="#manually-editing-of-the-toolbar-layout" id="id203">Manually editing of the toolbar layout</a></li>
+<li><a class="reference internal" href="#available-toolbar-elements" id="id204">Available toolbar elements</a></li>
 </ul>
 </li>
-<li><a class="reference internal" href="#plugin-documentation" id="id204">Plugin documentation</a><ul>
-<li><a class="reference internal" href="#save-actions" id="id205">Save Actions</a><ul>
-<li><a class="reference internal" href="#instant-save" id="id206">Instant Save</a></li>
-<li><a class="reference internal" href="#backup-copy" id="id207">Backup Copy</a></li>
 </ul>
 </li>
+<li><a class="reference internal" href="#plugin-documentation" id="id205">Plugin documentation</a><ul>
+<li><a class="reference internal" href="#save-actions" id="id206">Save Actions</a><ul>
+<li><a class="reference internal" href="#instant-save" id="id207">Instant Save</a></li>
+<li><a class="reference internal" href="#backup-copy" id="id208">Backup Copy</a></li>
 </ul>
 </li>
-<li><a class="reference internal" href="#contributing-to-this-document" id="id208">Contributing to this document</a></li>
-<li><a class="reference internal" href="#scintilla-keyboard-commands" id="id209">Scintilla keyboard commands</a><ul>
-<li><a class="reference internal" href="#keyboard-commands" id="id210">Keyboard commands</a></li>
 </ul>
 </li>
-<li><a class="reference internal" href="#tips-and-tricks" id="id211">Tips and tricks</a><ul>
-<li><a class="reference internal" href="#document-notebook" id="id212">Document notebook</a></li>
-<li><a class="reference internal" href="#editor" id="id213">Editor</a></li>
-<li><a class="reference internal" href="#interface" id="id214">Interface</a></li>
-<li><a class="reference internal" href="#gtk-related" id="id215">GTK-related</a></li>
+<li><a class="reference internal" href="#contributing-to-this-document" id="id209">Contributing to this document</a></li>
+<li><a class="reference internal" href="#scintilla-keyboard-commands" id="id210">Scintilla keyboard commands</a><ul>
+<li><a class="reference internal" href="#keyboard-commands" id="id211">Keyboard commands</a></li>
 </ul>
 </li>
-<li><a class="reference internal" href="#compile-time-options" id="id216">Compile-time options</a><ul>
-<li><a class="reference internal" href="#src-geany-h" id="id217">src/geany.h</a></li>
-<li><a class="reference internal" href="#project-h" id="id218">project.h</a></li>
-<li><a class="reference internal" href="#editor-h" id="id219">editor.h</a></li>
-<li><a class="reference internal" href="#keyfile-c" id="id220">keyfile.c</a></li>
-<li><a class="reference internal" href="#build-h" id="id221">build.h</a></li>
-<li><a class="reference internal" href="#build-c" id="id222">build.c</a></li>
+<li><a class="reference internal" href="#tips-and-tricks" id="id212">Tips and tricks</a><ul>
+<li><a class="reference internal" href="#document-notebook" id="id213">Document notebook</a></li>
+<li><a class="reference internal" href="#editor" id="id214">Editor</a></li>
+<li><a class="reference internal" href="#interface" id="id215">Interface</a></li>
+<li><a class="reference internal" href="#gtk-related" id="id216">GTK-related</a></li>
 </ul>
 </li>
-<li><a class="reference internal" href="#gnu-general-public-license" id="id223">GNU General Public License</a></li>
-<li><a class="reference internal" href="#license-for-scintilla-and-scite" id="id224">License for Scintilla and SciTE</a></li>
+<li><a class="reference internal" href="#compile-time-options" id="id217">Compile-time options</a><ul>
+<li><a class="reference internal" href="#src-geany-h" id="id218">src/geany.h</a></li>
+<li><a class="reference internal" href="#project-h" id="id219">project.h</a></li>
+<li><a class="reference internal" href="#editor-h" id="id220">editor.h</a></li>
+<li><a class="reference internal" href="#keyfile-c" id="id221">keyfile.c</a></li>
+<li><a class="reference internal" href="#build-h" id="id222">build.h</a></li>
+<li><a class="reference internal" href="#build-c" id="id223">build.c</a></li>
 </ul>
+</li>
+<li><a class="reference internal" href="#gnu-general-public-license" id="id224">GNU General Public License</a></li>
+<li><a class="reference internal" href="#license-for-scintilla-and-scite" id="id225">License for Scintilla and SciTE</a></li>
+</ul>
 </div>
 <div class="section" id="introduction">
 <h1><a class="toc-backref" href="#id12">Introduction</a></h1>
@@ -1436,6 +1439,7 @@
 <pre class="literal-block">
 [Default]
 myname=My name is {developer}
+mysystem=My system: {command:uname -a}
 </pre>
 <p>this will replace <tt class="docutils literal">myname</tt> with "My name is " and the value of the template
 preference <tt class="docutils literal">developer</tt>.</p>
@@ -4891,6 +4895,15 @@
 <td>file header, snippets, custom filetype
 templates</td>
 </tr>
+<tr><td>command:path</td>
+<td>Executes the specified command and replace
+the wildcard with the command's standard
+output. See <a class="reference internal" href="#special-command-wilcard">Special {command:} wilcard</a>
+for details.</td>
+<td>filetype templates, file header,
+function description, ChangeLog entry,
+bsd, gpl, snippets</td>
+</tr>
 </tbody>
 </table>
 <table class="docutils footnote" frame="void" id="id10" rules="none">
@@ -4902,17 +4915,39 @@
 For details please see <a class="reference external" href="http://man.cx/strftime">http://man.cx/strftime</a>.</td></tr>
 </tbody>
 </table>
+<div class="section" id="special-command-wilcard">
+<h5><a class="toc-backref" href="#id201">Special {command:} wilcard</a></h5>
+<p>The {command:} wilcard is a special one because it can execute
+a specified command and put the command's output (stdout) into
+the template.</p>
+<p>Example:</p>
+<pre class="literal-block">
+{command:uname -a}
+</pre>
+<p>will result in:</p>
+<pre class="literal-block">
+Linux localhost 2.6.9-023stab046.2-smp #1 SMP Mon Dec 10 15:04:55 MSK 2007 x86_64 GNU/Linux
+</pre>
+<p>Using this wildcard you can insert nearly any arbitrary text into the
+template.</p>
+<div class="note">
+<p class="first admonition-title">Note</p>
+<p class="last">If the specified command could not be found or not executed, the wildcard is substituted
+by an empty string. In such cases, you can find the occurred error message on Geany's
+standard error and in the Help->Debug Messages dialog.</p>
 </div>
 </div>
 </div>
+</div>
+</div>
 <div class="section" id="customizing-the-toolbar">
-<h2><a class="toc-backref" href="#id201">Customizing the toolbar</a></h2>
+<h2><a class="toc-backref" href="#id202">Customizing the toolbar</a></h2>
 <p>You can add, remove and reorder the elements in the toolbar by using the toolbar editor
 by manually editing the file <tt class="docutils literal">ui_toolbar.xml</tt>.</p>
 <p>The toolbar editor can be opened from the preferences editor on the Toolbar tab or
 by right-clicking on the toolbar itself and choosing it from the menu.</p>
 <div class="section" id="manually-editing-of-the-toolbar-layout">
-<h3><a class="toc-backref" href="#id202">Manually editing of the toolbar layout</a></h3>
+<h3><a class="toc-backref" href="#id203">Manually editing of the toolbar layout</a></h3>
 <p>To override the system-wide configuration file, copy it from
 <tt class="docutils literal">$prefix/share/geany</tt> to your configuration directory, usually
 <tt class="docutils literal"><span class="pre">~/.config/geany/</span></tt>. <tt class="docutils literal">$prefix</tt> is the path where Geany is installed
@@ -4936,7 +4971,7 @@
 </div>
 </div>
 <div class="section" id="available-toolbar-elements">
-<h3><a class="toc-backref" href="#id203">Available toolbar elements</a></h3>
+<h3><a class="toc-backref" href="#id204">Available toolbar elements</a></h3>
 <table border="1" class="docutils">
 <colgroup>
 <col width="19%" />
@@ -5050,11 +5085,11 @@
 </div>
 </div>
 <div class="section" id="plugin-documentation">
-<h1><a class="toc-backref" href="#id204">Plugin documentation</a></h1>
+<h1><a class="toc-backref" href="#id205">Plugin documentation</a></h1>
 <div class="section" id="save-actions">
-<h2><a class="toc-backref" href="#id205">Save Actions</a></h2>
+<h2><a class="toc-backref" href="#id206">Save Actions</a></h2>
 <div class="section" id="instant-save">
-<h3><a class="toc-backref" href="#id206">Instant Save</a></h3>
+<h3><a class="toc-backref" href="#id207">Instant Save</a></h3>
 <p>This plugin sets on every new file (File->New or File-> New (with template))
 a randomly chosen filename and set its filetype appropriate to the used template
 or when no template was used, to a configurable default filetype.
@@ -5064,7 +5099,7 @@
 similar.</p>
 </div>
 <div class="section" id="backup-copy">
-<h3><a class="toc-backref" href="#id207">Backup Copy</a></h3>
+<h3><a class="toc-backref" href="#id208">Backup Copy</a></h3>
 <p>This plugin creates a backup copy of the current file in Geany when it is
 saved. You can specify the directory where the backup copy is saved and
 you can configure the automatically added extension in the configure dialog
@@ -5075,7 +5110,7 @@
 </div>
 </div>
 <div class="section" id="contributing-to-this-document">
-<h1><a class="toc-backref" href="#id208">Contributing to this document</a></h1>
+<h1><a class="toc-backref" href="#id209">Contributing to this document</a></h1>
 <p>This document (<tt class="docutils literal">geany.txt</tt>) is written in <a class="reference external" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a>
 (or "reST"). The source file for it is located in Geany's <tt class="docutils literal">doc</tt>
 subdirectory.  If you intend on making changes, you should grab the
@@ -5095,7 +5130,7 @@
 and Fedora systems.</p>
 </div>
 <div class="section" id="scintilla-keyboard-commands">
-<h1><a class="toc-backref" href="#id209">Scintilla keyboard commands</a></h1>
+<h1><a class="toc-backref" href="#id210">Scintilla keyboard commands</a></h1>
 <p>Copyright © 1998, 2006 Neil Hodgson <neilh(at)scintilla(dot)org></p>
 <p>This appendix is distributed under the terms of the License for
 Scintilla and SciTE. A copy of this license can be found in the file
@@ -5104,7 +5139,7 @@
 Scintilla and SciTE</a>.</p>
 <p>20 June 2006</p>
 <div class="section" id="keyboard-commands">
-<h2><a class="toc-backref" href="#id210">Keyboard commands</a></h2>
+<h2><a class="toc-backref" href="#id211">Keyboard commands</a></h2>
 <p>Keyboard commands for Scintilla mostly follow common Windows and GTK+
 conventions. All move keys (arrows, page up/down, home and end)
 allows to extend or reduce the stream selection when holding the
@@ -5186,9 +5221,9 @@
 </div>
 </div>
 <div class="section" id="tips-and-tricks">
-<h1><a class="toc-backref" href="#id211">Tips and tricks</a></h1>
+<h1><a class="toc-backref" href="#id212">Tips and tricks</a></h1>
 <div class="section" id="document-notebook">
-<h2><a class="toc-backref" href="#id212">Document notebook</a></h2>
+<h2><a class="toc-backref" href="#id213">Document notebook</a></h2>
 <ul class="simple">
 <li>Double-click on empty space in the notebook tab bar to open a
 new document.</li>
@@ -5199,7 +5234,7 @@
 </ul>
 </div>
 <div class="section" id="editor">
-<h2><a class="toc-backref" href="#id213">Editor</a></h2>
+<h2><a class="toc-backref" href="#id214">Editor</a></h2>
 <ul class="simple">
 <li>Alt-scroll wheel moves up/down a page.</li>
 <li>Ctrl-scroll wheel zooms in/out.</li>
@@ -5209,13 +5244,13 @@
 </ul>
 </div>
 <div class="section" id="interface">
-<h2><a class="toc-backref" href="#id214">Interface</a></h2>
+<h2><a class="toc-backref" href="#id215">Interface</a></h2>
 <ul class="simple">
 <li>Double-click on a symbol-list group to expand or compact it.</li>
 </ul>
 </div>
 <div class="section" id="gtk-related">
-<h2><a class="toc-backref" href="#id215">GTK-related</a></h2>
+<h2><a class="toc-backref" href="#id216">GTK-related</a></h2>
 <ul class="simple">
 <li>Scrolling the mouse wheel over a notebook tab bar will switch
 notebook pages.</li>
@@ -5230,7 +5265,7 @@
 </div>
 </div>
 <div class="section" id="compile-time-options">
-<h1><a class="toc-backref" href="#id216">Compile-time options</a></h1>
+<h1><a class="toc-backref" href="#id217">Compile-time options</a></h1>
 <p>There are some options which can only be changed at compile time,
 and some options which are used as the default for configurable
 options. To change these options, edit the appropriate source file
@@ -5242,7 +5277,7 @@
 <p class="last">Most users should not need to change these options.</p>
 </div>
 <div class="section" id="src-geany-h">
-<h2><a class="toc-backref" href="#id217">src/geany.h</a></h2>
+<h2><a class="toc-backref" href="#id218">src/geany.h</a></h2>
 <table border="1" class="docutils">
 <colgroup>
 <col width="33%" />
@@ -5299,7 +5334,7 @@
 </table>
 </div>
 <div class="section" id="project-h">
-<h2><a class="toc-backref" href="#id218">project.h</a></h2>
+<h2><a class="toc-backref" href="#id219">project.h</a></h2>
 <table border="1" class="docutils">
 <colgroup>
 <col width="33%" />
@@ -5324,7 +5359,7 @@
 </table>
 </div>
 <div class="section" id="editor-h">
-<h2><a class="toc-backref" href="#id219">editor.h</a></h2>
+<h2><a class="toc-backref" href="#id220">editor.h</a></h2>
 <table border="1" class="docutils">
 <colgroup>
 <col width="33%" />
@@ -5350,7 +5385,7 @@
 </table>
 </div>
 <div class="section" id="keyfile-c">
-<h2><a class="toc-backref" href="#id220">keyfile.c</a></h2>
+<h2><a class="toc-backref" href="#id221">keyfile.c</a></h2>
 <p>These are default settings that can be overridden in the <a class="reference internal" href="#preferences">Preferences</a> dialog.</p>
 <table border="1" class="docutils">
 <colgroup>
@@ -5431,7 +5466,7 @@
 </table>
 </div>
 <div class="section" id="build-h">
-<h2><a class="toc-backref" href="#id221">build.h</a></h2>
+<h2><a class="toc-backref" href="#id222">build.h</a></h2>
 <table border="1" class="docutils">
 <colgroup>
 <col width="33%" />
@@ -5461,7 +5496,7 @@
 </table>
 </div>
 <div class="section" id="build-c">
-<h2><a class="toc-backref" href="#id222">build.c</a></h2>
+<h2><a class="toc-backref" href="#id223">build.c</a></h2>
 <table border="1" class="docutils">
 <colgroup>
 <col width="33%" />
@@ -5492,7 +5527,7 @@
 </div>
 </div>
 <div class="section" id="gnu-general-public-license">
-<h1><a class="toc-backref" href="#id223">GNU General Public License</a></h1>
+<h1><a class="toc-backref" href="#id224">GNU General Public License</a></h1>
 <pre class="literal-block">
             GNU GENERAL PUBLIC LICENSE
                Version 2, June 1991
@@ -5837,7 +5872,7 @@
 </pre>
 </div>
 <div class="section" id="license-for-scintilla-and-scite">
-<h1><a class="toc-backref" href="#id224">License for Scintilla and SciTE</a></h1>
+<h1><a class="toc-backref" href="#id225">License for Scintilla and SciTE</a></h1>
 <p>Copyright 1998-2003 by Neil Hodgson <neilh(at)scintilla(dot)org></p>
 <p>All Rights Reserved</p>
 <p>Permission to use, copy, modify, and distribute this software and
@@ -5857,7 +5892,7 @@
 <div class="footer">
 <hr class="footer" />
 <a class="reference external" href="geany.txt">View document source</a>.
-Generated on: 2010-01-01 23:17 UTC.
+Generated on: 2010-01-24 14:49 UTC.
 Generated by <a class="reference external" href="http://docutils.sourceforge.net/">Docutils</a> from <a class="reference external" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> source.
 
 </div>

Modified: trunk/doc/geany.txt
===================================================================
--- trunk/doc/geany.txt	2010-01-24 14:18:00 UTC (rev 4538)
+++ trunk/doc/geany.txt	2010-01-24 14:52:46 UTC (rev 4539)
@@ -1045,6 +1045,7 @@
 
     [Default]
     myname=My name is {developer}
+    mysystem=My system: {command:uname -a}
 
 this will replace ``myname`` with "My name is " and the value of the template
 preference ``developer``.
@@ -4212,6 +4213,11 @@
 fileheader     The file header template. This wildcard       file header, snippets, custom filetype
                will only be replaced in filetype             templates
                templates.
+
+command:path   Executes the specified command and replace    filetype templates, file header,
+               the wildcard with the command's standard      function description, ChangeLog entry,
+               output. See `Special {command:} wilcard`_     bsd, gpl, snippets
+               for details.
 ============== ============================================= =======================================
 
 
@@ -4221,6 +4227,30 @@
        For details please see http://man.cx/strftime.
 
 
+Special {command:} wilcard
+**************************
+
+The {command:} wilcard is a special one because it can execute
+a specified command and put the command's output (stdout) into
+the template.
+
+Example::
+
+    {command:uname -a}
+
+will result in::
+
+    Linux localhost 2.6.9-023stab046.2-smp #1 SMP Mon Dec 10 15:04:55 MSK 2007 x86_64 GNU/Linux
+
+Using this wildcard you can insert nearly any arbitrary text into the
+template.
+
+.. note::
+    If the specified command could not be found or not executed, the wildcard is substituted
+    by an empty string. In such cases, you can find the occurred error message on Geany's
+    standard error and in the Help->Debug Messages dialog.
+
+
 Customizing the toolbar
 -----------------------
 

Modified: trunk/src/callbacks.c
===================================================================
--- trunk/src/callbacks.c	2010-01-24 14:18:00 UTC (rev 4538)
+++ trunk/src/callbacks.c	2010-01-24 14:52:46 UTC (rev 4539)
@@ -1372,7 +1372,7 @@
 	line = symbols_get_current_function(doc, &cur_tag);
 	pos = sci_get_position_from_line(doc->editor->sci, line - 1);
 
-	text = templates_get_template_function(doc->file_type->id, cur_tag);
+	text = templates_get_template_function(doc, cur_tag);
 
 	sci_insert_text(doc->editor->sci, pos, text);
 	g_free(text);
@@ -1410,7 +1410,7 @@
 
 	g_return_if_fail(doc != NULL);
 
-	text = templates_get_template_licence(FILETYPE_ID(doc->file_type), GEANY_TEMPLATE_GPL);
+	text = templates_get_template_licence(doc, GEANY_TEMPLATE_GPL);
 
 	verify_click_pos(doc); /* make sure that the click_pos is valid */
 
@@ -1429,7 +1429,7 @@
 
 	g_return_if_fail(doc != NULL);
 
-	text = templates_get_template_licence(FILETYPE_ID(doc->file_type), GEANY_TEMPLATE_BSD);
+	text = templates_get_template_licence(doc, GEANY_TEMPLATE_BSD);
 
 	verify_click_pos(doc); /* make sure that the click_pos is valid */
 
@@ -1448,7 +1448,7 @@
 
 	g_return_if_fail(doc != NULL);
 
-	text = templates_get_template_changelog();
+	text = templates_get_template_changelog(doc);
 	sci_insert_text(doc->editor->sci, 0, text);
 	/* sets the cursor to the right position to type the changelog text,
 	 * the template has 21 chars + length of name and email */

Modified: trunk/src/editor.c
===================================================================
--- trunk/src/editor.c	2010-01-24 14:18:00 UTC (rev 4538)
+++ trunk/src/editor.c	2010-01-24 14:52:46 UTC (rev 4539)
@@ -2024,10 +2024,12 @@
 
 static void snippets_replace_wildcards(GeanyEditor *editor, GString *text)
 {
-	gchar *basename = g_path_get_basename(DOC_FILENAME(editor->document));
+	const gchar *file_name = DOC_FILENAME(editor->document);
+	gchar *basename = g_path_get_basename(file_name);
 
 	templates_replace_default_dates(text);
 	templates_replace_valist(text, "{filename}", basename, NULL);
+	templates_replace_command(text, file_name, editor->document->file_type->name, NULL);
 
 	g_free(basename);
 }

Modified: trunk/src/templates.c
===================================================================
--- trunk/src/templates.c	2010-01-24 14:18:00 UTC (rev 4538)
+++ trunk/src/templates.c	2010-01-24 14:52:46 UTC (rev 4539)
@@ -126,6 +126,9 @@
 static gchar *ft_templates[GEANY_MAX_BUILT_IN_FILETYPES] = {NULL};
 
 
+static void replace_static_values(GString *text);
+
+
 /* some simple macros to reduce code size and make the code readable */
 #define TEMPLATES_GET_FILENAME(shortname) \
 	g_strconcat(app->configdir, \
@@ -301,6 +304,7 @@
 			"{fileheader}", file_header,
 			NULL);
 		templates_replace_default_dates(template);
+		templates_replace_command(template, doc_filename, ft->name, NULL);
 
 		utils_free_pointers(2, file_header, content, NULL);
 		return g_string_free(template, FALSE);
@@ -453,6 +457,7 @@
  * e.g. indent = 8 prints " *     here comes the text of the line"
  * indent is meant to be the whole amount of characters before the real line content follows, i.e.
  * 6 characters are filled with whitespace when the comment characters include " *" */
+/* TODO make this function operating on a GString */
 static gchar *make_comment_block(const gchar *comment_text, gint filetype_idx, guint indent)
 {
 	gchar *frame_start;		/* to add before comment_text */
@@ -526,21 +531,33 @@
 }
 
 
-gchar *templates_get_template_licence(gint filetype_idx, gint licence_type)
+gchar *templates_get_template_licence(GeanyDocument *doc, gint licence_type)
 {
-	if (licence_type != GEANY_TEMPLATE_GPL && licence_type != GEANY_TEMPLATE_BSD)
-		return NULL;
+	GString *template;
+	gchar *result = NULL;
 
-	return make_comment_block(templates[licence_type], filetype_idx, 8);
+	g_return_val_if_fail(doc != NULL, NULL);
+	g_return_val_if_fail(licence_type == GEANY_TEMPLATE_GPL || licence_type == GEANY_TEMPLATE_BSD, NULL);
+
+	template = g_string_new(templates[licence_type]);
+	replace_static_values(template);
+	templates_replace_default_dates(template);
+	templates_replace_command(template, DOC_FILENAME(doc), doc->file_type->name, NULL);
+
+	result = make_comment_block(template->str, FILETYPE_ID(doc->file_type), 8);
+
+	g_string_free(template, TRUE);
+
+	return result;
 }
 
 
+/* TODO change the signature to take a GeanyDocument although this would break plugin API/ABI */
 gchar *templates_get_template_fileheader(gint filetype_idx, const gchar *fname)
 {
-	gchar *template = g_strdup(templates[GEANY_TEMPLATE_FILEHEADER]);
+	GString *template = g_string_new(templates[GEANY_TEMPLATE_FILEHEADER]);
 	gchar *shortname;
 	gchar *result;
-	gchar *date = utils_get_date_time(template_prefs.datetime_format, NULL);
 	filetype_id ft_id = filetype_idx;
 	GeanyFiletype *ft = filetypes[ft_id];
 
@@ -556,83 +573,77 @@
 	else
 		shortname = g_path_get_basename(fname);
 
-	utils_str_replace_all(&template, "{filename}", shortname);
-	utils_str_replace_all(&template, "{gpl}", templates[GEANY_TEMPLATE_GPL]);
-	utils_str_replace_all(&template, "{bsd}", templates[GEANY_TEMPLATE_BSD]);
-	utils_str_replace_all(&template, "{datetime}", date);
+	templates_replace_valist(template,
+		"{filename}", shortname,
+		"{gpl}", templates[GEANY_TEMPLATE_GPL],
+		"{bsd}", templates[GEANY_TEMPLATE_BSD],
+		NULL);
+	templates_replace_default_dates(template);
+	templates_replace_command(template, fname, ft->name, NULL);
 
-	result = make_comment_block(template, ft_id, 8);
+	result = make_comment_block(template->str, ft_id, 8);
 
-	g_free(template);
+	g_string_free(template, TRUE);
 	g_free(shortname);
-	g_free(date);
 	return result;
 }
 
 
-static gchar *get_file_template(GeanyFiletype *ft)
-{
-	filetype_id ft_id = FILETYPE_ID(ft);
-
-	g_return_val_if_fail(ft_id < GEANY_MAX_BUILT_IN_FILETYPES, NULL);
-
-	return g_strdup(ft_templates[ft_id]);
-}
-
-
 gchar *templates_get_template_new_file(GeanyFiletype *ft)
 {
-	gchar *ft_template = NULL;
+	GString *ft_template;
 	gchar *file_header = NULL;
 
+	g_return_val_if_fail(ft != NULL, NULL);
 	g_return_val_if_fail(ft->id < GEANY_MAX_BUILT_IN_FILETYPES, NULL);
 
+	ft_template = g_string_new(ft_templates[ft->id]);
 	if (FILETYPE_ID(ft) == GEANY_FILETYPES_NONE)
-		return get_file_template(ft);
+	{
+		replace_static_values(ft_template);
+	}
+	else
+	{	/* file template only used for new files */
+		file_header = templates_get_template_fileheader(ft->id, NULL);
+		templates_replace_valist(ft_template, "{fileheader}", file_header, NULL);
+	}
+	templates_replace_default_dates(ft_template);
+	templates_replace_command(ft_template, NULL, ft->name, NULL);
 
-	file_header = templates_get_template_fileheader(ft->id, NULL);	/* file template only used for new files */
-	ft_template = get_file_template(ft);
-	utils_str_replace_all(&ft_template, "{fileheader}", file_header);
 	g_free(file_header);
-	return ft_template;
+	return g_string_free(ft_template, FALSE);
 }
 
 
-gchar *templates_get_template_generic(gint template)
+gchar *templates_get_template_function(GeanyDocument *doc, const gchar *func_name)
 {
-	return g_strdup(templates[template]);
-}
+	gchar *result;
+	GString *text;
 
+	func_name = (func_name != NULL) ? func_name : "";
+	text = g_string_new(templates[GEANY_TEMPLATE_FUNCTION]);
 
-gchar *templates_get_template_function(gint filetype_idx, const gchar *func_name)
-{
-	gchar *template = g_strdup(templates[GEANY_TEMPLATE_FUNCTION]);
-	gchar *date = utils_get_date_time(template_prefs.date_format, NULL);
-	gchar *datetime = utils_get_date_time(template_prefs.datetime_format, NULL);
-	gchar *result;
+	templates_replace_valist(text, "{functionname}", func_name, NULL);
+	templates_replace_default_dates(text);
+	templates_replace_command(text, DOC_FILENAME(doc), doc->file_type->name, func_name);
 
-	utils_str_replace_all(&template, "{date}", date);
-	utils_str_replace_all(&template, "{datetime}", datetime);
-	utils_str_replace_all(&template, "{functionname}", (func_name) ? func_name : "");
+	result = make_comment_block(text->str, doc->file_type->id, 3);
 
-	result = make_comment_block(template, filetype_idx, 3);
-
-	g_free(template);
-	g_free(date);
-	g_free(datetime);
+	g_string_free(text, TRUE);
 	return result;
 }
 
 
-gchar *templates_get_template_changelog(void)
+gchar *templates_get_template_changelog(GeanyDocument *doc)
 {
-	gchar *date = utils_get_date_time(template_prefs.datetime_format, NULL);
-	gchar *result = g_strdup(templates[GEANY_TEMPLATE_CHANGELOG]);
+	GString *result = g_string_new(templates[GEANY_TEMPLATE_CHANGELOG]);
+	gchar *file_type_name = (doc != NULL) ? doc->file_type->name : "";
 
-	utils_str_replace_all(&result, "{date}", date);
+	replace_static_values(result);
+	templates_replace_default_dates(result);
+	templates_replace_command(result, DOC_FILENAME(doc), file_type_name, NULL);
 
-	g_free(date);
-	return result;
+	return g_string_free(result, FALSE);
 }
 
 
@@ -699,7 +710,7 @@
 		utils_string_replace_all(text, key, value);
 
 		key = va_arg(args, gchar*);
-		if (text == NULL)
+		if (key == NULL || text == NULL)
 			break;
 		value = va_arg(args, gchar*);
 	}
@@ -715,6 +726,8 @@
 	gchar *date = utils_get_date_time(template_prefs.date_format, NULL);
 	gchar *datetime = utils_get_date_time(template_prefs.datetime_format, NULL);
 
+	g_return_if_fail(text != NULL);
+
 	templates_replace_valist(text,
 		"{year}", year,
 		"{date}", date,
@@ -723,3 +736,71 @@
 
 	utils_free_pointers(3, year, date, datetime, NULL);
 }
+
+
+static gchar *run_command(const gchar *command, const gchar *file_name,
+						  const gchar *file_type, const gchar *func_name)
+{
+	gchar *result = NULL;
+	gchar **argv;
+
+	if (g_shell_parse_argv(command, NULL, &argv, NULL))
+	{
+		GError *error = NULL;
+		gchar **env;
+
+		file_name = (file_name != NULL) ? file_name : "";
+		file_type = (file_type != NULL) ? file_type : "";
+		func_name = (func_name != NULL) ? func_name : "";
+
+		env = utils_copy_environment(NULL,
+			"GEANY_FILENAME", file_name,
+			"GEANY_FILETYPE", file_type,
+			"GEANY_FUNCNAME", func_name,
+			NULL);
+		if (! g_spawn_sync(NULL, argv, env, G_SPAWN_SEARCH_PATH,
+				NULL, NULL, &result, NULL, NULL, &error))
+		{
+			g_warning("templates_replace_command: %s", error->message);
+			g_error_free(error);
+			return NULL;
+		}
+		g_strfreev(argv);
+		g_strfreev(env);
+	}
+	return result;
+}
+
+
+void templates_replace_command(GString *text, const gchar *file_name,
+							   const gchar *file_type, const gchar *func_name)
+{
+	gchar *match = NULL;
+	gchar *wildcard = NULL;
+	gchar *cmd;
+	gchar *result;
+
+	g_return_if_fail(text != NULL);
+
+	while ((match = strstr(text->str, "{command:")) != NULL)
+	{
+		cmd = match;
+		while (*match != '}' && *match != '\0')
+			match++;
+
+		wildcard = g_strndup(cmd, match - cmd + 1);
+		cmd = g_strndup(wildcard + 9, strlen(wildcard) - 10);
+
+		result = run_command(cmd, file_name, file_type, func_name);
+		if (result != NULL)
+		{
+			utils_string_replace_first(text, wildcard, result);
+			g_free(result);
+		}
+		else
+			utils_string_replace_first(text, wildcard, "");
+
+		g_free(wildcard);
+		g_free(cmd);
+	}
+}

Modified: trunk/src/templates.h
===================================================================
--- trunk/src/templates.h	2010-01-24 14:18:00 UTC (rev 4538)
+++ trunk/src/templates.h	2010-01-24 14:52:46 UTC (rev 4539)
@@ -66,18 +66,19 @@
 
 gchar *templates_get_template_new_file(GeanyFiletype *ft);
 
-gchar *templates_get_template_changelog(void);
+gchar *templates_get_template_changelog(GeanyDocument *doc);
 
-gchar *templates_get_template_generic(gint template);
+gchar *templates_get_template_function(GeanyDocument *doc, const gchar *func_name);
 
-gchar *templates_get_template_function(gint filetype_idx, const gchar *func_name);
+gchar *templates_get_template_licence(GeanyDocument *doc, gint licence_type);
 
-gchar *templates_get_template_licence(gint filetype_idx, gint licence_type);
-
 void templates_replace_default_dates(GString *text);
 
 void templates_replace_valist(GString *text, const gchar *first_wildcard, ...) G_GNUC_NULL_TERMINATED;
 
+void templates_replace_command(GString *text, const gchar *file_name,
+							   const gchar *file_type, const gchar *func_name);
+
 void templates_free_templates(void);
 
 #endif


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list