commented.nvim icon indicating copy to clipboard operation
commented.nvim copied to clipboard

support left aligned commenting

Open tkkcc opened this issue 4 years ago • 11 comments

This is the best comment plugin for me. nvim-comment and kommentary still need improvement. The only missing feature in this plugin is left aligned commenting. Some code formater will align comments. For example, python format black will turn

# if i==1:
    # print(2)

into

# if i==1:
# print(2)

lua's format lua-format will turn

--if a == 1 then
  --a = 2
  --a = 2
--end

into

-- if a == 1 then
-- a = 2
-- a = 2
-- end

This makes coding tough, and left aligned commenting can avoid this issue. Both nvim-comment and kommentary choose left aligned commenting. and nerdcommenter binds <leader>cl to it.

Also, when <leader>cl is used to uncomment, various spacing handling should be skiped.

tkkcc avatar Jul 19 '21 12:07 tkkcc

Thank you for your clear explanation for this behavior. I haven't implemented this feature(out of laziness), but I guess it will not be too difficult to do.

winston0410 avatar Jul 20 '21 14:07 winston0410

@tkkcc The feature has been implemented in https://github.com/winston0410/commented.nvim/commit/994ca1e2213853cb54e6b36598e9222e57c8b52e

I haven't made the documentation yet, and it will be great if you could help out with that :)

winston0410 avatar Jul 21 '21 18:07 winston0410

Thanks. I tried the trim_leading_whitespace=true option, but what it did is just the issue it self. There seems a misunderstanding. For left aligned commenting, the comment string is left aligned, but original code's indention is preserved, so the code block will not be unexpectedly modified by code formatter during commenting and uncommenting. For example, commenting should turn

if i==1:
       print(2)

into

-- if i==1:
--        print(2)

then uncommenting should turn

-- if i==1:
--        print(2)

into

if i==1:
       print(2)

This is the default logic in vim-commentary, nvim-comment and kommentary, you can try any of them if you want.

tkkcc avatar Jul 22 '21 05:07 tkkcc

@tkkcc But isn't that the default behavior for commented (trim_leading_whitespace = false)? Can you provide a dummy code that I can use it for testing?

winston0410 avatar Jul 22 '21 06:07 winston0410

commented by default will turn

if i==1:
       print(2)

into

-- if i==1:
      -- print(2)

tkkcc avatar Jul 22 '21 07:07 tkkcc

@tkkcc Oh I get what you mean now. Let me fix this today.

winston0410 avatar Jul 22 '21 07:07 winston0410

@tkkcc check https://github.com/winston0410/commented.nvim/commit/60efd1bf3c06b2190511e6ad4b9ae9f08e1b41a0

winston0410 avatar Jul 22 '21 08:07 winston0410

Current issue is the comment string is not context aware. I get

if true:
#     if i == 1:
#         print(2)

expect

if true:
    # if i == 1:
    #     print(2)

tkkcc avatar Jul 22 '21 09:07 tkkcc

@tkkcc Right thank you for pointing that out. I guess it will take more on work on this one.

winston0410 avatar Jul 22 '21 10:07 winston0410

Please consider reopening the issue

ahmedkhalf avatar Aug 01 '21 13:08 ahmedkhalf

@ahmedkhalf Reopened, as this is not fixed yet.

winston0410 avatar Aug 01 '21 13:08 winston0410