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

Macro tracking issue #564

Closed
hrsh7th opened this issue Nov 22, 2021 · 8 comments
Closed

Macro tracking issue #564

hrsh7th opened this issue Nov 22, 2021 · 8 comments
Labels
difficult help wanted Extra attention is needed

Comments

@hrsh7th
Copy link
Owner

hrsh7th commented Nov 22, 2021

#551
#558

@hrsh7th
Copy link
Owner Author

hrsh7th commented Nov 22, 2021

I think we can't support macro correctly. (If anyone have any ideas, please let me know.

  1. The user press <CR> to confirm the selected item
  2. The <CR> will be added to the macro register literally
  3. The user executes the macro. the <CR> will add the new line (because the selected entry is nothing in executing macro)

I think the nvim-cmp should stop working in executing the macro.

@hrsh7th hrsh7th added difficult help wanted Extra attention is needed labels Nov 24, 2021
@eckon
Copy link

eckon commented Jan 5, 2022

Hey, firstly thanks for the great work @hrsh7th.

Then to my question: is there currently a way to deactivate this behavior? Meaning stopping nvim-cmp from executing in the macro as you mentioned?

Currently this prevents me from using any macros that include the symbols mentioned in #551 ,, ., ( (and I guess the same for #558 <CR> which is not as bad for me personally).
This I need from time to time, at least often enough that I can not ignore it, and I would be surprised if I am the only one (unless no one is using macros for refactoring anymore).

As far as I can remember coc.nvim also never completed correctly by itself in a macro (maybe even didn't do anything), which was fine, because it had no side-effects on the normal macro and I could just write the macro as if I did not have the completion.

I would like to help, but sadly I do not know how to fix this. Maybe if others still need this behavior and as a quickfix until someone else figured out a better way, add a flag to disable macro execution?

@smjonas
Copy link
Contributor

smjonas commented Jan 5, 2022

By the way, the RecordingEnter and RecordingLeave events have recently been added to Neovim. I think they will make things easier to implement now (I agree it would be nice to include an option to disable cmp when a macro is being recorded).

@dmitmel
Copy link
Collaborator

dmitmel commented Jan 5, 2022

There is no need for those autocommands, you can simply do

cmp.setup({
  enabled = function()
    return vim.fn.reg_recording() == ''
  end,
})

@eckon
Copy link

eckon commented Jan 5, 2022

@dmitmel good to know, sadly enabling/disabling cmp does not seem to work. I am guessing it is because the imaps are already set at the time of the recording.

image
etc.. (through :imap<CR>)

The events allow for a (at least for me) dirty way of unsetting these mappings when starting the macro, and it seems like nvim-cmp just rebinds them afterwards (but could be that this results in other problems - didnt try it out much yet).

In case anyone is interested (use at your own risk):

augroup HandleNvimCmpOnMacro
  autocmd!
  autocmd RecordingEnter * for symbol in [',', '.', '('] | execute('silent! iunmap ' . symbol) | endfor
augroup END

Of course if there is a better solution then I would be glad to throw this snippet away.

@hrsh7th
Copy link
Owner Author

hrsh7th commented Jan 5, 2022

Hm... we should define mapping as expr. and we should do something by returning <Cmd>call luaeval(...)<CR> instead of feedkeys.

@mikehaertl
Copy link

@hrsh7th Is this issue solved? Or why was it closed? What is the solution? I still have the problem that I can not record any linebreaks in my macros when I have this enabled:

      ['<CR>'] = cmp.mapping.confirm({ select = false }),

@mikehaertl
Copy link

Probably handled in #800 now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficult help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants