nvim-cmp icon indicating copy to clipboard operation
nvim-cmp copied to clipboard

"E129: Function name required" when setting pastetoggle

Open keith-rollin opened this issue 3 years ago • 2 comments

FAQ

  • [X] I have checked the FAQ and it didn't resolve my problem.

Announcement

Minimal reproducible full config

I kept the template mostly unchanged, only adding the two lines at the bottom.

if has('vim_starting')
  set encoding=utf-8
endif
scriptencoding utf-8

if &compatible
  set nocompatible
endif

let s:plug_dir = expand('/tmp/plugged/vim-plug')
if !filereadable(s:plug_dir .. '/plug.vim')
  execute printf('!curl -fLo %s/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim', s:plug_dir)
end

execute 'set runtimepath+=' . s:plug_dir
call plug#begin(s:plug_dir)
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/vim-vsnip'
Plug 'neovim/nvim-lspconfig'
call plug#end()
PlugInstall | quit

" Setup global configuration. More on configuration below.
lua << EOF
local cmp = require "cmp"
cmp.setup {
  snippet = {
    expand = function(args)
      vim.fn["vsnip#anonymous"](args.body)
    end,
  },

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

  sources = {
    { name = "nvim_lsp" },
    { name = "buffer" },
  },
}
EOF

lua << EOF
local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())

require'lspconfig'.cssls.setup {
  capabilities = capabilities,
}
EOF


let mapleader = "\<space>"
set pastetoggle=<leader>v

Description

Trying to use auto-completion (entering some text and then trying to accept a suggestion or navigate the popup menu) results in the following error message at the bottom of the screen:

E129: Function name required

Running in Verbose mode to help track this down, the last line printed before the error occurs is:

Executing: call:lua.cmp.utils.keymap.set_map(1)

I'm wondering if this is related to the following mapping established in nvim-cmp/lua/cmp/utils/keymap.lua, which is the only place I see the path reported in the Verbose logging:

i  <C-P>       * <Cmd>call v:lua.cmp.utils.keymap.set_map(1)<CR>

Steps to reproduce

  • Run nvim -u cmp-repro.vim cmp-repro.vim
  • Press 'G' to move to the last line where pastetoggle is set
  • Press 'o' to start editing under that line
  • Enter 'past' so that the autocomplete menu shows up
  • Press Enter to accept a completion

Expected behavior

That can select text to be entered into my document and that I can press the "accept" key sequence to enter it into my document.

Actual behavior

Interacting with the popup menu results in the error message I described.

Additional context

Commenting out the "set pastetoggle" line in cmp-repro.vim causes the error to not occur and for successful operation of auto-complete.

Various flags are changed after this error. For instance, paste mode is enabled, tab settings are set to their defaults, etc.

keith-rollin avatar Jul 27 '22 07:07 keith-rollin

I can reproduce this. But I think set pastetoggle=<Leader>v is not valid option command. What do you think about this?

hrsh7th avatar Aug 20 '22 12:08 hrsh7th

I think I see what you're saying. "<Leader>" is for key mappings, so why would it be allowed when setting 'pastetoggle'? I think the documentation for 'pastetoggle' hints that it should work:

	When non-empty, specifies the key sequence that toggles the 'paste'
	option.  This is like specifying a mapping:
	    :map {keys} :set invpaste<CR>
	Where {keys} is the value of 'pastetoggle'.

So if setting 'pastetoggle' is equivalent to invoking ':map', then one could reasonably infer that "<Leader>" would be supported in both places.

I'd used that 'pastetoggle' sequence for ages with no problems, so it seems supported. And I didn't come up with it myself; I copied it from somewhere. This means that other people are also using it. A Google search turns up other people recommending using "<Leader>" this way. So even if it's not officially supported, it's probably "de facto" supported.

This is a goofy bug, whether it's in nvim-cmp or in neovim. It caused me to give up on trying to use nvim-cmp two or three times before I decided to really concentrate on tracking it down. But maybe other people who have run across this issue just gave up and moved on to some other 'completion' tool after getting frustrated. It's a lousy experience and it would be great to do something so that future people could avoid it.

For my own future experience, I'm OK if this doesn't get fixed. I tracked down the issue and I've undefined 'pastetoggle'; I can live without it. But I posted the bug in case it was something you could address for other people hitting the same issue.

keith-rollin avatar Aug 20 '22 17:08 keith-rollin