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
This commit is contained in:
parent
eaa0592bb3
commit
5dbd06700d
@ -5,6 +5,10 @@
|
|||||||
Apply changes in the toolbar editor instantly.
|
Apply changes in the toolbar editor instantly.
|
||||||
Show icons in the toolbar editor.
|
Show icons in the toolbar editor.
|
||||||
Speed up toolbar editor dialog creation.
|
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>
|
2009-07-16 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
|
||||||
|
139
src/templates.c
139
src/templates.c
@ -591,122 +591,46 @@ void templates_init(void)
|
|||||||
* 6 characters are filled with whitespace when the comment characters include " *" */
|
* 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)
|
static gchar *make_comment_block(const gchar *comment_text, gint filetype_idx, guint indent)
|
||||||
{
|
{
|
||||||
gchar *frame_start = ""; /* to add before comment_text */
|
gchar *frame_start; /* to add before comment_text */
|
||||||
gchar *frame_end = ""; /* to add after comment_text */
|
gchar *frame_end; /* to add after comment_text */
|
||||||
gchar *line_prefix; /* to add before every line in comment_text */
|
gchar *line_prefix; /* to add before every line in comment_text */
|
||||||
gchar *result;
|
gchar *result;
|
||||||
gchar *tmp;
|
gchar *tmp;
|
||||||
gchar *prefix;
|
gchar *prefix;
|
||||||
gchar **lines;
|
gchar **lines;
|
||||||
guint i, len;
|
guint i, len;
|
||||||
|
GeanyFiletype *ft = filetypes_index(filetype_idx);
|
||||||
|
|
||||||
/* TODO the following switch could be replaced by some intelligent code which reads
|
g_return_val_if_fail(ft != NULL, NULL);
|
||||||
* frame_start, frame_end and line_prefix from the filetype definition files */
|
|
||||||
switch (filetype_idx)
|
if (NZV(ft->comment_open))
|
||||||
{
|
{
|
||||||
case GEANY_FILETYPES_HTML:
|
if (NZV(ft->comment_close))
|
||||||
case GEANY_FILETYPES_XML:
|
|
||||||
case GEANY_FILETYPES_DOCBOOK:
|
|
||||||
{
|
{
|
||||||
frame_start = "<!--\n";
|
frame_start = g_strconcat(ft->comment_open, "\n", NULL);
|
||||||
frame_end = "-->\n";
|
frame_end = g_strconcat(ft->comment_close, "\n", NULL);
|
||||||
line_prefix = "";
|
line_prefix = "";
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
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 = "#";
|
frame_start = NULL;
|
||||||
break;
|
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 = "";
|
||||||
|
}
|
||||||
|
|
||||||
case GEANY_FILETYPES_JS:
|
/* do some magic to nicely format C-like multi-line comments */
|
||||||
case GEANY_FILETYPES_HAXE:
|
if (NZV(frame_start) && frame_start[1] == '*')
|
||||||
{
|
{
|
||||||
line_prefix = "//";
|
/* prefix the string with a space */
|
||||||
break;
|
setptr(frame_end, g_strconcat(" ", frame_end, NULL));
|
||||||
}
|
line_prefix = " *";
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
case GEANY_FILETYPES_ASM:
|
|
||||||
case GEANY_FILETYPES_NSIS:
|
|
||||||
{
|
|
||||||
line_prefix = ";";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case GEANY_FILETYPES_BASIC:
|
|
||||||
{
|
|
||||||
line_prefix = "'";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case GEANY_FILETYPES_PASCAL:
|
|
||||||
{
|
|
||||||
frame_start = "{\n";
|
|
||||||
frame_end = "}\n";
|
|
||||||
line_prefix = "";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case GEANY_FILETYPES_CAML:
|
|
||||||
{
|
|
||||||
frame_start = "(*\n";
|
|
||||||
frame_end = " *)\n";
|
|
||||||
line_prefix = " *";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case GEANY_FILETYPES_NONE:
|
|
||||||
{
|
|
||||||
line_prefix = "";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default: /* assume C-like multi-line comment is appropriate */
|
|
||||||
{
|
|
||||||
frame_start = "/*\n";
|
|
||||||
frame_end = " */\n";
|
|
||||||
line_prefix = " *";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* construct the real prefix with given amount of whitespace */
|
/* 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);
|
prefix = g_strconcat(line_prefix, tmp, NULL);
|
||||||
g_free(tmp);
|
g_free(tmp);
|
||||||
|
|
||||||
|
|
||||||
/* add line_prefix to every line of comment_text */
|
/* add line_prefix to every line of comment_text */
|
||||||
lines = g_strsplit(comment_text, "\n", -1);
|
lines = g_strsplit(comment_text, "\n", -1);
|
||||||
len = g_strv_length(lines) - 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);
|
tmp = g_strjoinv("\n", lines);
|
||||||
|
|
||||||
/* add frame_start and frame_end */
|
/* 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);
|
utils_free_pointers(4, prefix, tmp, frame_start, frame_end, NULL);
|
||||||
g_free(tmp);
|
|
||||||
g_strfreev(lines);
|
g_strfreev(lines);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user