vim-textobj-quote icon indicating copy to clipboard operation
vim-textobj-quote copied to clipboard

Educate just doesn’t switch on automatically

Open mcepl opened this issue 4 years ago • 15 comments

No matter whether I rely on default (which is supposed to be that educate is on), or whether I add 'educate': 1 explicitly to the configuration of the plugin), it is always off, and I have to run command :Edcuate every time I start new instance of vim (neovim from the master branch of the git, or vim 8.2.0348, but I have observed it for some time already).

I don’t see any error messages anywhere.

mcepl avatar Apr 13 '20 09:04 mcepl

Can you please post your vim RC code for how you are setting 'educate': 1? I suspect this is just an issue with your usage of autocmd or similar, it definitely works for me. In fact my preference is to have it defaulting to off and enable it manually, and I find I have to be very careful and aggressive about how I set it to 0 to actually keep it off.

alerque avatar Apr 13 '20 10:04 alerque

Here it is (complete vimrc is on https://gitlab.com/mcepl/vimdir/-/blob/master/vimrc ):

" for vim-textobj-quote
function! TextObjSettings()
  if exists(":Educate")
      if &spelllang =~ 'cs'
         call textobj#quote#init({ 'double':'„“', 'single':'‚‘', 'educate': 1 })
      elseif &spelllang =~ 'en'
         call textobj#quote#init({ 'double':'“”', 'single':'‘’', 'educate': 1 })
      endif
      exe "Educate"
  endif
endfunction
map <silent> <leader>qc <Plug>ReplaceWithCurly

let g:textobj#quote#educate = 1
autocmd OptionSet spelllang call TextObjSettings()
autocmd BufEnter  *.rst     call TextObjSettings()
noremap <buffer> <Leader>sq call TextObjSettings()

mcepl avatar Apr 13 '20 11:04 mcepl

Why are you running exe "Educate" as part of that function?

alerque avatar Apr 13 '20 14:04 alerque

Why are you running exe "Educate" as part of that function?

One of many desperate attempts to switch educate on?

mcepl avatar Apr 13 '20 16:04 mcepl

@mcepl FWIW, I installed this plugin the other day and had the same problem. Found this issue when googling the problem. I could activate Educate manually, but I couldn't get it to come on with the FileType autocmd provided in the documentation. After some trial and error, I discovered that my problem was caused by a conflict with the jiangmiao/auto-pairs plugin. When I removed that plugin, everything worked as expected.

Since I use coc.nvim, I just switched to using the coc-pairs plugin instead. Hope that helps!

joshukraine avatar Apr 30 '20 15:04 joshukraine

@mcepl Have you tried testing this creating a MWE with just this plugin and nothing else?

alerque avatar Apr 30 '20 15:04 alerque

No auto-pairs here.

mcepl avatar May 01 '20 07:05 mcepl

@mcepl Do you mean you don't have auto-pairs or you do? If the latter (as your comma suggests) then I think we can narrow this down to that. If the former, please don't just limit the test to disabling auto-pairs, strip all other plugins to a bare minimum config with just this plugin and see if it still fails.

alerque avatar May 01 '20 08:05 alerque

Sorry, the comma was a mistake.

mcepl avatar May 01 '20 11:05 mcepl

You are right, this is a clash with https://github.com/tmsvg/pear-tree , when I removed that, Educate is suddenly automatically on. Thank you.

mcepl avatar May 02 '20 20:05 mcepl

Hmm. I would actually be inclined to keep this open. If we are clashing with multiple other plugins (in this case both plugins doing a similar thing) we (or they) might be doing something wrong. I don't think these necessarily need to conflict, or at least could do so more gracefully.

alerque avatar May 02 '20 20:05 alerque

OK

mcepl avatar May 03 '20 15:05 mcepl

Hey @tmsvg or @jiangmiao do either of you happen to have an idea off the top of your head why a plugin like this would conflict or what should be done about it. I imagine there is a hook somewhere both plugins are trying to grab and that we should check if it has been previously utilized, but I'm not quite sure where to start.

alerque avatar May 12 '20 14:05 alerque

vim-textobj-quote and the other plugins mentioned here (auto-pairs, pear-tree) are using inoremap to map various keypresses in insert mode to execute their own functions. I believe that results in a bad interaction if multiple plugins want to define what should happen for the same keypress (e.g. ' and ").

I'm not sure how that could be fixed in a proper way, but as a workaround, I started to make sure only one of these plugins take control for a given key. For example, the auto-pairs plugin can be configured per file type to handle only a subset of keypresses instead of its default list:

autocmd FileType markdown let b:AutoPairs = { '(':')', '[':']', '`':'`', '```':'```' }
autocmd FileType mail let b:AutoPairs = { '(':')', '[':']', '`':'`' }

In other words, I can describe that I'm fine to only auto-pair (, [, ` and ``` keys/sequences while editing markdown files, and only (, [, and ` while editing mail. That way the auto-pairs plugin doesn't map the ' and " keys for its own purposes, leaving vim-textobj-quote to do its own thing.

I wonder if there's a good way to somehow let these mappings to be chained :thinking: E.g. let vim-textobj-quote to replace straight quote " with curly quote , and then let auto-pairs insert its curly pair resulting in “”.

ferki avatar Feb 12 '22 11:02 ferki

I'm sure we could figure out some sort of handoff, bit it might take some fiddling and cooperation for both sides with a hook / callback of some sort since the trigger event isn't quite what the other side normally handles.

alerque avatar Feb 12 '22 11:02 alerque