Hi,

I sent in a patch on April 23rd, but have not received any accept /
reject notice, possibly because I didn't tag it with [patch], so here
it is again. Resolves feature request #2990915 as illustrated here:

http://i.imgur.com/sYCIf.png

When comment_use_indent is set to true in per-filetype config,
comments are no longer indented on a line-by-line basis, but have the
indentation of the least indented line in the block. This looks a lot
better.

In addition, empty lines are commented out by default. In the original
patch, I introduced a new option for it, but Thomas Martitz suggested
that this is not preferable.

Best regards,
Tambet
Index: src/callbacks.c
===================================================================
--- src/callbacks.c	(revision 5009)
+++ src/callbacks.c	(working copy)
@@ -1631,7 +1631,7 @@
 	GeanyDocument *doc = document_get_current();
 	g_return_if_fail(doc != NULL);
 
-	editor_do_comment(doc->editor, -1, FALSE, FALSE);
+	editor_do_comment(doc->editor, -1, TRUE, FALSE);
 }
 
 
Index: src/editor.c
===================================================================
--- src/editor.c	(revision 5009)
+++ src/editor.c	(working copy)
@@ -3043,7 +3043,7 @@
 void editor_do_comment(GeanyEditor *editor, gint line, gboolean allow_empty_lines, gboolean toggle)
 {
 	gint first_line, last_line;
-	gint x, i, line_start, line_len;
+	gint x, minx, i, line_start, line_len;
 	gint sel_start, sel_end, co_len;
 	gchar sel[256], *co, *cc;
 	gboolean break_loop = FALSE, single_line = FALSE;
@@ -3089,6 +3089,36 @@
 
 	sci_start_undo_action(editor->sci);
 
+	/* find block's minimum indentation */
+	minx = G_MAXINT;
+	
+	if (ft->comment_use_indent) 
+	{
+		for (i = first_line; i <= last_line; i++)
+		{
+			gint buf_len;
+
+			line_start = sci_get_position_from_line(editor->sci, i);
+			line_len = sci_get_line_length(editor->sci, i);
+			x = 0;
+
+			buf_len = MIN((gint)sizeof(sel) - 1, line_len - 1);
+			if (buf_len < 0)
+				continue;
+			sci_get_text_range(editor->sci, line_start, line_start + buf_len, sel);
+			sel[buf_len] = '\0';
+
+			while (isspace(sel[x])) x++;
+			
+			/* omit blank lines from minimum indentation calculation, if not allowed */
+			if (x < minx && (allow_empty_lines || (x < line_len && sel[x] != '\0')))
+				minx = x;
+		}
+	}
+
+	if (minx == G_MAXINT)
+		minx = 0;
+
 	for (i = first_line; (i <= last_line) && (! break_loop); i++)
 	{
 		gint buf_len;
@@ -3115,7 +3145,7 @@
 				single_line = TRUE;
 
 				if (ft->comment_use_indent)
-					start = line_start + x;
+					start = line_start + minx;
 
 				if (toggle)
 				{
_______________________________________________
Geany-devel mailing list
[email protected]
http://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel

Reply via email to