Revision: 1433
http://svn.sourceforge.net/geany/?rev=1433&view=rev
Author: ntrel
Date: 2007-03-31 04:39:56 -0700 (Sat, 31 Mar 2007)
Log Message:
-----------
Make file header optional for filetype templates - use the string
'{fileheader}' to mark where the file header should be placed, which
can be anywhere in the filetype template.
Modified Paths:
--------------
trunk/ChangeLog
trunk/doc/geany.docbook
trunk/src/templates.c
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2007-03-30 16:34:51 UTC (rev 1432)
+++ trunk/ChangeLog 2007-03-31 11:39:56 UTC (rev 1433)
@@ -1,3 +1,11 @@
+2007-03-31 Nick Treleaven <nick.treleaven(a)btinternet.com>
+
+ * src/templates.c, doc/geany.docbook:
+ Make file header optional for filetype templates - use the string
+ '{fileheader}' to mark where the file header should be placed, which
+ can be anywhere in the filetype template.
+
+
2007-03-30 Nick Treleaven <nick.treleaven(a)btinternet.com>
* geany.desktop.in:
Modified: trunk/doc/geany.docbook
===================================================================
--- trunk/doc/geany.docbook 2007-03-30 16:34:51 UTC (rev 1432)
+++ trunk/doc/geany.docbook 2007-03-31 11:39:56 UTC (rev 1433)
@@ -2005,17 +2005,29 @@
description.
</para>
<section>
+ <title>Template metadata</title>
+ <para>
+ Metadata can be used with all templates, but by default user set metadata is only
+ used for the ChangeLog and File header templates.
+ </para>
+ <para>
+ In the configuration dialog you can find a tab "Templates"
+ (see <xref linkend="confdialog_templ"/>). You can define the default values which
+ will be inserted in the templates. You should restart <application>Geany</application>
+ after making changes, because they are only read at startup.
+ </para>
+ </section>
+ <section>
<title>Filetype templates</title>
<para>
Filetype templates are templates used as the basis of a new file. To use them, choose
the <literal>New (with Template)</literal> menu item from the
- <literal>File</literal> menu. At creation of a new file with a filetype template, the
- fileheader template is automatically prepended.
+ <literal>File</literal> menu.
</para>
<para>
- By default, templates are created for certain filetypes. Other filetype templates can be
+ By default, templates are created for some filetypes. Other filetype templates can be
added by creating the appropriate template file and restarting
- <application>Geany</application>.
+ <application>Geany</application>. You can also edit the default filetype templates.
</para>
<para>
Filetype template files are read from the <filename>~/.geany/templates</filename>
@@ -2027,25 +2039,17 @@
'<filename>filetypes.</filename>'.
</para>
<para>
+ The file's contents are just the text to place in the document, except for the
+ optional <literal>{fileheader}</literal> template wildcard. This can be placed anywhere,
+ but is usually on the first line of the file, followed by a blank line.
+ </para>
+ <para>
There is also a template file <filename>template.none</filename> which is used when
the <literal>New</literal> command is used without a filetype. This is empty by
default.
</para>
</section>
<section>
- <title>Template metadata</title>
- <para>
- Metadata can be used with all templates, but by default user set metadata is only
- used for the ChangeLog and File header templates.
- </para>
- <para>
- In the configuration dialog you can find a tab "Templates"
- (see <xref linkend="confdialog_templ"/>). You can define the default values which
- will be inserted in the templates. You should restart <application>Geany</application>
- after making changes, because they are only read at startup.
- </para>
- </section>
- <section>
<title>Customizing templates</title>
<para>
Each template can be customized to your needs. The templates are stored in the
@@ -2162,6 +2166,13 @@
description template.</entry>
<entry>function description</entry>
</row>
+ <row>
+ <entry>fileheader</entry>
+ <entry>The file header template.
+ This wildcard will only be replaced in filetype
+ templates.</entry>
+ <entry>filetypes</entry>
+ </row>
</tbody>
</tgroup>
</table>
Modified: trunk/src/templates.c
===================================================================
--- trunk/src/templates.c 2007-03-30 16:34:51 UTC (rev 1432)
+++ trunk/src/templates.c 2007-03-31 11:39:56 UTC (rev 1433)
@@ -51,7 +51,8 @@
\n\
You should have received a copy of the GNU General Public License\n\
along with this program; if not, write to the Free Software\n\
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n\
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,\n\
+MA 02110-1301, USA.\n\
";
static const gchar templates_bsd_notice[] = "\
@@ -109,7 +110,7 @@
static const gchar templates_filetype_none[] = "";
-static const gchar templates_filetype_c[] = "\n\
+static const gchar templates_filetype_c[] = "{fileheader}\n\n\
#include <stdio.h>\n\
\n\
int main(int argc, char** argv)\n\
@@ -119,7 +120,7 @@
}\n\
";
-static const gchar templates_filetype_cpp[] = "\n\
+static const gchar templates_filetype_cpp[] = "{fileheader}\n\n\
#include <iostream>\n\
\n\
int main(int argc, char** argv)\n\
@@ -129,7 +130,7 @@
}\n\
";
-static const gchar templates_filetype_d[] = "\n\
+static const gchar templates_filetype_d[] = "{fileheader}\n\n\
import std.stdio;\n\
\n\
int main(char[][] args)\n\
@@ -139,7 +140,8 @@
}\n\
";
-static const gchar templates_filetype_php[] = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n\
+static const gchar templates_filetype_php[] = "{fileheader}\n\
+<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n\
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n\
<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n\
\n\
@@ -155,7 +157,8 @@
</html>\n\
";
-static const gchar templates_filetype_html[] = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n\
+static const gchar templates_filetype_html[] = "{fileheader}\n\
+<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n\
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n\
<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n\
\n\
@@ -171,7 +174,7 @@
</html>\n\
";
-static const gchar templates_filetype_pascal[] = "\n\
+static const gchar templates_filetype_pascal[] = "{fileheader}\n\n\
program {untitled};\n\
\n\
uses crt;\n\
@@ -183,7 +186,7 @@
END.\n\
";
-static const gchar templates_filetype_java[] = "\n\
+static const gchar templates_filetype_java[] = "{fileheader}\n\n\
public class {untitled} {\n\
\n\
public static void main (String args[]) {\
@@ -193,8 +196,7 @@
}\n\
";
-static const gchar templates_filetype_ruby[] = "\n\
-\n\
+static const gchar templates_filetype_ruby[] = "{fileheader}\n\n\
class StdClass\n\
def initialize\n\
\n\
@@ -560,7 +562,6 @@
gchar *templates_get_template_new_file(filetype *ft)
{
- gchar *template = NULL;
gchar *ft_template = NULL;
gchar *file_header = NULL;
@@ -569,10 +570,9 @@
file_header = get_file_header(ft, NULL); // file template only used for new files
ft_template = get_file_template(ft);
- template = g_strconcat(file_header, "\n", ft_template, NULL);
- g_free(ft_template);
+ ft_template = utils_str_replace(ft_template, "{fileheader}", file_header);
g_free(file_header);
- return template;
+ return ft_template;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
Revision: 1427
http://svn.sourceforge.net/geany/?rev=1427&view=rev
Author: ntrel
Date: 2007-03-28 05:11:37 -0700 (Wed, 28 Mar 2007)
Log Message:
-----------
Don't auto-indent {} braces for filetypes that don't use them.
Add lexer_has_braces(), do_indent() for in place buffer indentation.
Rewrite some of get_indent().
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/sci_cb.c
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2007-03-27 15:48:16 UTC (rev 1426)
+++ trunk/ChangeLog 2007-03-28 12:11:37 UTC (rev 1427)
@@ -1,3 +1,11 @@
+2007-03-28 Nick Treleaven <nick.treleaven(a)btinternet.com>
+
+ * src/sci_cb.c:
+ Don't auto-indent {} braces for filetypes that don't use them.
+ Add lexer_has_braces(), do_indent() for in place buffer indentation.
+ Rewrite some of get_indent().
+
+
2007-03-27 Nick Treleaven <nick.treleaven(a)btinternet.com>
* src/keybindings.c, src/keybindings.h, src/sci_cb.c, src/sci_cb.h,
Modified: trunk/src/sci_cb.c
===================================================================
--- trunk/src/sci_cb.c 2007-03-27 15:48:16 UTC (rev 1426)
+++ trunk/src/sci_cb.c 2007-03-28 12:11:37 UTC (rev 1427)
@@ -377,9 +377,48 @@
}
+static gboolean lexer_has_braces(ScintillaObject *sci)
+{
+ gint lexer = SSM(sci, SCI_GETLEXER, 0, 0);
+
+ switch (lexer)
+ {
+ case SCLEX_CPP:
+ case SCLEX_D:
+ case SCLEX_HTML: // for PHP & JS
+ case SCLEX_PASCAL: // for multiline comments?
+ case SCLEX_BASH:
+ return TRUE;
+ default:
+ return FALSE;
+ }
+}
+
+
+// in place indentation of one tab or equivalent spaces
+static void do_indent(gchar *buf, gsize len, guint *index)
+{
+ guint j = *index;
+
+ if (app->pref_editor_use_tabs)
+ {
+ if (j < len - 1) // leave room for a \0 terminator.
+ buf[j++] = '\t';
+ }
+ else
+ { // insert as many spaces as a tab would take
+ guint k;
+ for (k = 0; k < (guint) app->pref_editor_tab_width && k < len - 1; k++)
+ buf[j++] = ' ';
+ }
+ *index = j;
+}
+
+
+/* "use_this_line" to auto-indent only if it is a real new line
+ * and ignore the case of sci_cb_close_block */
static void get_indent(ScintillaObject *sci, gint pos, gboolean use_this_line)
{
- // very simple indentation algorithm
guint i, len, j = 0;
gint prev_line;
gchar *linebuf;
@@ -392,51 +431,36 @@
for (i = 0; i < len && j <= (sizeof(indent) - 1); i++)
{
- if (linebuf[i] == ' ' || linebuf[i] == '\t')
+ if (linebuf[i] == ' ' || linebuf[i] == '\t') // simple indentation
indent[j++] = linebuf[i];
- // "&& ! use_this_line" to auto-indent only if it is a real new line
- // and ignore the case of sci_cb_close_block
- else if (linebuf[i] == '{' && ! use_this_line &&
- app->pref_editor_indention_mode == INDENT_ADVANCED)
+ else if (app->pref_editor_indention_mode != INDENT_ADVANCED)
+ break;
+ else if (use_this_line)
+ break;
+ else // sci_cb_close_block
{
- if (app->pref_editor_use_tabs)
+ if (! lexer_has_braces(sci))
+ break;
+
+ if (linebuf[i] == '{')
{
- indent[j++] = '\t';
+ do_indent(indent, sizeof(indent), &j);
+ break;
}
else
- { // insert as many spaces as a tabulator would take
- gint k;
- for (k = 0; k < app->pref_editor_tab_width; k++)
- indent[j++] = ' ';
- }
+ {
+ gint k = len - 1;
- break;
- }
- else
- {
- gint k = len - 1;
+ while (k > 0 && isspace(linebuf[k])) k--;
- if (use_this_line)
- break; // break immediately in the case of sci_cb_close_block
-
- while (k > 0 && isspace(linebuf[k])) k--;
-
- // if last non-whitespace character is a { increase indention by a tab
- // e.g. for (...) {
- if (app->pref_editor_indention_mode == INDENT_ADVANCED && linebuf[k] == '{')
- {
- if (app->pref_editor_use_tabs)
+ // if last non-whitespace character is a { increase indentation by a tab
+ // e.g. for (...) {
+ if (linebuf[k] == '{')
{
- indent[j++] = '\t';
+ do_indent(indent, sizeof(indent), &j);
}
- else
- { // insert as many spaces as a tabulator would take
- gint n;
- for (n = 0; n < app->pref_editor_tab_width; n++)
- indent[j++] = ' ';
- }
+ break;
}
- break;
}
}
indent[j] = '\0';
@@ -503,7 +527,7 @@
void sci_cb_close_block(gint idx, gint pos)
{
gint x = 0, cnt = 0;
- gint start_brace, line, line_start, line_len, eol_char_len, lexer;
+ gint start_brace, line, line_start, line_len, eol_char_len;
gchar *text, *line_buf;
ScintillaObject *sci;
@@ -511,9 +535,7 @@
sci = doc_list[idx].sci;
- lexer = SSM(sci, SCI_GETLEXER, 0, 0);
- if (lexer != SCLEX_CPP && lexer != SCLEX_HTML && lexer != SCLEX_PASCAL &&
- lexer != SCLEX_D && lexer != SCLEX_BASH)
+ if (! lexer_has_braces(sci))
return;
start_brace = brace_match(sci, pos);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.