Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line toggler doesn't work (v0.6.1) #265

Closed
delminskii opened this issue Oct 22, 2022 · 5 comments
Closed

Line toggler doesn't work (v0.6.1) #265

delminskii opened this issue Oct 22, 2022 · 5 comments

Comments

@delminskii
Copy link

delminskii commented Oct 22, 2022

I noticed a toggle (set as a custom <Leader>cc shortcut by me) doesn't work anymore after some update I don't know which. Other than that works perfect. I've tried neovim both 0.7.2 & 0.8.0 - still no luck.
Btw, the mappings listed in extra table of the config below works great.
Timeoutlen value equals to 1000.

Plugin version tag: 0.6.1 (set via packer plugin manager)
Neovim version: the latest 0.9.0 build from github repo (appimage build)

My plugin related settings:

-- =============================================================================
-- Comment.nvim settings
-- =============================================================================
local U = require('Comment.utils')
local A = vim.api
local opt = {silent = true, noremap = true}
require('Comment').setup({
  ignore = '^$',

  ---LHS of toggle mappings in NORMAL + VISUAL mode
  ---@type table
  toggler = {
    ---Line-comment toggle keymap
    line = '<Leader>cc',
  },

  ---LHS of operator-pending mappings in NORMAL + VISUAL mode
  ---@type table
  opleader = {
    ---Line-comment keymap
    line = '<Leader>c',
  },

  ---LHS of extra mappings
  ---@type table
  extra = {
    ---Add comment on the line above
    above = '<Leader>cO',
    ---Add comment on the line below
    below = '<Leader>co',
    ---Add comment at the end of line
    eol = '<Leader>cA',
  },
})

-- https:/numToStr/Comment.nvim/issues/70#issuecomment-998494798
function _G.___gdc(vmode)
  local range = U.get_region(vmode)
  local lines = U.get_lines(range)

  -- Copying the block
  local srow = range.erow
  A.nvim_buf_set_lines(0, srow, srow, false, lines)

  -- Doing the comment
  require('Comment.api').toggle_linewise_op(vmode)

  -- Move the cursor
  local erow = srow + 1
  local line = U.get_lines({ srow = srow, erow = erow })
  local _, col = U.grab_indent(line[1])
  A.nvim_win_set_cursor(0, { erow, col })
end

-- <Leader>dc will do (yank & comment & paste);
-- Example: <Leader>dc3j will copy & comment 4 lines (current+3 below) and
-- paste them after
map('x', '<Leader>dc', [[<ESC><CMD>lua ___gdc(vim.fn.visualmode())<CR>]])
map('n', '<Leader>dc', [[<CMD>set operatorfunc=v:lua.___gdc<CR>g@]])
@delminskii delminskii changed the title Toggler doesn't work (v0.6.1) Line toggler doesn't work (v0.6.1) Oct 22, 2022
@numToStr
Copy link
Owner

I highly doubt that <leader>cc is not working. Everything is working fine for me.

Beside that, in function _G.___gdc you need to replace toggle_linewise_op with toggle.linewise

@delminskii
Copy link
Author

delminskii commented Oct 22, 2022

@numToStr Thank you very much. I use xterm-256color terminal on my debian10 machine. I've tried to use toggle.linewise instead of toggle_linewise_op function name but I get an error telling that toggle.linewise is nil (please note I use deprecated old 0.6.1 version - I think becase of that). Everything works great to me with toggle_linewise_op written.
The default gcc doesn't work too (in case I do not set any options table to setup function explicitly)

Also, I have tried everything listed in #115 . I even see \cc in :map list.
2022-10-22--1666427150_774x55_scrot

@numToStr
Copy link
Owner

@delminskii You should also follow PR #183 to know more about the deprecated functions etc. Obviously this is for future reference, when you are ready to upgrade.

@delminskii
Copy link
Author

@numToStr Yeah, thank you. I've had to upgrade to the latest (current) version of your plugin and rewrite my code a little bit. Now everything works fine.

function _G.___gdc(vmode)
  local range = U.get_region(vmode)
  local lines = U.get_lines(range)

  -- Copying the block
  local srow = range.erow
  A.nvim_buf_set_lines(0, srow, srow, false, lines)

  -- Doing the comment
  require('Comment.api').toggle.linewise(vmode)

  -- Move the cursor
  local erow = srow + 1
  local line = U.get_lines({ srow = srow, erow = erow })
  local _, col, _ = string.find(line[1], '^(%s*)')
  A.nvim_win_set_cursor(0, { erow, col })
end

@Raskilas
Copy link

It is seems that because of configuration provided to plugin inside require('Comment').setup({ ... }) you should call :PackerSync on each configuration update (for Packer plugin manager of course).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants