From 4235b806b88f2914243d1f4b7d9ae5a47e03bbf1 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Wed, 8 Feb 2023 17:36:23 +0000 Subject: [PATCH 1/2] Don't insert * after new line in multi-line comment if previous line doesn't start with * Fixes #3386. --- doc/geany.txt | 3 ++- src/editor.c | 15 +++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/doc/geany.txt b/doc/geany.txt index 5612b9558a..4390931780 100644 --- a/doc/geany.txt +++ b/doc/geany.txt @@ -2208,7 +2208,8 @@ Automatic continuation multi-line comments * on the next line with the correct indentation based on the previous line, - as long as the multi-line is not closed by ``*/``. + as long as the multi-line is not closed by ``*/``. If the previous line + has no ``*`` prefix, the new line will not be changed. Autocomplete symbols When you start to type a symbol name, look for the full string to diff --git a/src/editor.c b/src/editor.c index 9114740e04..951e3c9178 100644 --- a/src/editor.c +++ b/src/editor.c @@ -3492,8 +3492,8 @@ static void auto_multiline(GeanyEditor *editor, gint cur_line) if (sci_get_style_at(sci, indent_pos) == style || indent_pos >= sci_get_length(sci)) { gchar *previous_line = sci_get_line(sci, cur_line - 1); - /* the type of comment, '*' (C/C++/Java), '+' and the others (D) */ - const gchar *continuation = "*"; + /* the type of comment, '*' (C/C++/Java), '+' D comment that nests */ + const gchar *continuation = (style == SCE_D_COMMENTNESTED) ? "+" : "*"; const gchar *whitespace = ""; /* to hold whitespace if needed */ gchar *result; gint len = strlen(previous_line); @@ -3526,10 +3526,13 @@ static void auto_multiline(GeanyEditor *editor, gint cur_line) { /* we are on the second line of a multi line comment, so we have to insert white space */ whitespace = " "; } - - if (style == SCE_D_COMMENTNESTED) - continuation = "+"; /* for nested comments in D */ - + else if (!(g_str_has_prefix(previous_line + i, continuation) && + (i + 1 == len || isspace(previous_line[i + 1])))) + { + // previous line isn't formatted so abort + g_free(previous_line); + return; + } result = g_strconcat(whitespace, continuation, " ", NULL); sci_add_text(sci, result); g_free(result); From a21ad8df2e9370ac7c3f233a3204724483e9aa8e Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Thu, 16 Feb 2023 17:24:23 +0000 Subject: [PATCH 2/2] Tweak wording --- doc/geany.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/geany.txt b/doc/geany.txt index 4390931780..cfb1ef86e2 100644 --- a/doc/geany.txt +++ b/doc/geany.txt @@ -2209,7 +2209,7 @@ Automatic continuation multi-line comments on the next line with the correct indentation based on the previous line, as long as the multi-line is not closed by ``*/``. If the previous line - has no ``*`` prefix, the new line will not be changed. + has no ``*`` prefix, no ``*`` will be added to the new line. Autocomplete symbols When you start to type a symbol name, look for the full string to