Geany: How to make blank newlines also commented with Ctrl+E?

Created on 2 Aug 2019  路  4Comments  路  Source: geany/geany

For example, take this Ruby code:

(0..9).each do |i|
  puts i

  puts '-' if (i % 3) == 0
end

If you do Ctrl+E, it will produce this:

#(0..9).each do |i|
#  puts i

#  puts '-' if (i % 3) == 0
#end

But, I'd like it to produce this:

#(0..9).each do |i|
#  puts i
#  
#  puts '-' if (i % 3) == 0
#end

You can imagine that code with many blank newlines makes it hard to distinguish if the whole block is commented, or just sections.

Is there a setting for this?

I think this is useful for usually-single-line-commented languages, like Ruby/Python, especially if your settings don't strip spaces on newline.

Thanks.

question

Most helpful comment

After a little archaeology, there was discussion about this here
Then it was moved to Github, mixed in with an unrelated commit in #1.
Then it was split out into #6, but then closed by the author @losingkeys due to inactivity.

The only part that confuses me is that the above mentioned issues were to do exactly the opposite of what this question is asking for, and I cannot see any relevant changes to this code in the intervening years.

I guess not that many people care for this option, but I would really like it haha.

It seems reasonable to me, especially if it's made optional.

All 4 comments

I vaguely thought there was an option for this, but I can't find it now, maybe it was proposed and never implemented.

Yes, I also searched through the current manual and couldn't find anything. I also searched through the open issues.

I guess not that many people care for this option, but I would really like it haha.

After a little archaeology, there was discussion about this here
Then it was moved to Github, mixed in with an unrelated commit in #1.
Then it was split out into #6, but then closed by the author @losingkeys due to inactivity.

The only part that confuses me is that the above mentioned issues were to do exactly the opposite of what this question is asking for, and I cannot see any relevant changes to this code in the intervening years.

I guess not that many people care for this option, but I would really like it haha.

It seems reasonable to me, especially if it's made optional.

I tried just hacking it, and it works. The below is my git diff.

I don't know what buf_len should be set to, so I just set it to 0 and didn't cause any problems.

All of the changes below would be surrounded by some if statement for the setting. Also, instead of setting allow_empty_lines = TRUE; directly, that would be passed in as an arg.

The last step would be to add it as a preference to Edit=>Preferences=>Editor=>Features as a checkbox. I have no idea how to do that though, and will also have to create PO files (which is a lot of work).

diff --git a/src/editor.c b/src/editor.c
index 620248c4..8663ad90 100644
--- a/src/editor.c
+++ b/src/editor.c
@@ -3031,11 +3031,11 @@ gint editor_do_uncomment(GeanyEditor *editor, gint line, gboolean toggle)

                buf_len = MIN((gint)sizeof(sel) - 1, line_len);
                if (buf_len <= 0)
-                       continue;
+                       buf_len = 0;
                sci_get_text_range(editor->sci, line_start, line_start + buf_len, sel);
                sel[buf_len] = '\0';

-               while (isspace(sel[x])) x++;
+               //while (isspace(sel[x])) x++;

                /* to skip blank lines */
                if (x < line_len && sel[x] != '\0')
@@ -3140,8 +3140,8 @@ void editor_do_comment_toggle(GeanyEditor *editor)
                return;

        co_len = strlen(co);
-       if (co_len == 0)
-               return;
+       //if (co_len == 0)
+       //      return;

        sci_start_undo_action(editor->sci);

@@ -3155,11 +3155,11 @@ void editor_do_comment_toggle(GeanyEditor *editor)

                buf_len = MIN((gint)sizeof(sel) - 1, line_len);
                if (buf_len < 0)
-                       continue;
+                       buf_len = 0;
                sci_get_text_range(editor->sci, line_start, line_start + buf_len, sel);
                sel[buf_len] = '\0';

-               while (isspace(sel[x])) x++;
+               //while (isspace(sel[x])) x++;

                /* use single line comment */
                if (EMPTY(cc))
@@ -3310,9 +3310,9 @@ gint editor_do_comment(GeanyEditor *editor, gint line, gboolean allow_empty_line
        if (! filetype_get_comment_open_close(ft, single_comment, &co, &cc))
                return 0;

-       co_len = strlen(co);
-       if (co_len == 0)
-               return 0;
+       //co_len = strlen(co);
+       //if (co_len == 0)
+       //      return 0;

        sci_start_undo_action(editor->sci);

@@ -3326,11 +3326,12 @@ gint editor_do_comment(GeanyEditor *editor, gint line, gboolean allow_empty_line

                buf_len = MIN((gint)sizeof(sel) - 1, line_len);
                if (buf_len < 0)
-                       continue;
+                       buf_len = 0;
                sci_get_text_range(editor->sci, line_start, line_start + buf_len, sel);
                sel[buf_len] = '\0';

-               while (isspace(sel[x])) x++;
+               //while (isspace(sel[x])) x++;
+               allow_empty_lines = TRUE;

                /* to skip blank lines */
                if (allow_empty_lines || (x < line_len && sel[x] != '\0'))
Was this page helpful?
0 / 5 - 0 ratings

Related issues

sami10007 picture sami10007  路  4Comments

AdamDanischewski picture AdamDanischewski  路  13Comments

makitso picture makitso  路  16Comments

fyah picture fyah  路  4Comments

webdev23 picture webdev23  路  8Comments