Kaydet (Commit) 5dbd0670 authored tarafından Enrico Tröger's avatar Enrico Tröger

Improve inserting of comment templates like File header or licence notices. The…

Improve inserting of comment templates like File header or licence notices. The comment information are now read from the filetype configuration files.

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@3991 ea778897-0a13-0410-b9d1-a72fbfd435f5
üst eaa0592b
......@@ -5,6 +5,10 @@
Apply changes in the toolbar editor instantly.
Show icons in the toolbar editor.
Speed up toolbar editor dialog creation.
* src/templates.c:
Improve inserting of comment templates like File header or licence
notices. The comment information are now read from the filetype
configuration files.
2009-07-16 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
......
......@@ -591,122 +591,46 @@ void templates_init(void)
* 6 characters are filled with whitespace when the comment characters include " *" */
static gchar *make_comment_block(const gchar *comment_text, gint filetype_idx, guint indent)
{
gchar *frame_start = ""; /* to add before comment_text */
gchar *frame_end = ""; /* to add after comment_text */
gchar *line_prefix; /* to add before every line in comment_text */
gchar *frame_start; /* to add before comment_text */
gchar *frame_end; /* to add after comment_text */
gchar *line_prefix; /* to add before every line in comment_text */
gchar *result;
gchar *tmp;
gchar *prefix;
gchar **lines;
guint i, len;
GeanyFiletype *ft = filetypes_index(filetype_idx);
/* TODO the following switch could be replaced by some intelligent code which reads
* frame_start, frame_end and line_prefix from the filetype definition files */
switch (filetype_idx)
{
case GEANY_FILETYPES_HTML:
case GEANY_FILETYPES_XML:
case GEANY_FILETYPES_DOCBOOK:
{
frame_start = "<!--\n";
frame_end = "-->\n";
line_prefix = "";
break;
}
case GEANY_FILETYPES_PYTHON:
case GEANY_FILETYPES_R:
case GEANY_FILETYPES_RUBY:
case GEANY_FILETYPES_SH:
case GEANY_FILETYPES_MAKE:
case GEANY_FILETYPES_PERL:
case GEANY_FILETYPES_DIFF:
case GEANY_FILETYPES_TCL:
case GEANY_FILETYPES_CONF:
case GEANY_FILETYPES_PO:
case GEANY_FILETYPES_YAML:
case GEANY_FILETYPES_CMAKE:
{
line_prefix = "#";
break;
}
case GEANY_FILETYPES_JS:
case GEANY_FILETYPES_HAXE:
{
line_prefix = "//";
break;
}
case GEANY_FILETYPES_LATEX:
case GEANY_FILETYPES_MATLAB:
{
line_prefix = "%";
break;
}
case GEANY_FILETYPES_ADA:
case GEANY_FILETYPES_HASKELL:
case GEANY_FILETYPES_VHDL:
case GEANY_FILETYPES_LUA:
{
line_prefix = "--";
break;
}
case GEANY_FILETYPES_FORTRAN:
{
line_prefix = "!";
break;
}
case GEANY_FILETYPES_F77:
{
line_prefix = "c";
break;
}
g_return_val_if_fail(ft != NULL, NULL);
case GEANY_FILETYPES_ASM:
case GEANY_FILETYPES_NSIS:
{
line_prefix = ";";
break;
}
case GEANY_FILETYPES_BASIC:
{
line_prefix = "'";
break;
}
case GEANY_FILETYPES_PASCAL:
if (NZV(ft->comment_open))
{
if (NZV(ft->comment_close))
{
frame_start = "{\n";
frame_end = "}\n";
frame_start = g_strconcat(ft->comment_open, "\n", NULL);
frame_end = g_strconcat(ft->comment_close, "\n", NULL);
line_prefix = "";
break;
}
case GEANY_FILETYPES_CAML:
{
frame_start = "(*\n";
frame_end = " *)\n";
line_prefix = " *";
break;
}
case GEANY_FILETYPES_NONE:
else
{
line_prefix = "";
break;
frame_start = NULL;
frame_end = NULL;
line_prefix = ft->comment_open;
}
}
else
{ /* use C-like multi-line comments as fallback */
frame_start = g_strdup("/*\n");
frame_end = g_strdup("*/\n");
line_prefix = "";
}
default: /* assume C-like multi-line comment is appropriate */
{
frame_start = "/*\n";
frame_end = " */\n";
line_prefix = " *";
}
/* do some magic to nicely format C-like multi-line comments */
if (NZV(frame_start) && frame_start[1] == '*')
{
/* prefix the string with a space */
setptr(frame_end, g_strconcat(" ", frame_end, NULL));
line_prefix = " *";
}
/* construct the real prefix with given amount of whitespace */
......@@ -715,7 +639,6 @@ static gchar *make_comment_block(const gchar *comment_text, gint filetype_idx, g
prefix = g_strconcat(line_prefix, tmp, NULL);
g_free(tmp);
/* add line_prefix to every line of comment_text */
lines = g_strsplit(comment_text, "\n", -1);
len = g_strv_length(lines) - 1;
......@@ -728,10 +651,12 @@ static gchar *make_comment_block(const gchar *comment_text, gint filetype_idx, g
tmp = g_strjoinv("\n", lines);
/* add frame_start and frame_end */
result = g_strconcat(frame_start, tmp, frame_end, NULL);
if (frame_start != NULL)
result = g_strconcat(frame_start, tmp, frame_end, NULL);
else
result = g_strconcat(tmp, frame_end, NULL);
g_free(prefix);
g_free(tmp);
utils_free_pointers(4, prefix, tmp, frame_start, frame_end, NULL);
g_strfreev(lines);
return result;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment