Hi, > As it seems to be trying to get the line, can't it just use > sci_get_line which is length safe and null terminated?
Thanks for the tip. This does make the code more readable and arguably safer. Attached is a new patch. Best regards, Tambet
Index: src/callbacks.c =================================================================== --- src/callbacks.c (revision 5096) +++ 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 5096) +++ 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,30 @@ 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++) + { + gchar *linebuf; + + x = 0; + linebuf = sci_get_line(editor->sci, i); + g_strdelimit(linebuf, "\r\n", '\0'); + while (isspace(linebuf[x])) x++; + + /* omit blank lines from minimum indentation calculation, if not allowed */ + if (x < minx && (allow_empty_lines || linebuf[x] != '\0')) + minx = x; + g_free(linebuf); + } + } + + if (minx == G_MAXINT) + minx = 0; + for (i = first_line; (i <= last_line) && (! break_loop); i++) { gint buf_len; @@ -3115,7 +3139,7 @@ single_line = TRUE; if (ft->comment_use_indent) - start = line_start + x; + start = line_start + minx; if (toggle) {
_______________________________________________ Geany-devel mailing list Geany-devel@uvena.de http://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel