Hi,

I wasn't sure if I should make a feature request or a bug report, so if needed, let me know which and I'll file it on the project site.

The patch attached to this message does a few things, sorry I didn't split them into different patches, but it's so small and related that it's hardly worth it.

Here's what the patch does:

#1
--
Makes the indent parameter value used for calls to make_comment_block() a "global", so that it's settable from a single location. It also makes it 3 instead of 8, where before it was 3 for function templates, and 8 for license and fileheader. I guess it's a matter of taste on this value, but IMHO, 8 is just too much. This is related to feature request 'Specify spacing before fileheader - ID: 3193527'[1].

#2
--
Strips whitespace from the start and end of the templates before passing to make_comment_block() so that trailing newlines are consistent. I'm not sure if this is desired or not, but I think the resulting comment looks better than before where there was 2 empty comment lines before the closing */. I'm also not sure if the 3 calls to g_strstrip() should be just a single call inside the make_comment_block() function. Also, not being very familiar with GString, I'm not 100% sure if calling g_strstrip() on the ->str member behind its back is OK, but it seems fine since g_strstrip() changes the string in place without changing the amount of memory used.

#3
--
Change filetypes.c to use /* */ style comments rather than // style, to prevent those ISO C90 warnings from GCC. It's probably best to make the default for C not be C++ style comments.

With the small amount of testing I've done, it seems to all work fine.

[1] https://sourceforge.net/tracker/?func=detail&aid=3193527&group_id=153444&atid=787794

Cheers,
Matthew Brush (codebrainz)
Index: src/templates.c
===================================================================
--- src/templates.c	(revision 5587)
+++ src/templates.c	(working copy)
@@ -511,7 +511,7 @@
 	len = g_strv_length(lines);
 	if (len > 0)	/* prevent unsigned wraparound if comment_text is empty */
 	{
-		for (i = 0; i < len - 1; i++)
+		for (i = 0; i < len; i++)
 		{
 			tmp = lines[i];
 			lines[i] = g_strconcat(prefix, tmp, NULL);
@@ -527,7 +527,7 @@
 	if (frame_start != NULL)
 		g_string_append(comment_text, frame_start);
 	/* add the new main content */
-	g_string_append(comment_text, tmp);
+	g_string_append_printf(comment_text, "%s%s", tmp, template_eol_char);
 	/* add frame_start  */
 	if (frame_end != NULL)
 		g_string_append(comment_text, frame_end);
@@ -549,7 +549,9 @@
 	templates_replace_default_dates(template);
 	templates_replace_command(template, DOC_FILENAME(doc), doc->file_type->name, NULL);
 
-	make_comment_block(template, doc->file_type->id, 8);
+	g_strstrip(template->str);
+
+	make_comment_block(template, doc->file_type->id, GEANY_TEMPLATES_HEADER_INDENT);
 	convert_eol_characters(template, doc);
 
 	return g_string_free(template, FALSE);
@@ -566,9 +568,11 @@
 		"{gpl}", templates[GEANY_TEMPLATE_GPL],
 		"{bsd}", templates[GEANY_TEMPLATE_BSD],
 		NULL);
+	
+	g_strstrip(template->str);
 
 	/* we don't replace other wildcards here otherwise they would get done twice for files */
-	make_comment_block(template, ft->id, 8);
+	make_comment_block(template, ft->id, GEANY_TEMPLATES_HEADER_INDENT);
 	return g_string_free(template, FALSE);
 }
 
@@ -625,7 +629,9 @@
 	templates_replace_default_dates(text);
 	templates_replace_command(text, DOC_FILENAME(doc), doc->file_type->name, func_name);
 
-	make_comment_block(text, doc->file_type->id, 3);
+	g_strstrip(text->str);
+
+	make_comment_block(text, doc->file_type->id, GEANY_TEMPLATES_HEADER_INDENT);
 	convert_eol_characters(text, doc);
 
 	return g_string_free(text, FALSE);
Index: src/templates.h
===================================================================
--- src/templates.h	(revision 5587)
+++ src/templates.h	(working copy)
@@ -30,6 +30,8 @@
 #ifndef GEANY_TEMPLATES_H
 #define GEANY_TEMPLATES_H 1
 
+#define GEANY_TEMPLATES_HEADER_INDENT 3
+
 enum
 {
 	GEANY_TEMPLATE_GPL = 0,
Index: data/filetypes.c
===================================================================
--- data/filetypes.c	(revision 5587)
+++ data/filetypes.c	(working copy)
@@ -47,11 +47,11 @@
 #wordchars=_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
 
 # if only single comment char is supported like # in this file, leave comment_close blank
-comment_open=//
-comment_close=
-# this is an alternative way, so multiline comments are used
-#comment_open=/*
-#comment_close=*/
+comment_open=/*
+comment_close=*/
+# this is an alternative way, so single line comments are used
+#comment_open=//
+#comment_close=
 
 # set to false if a comment character/string should start at column 0 of a line, true uses any
 # indentation of the line, e.g. setting to true causes the following on pressing CTRL+d
_______________________________________________
Geany-devel mailing list
Geany-devel@uvena.de
http://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel

Reply via email to