preservim / vim-textobj-quote

Use ‘curly’ quote characters in Vim
Other
123 stars 6 forks source link

Educate just doesn’t switch on automatically #20

Open mcepl opened 4 years ago

mcepl commented 4 years ago

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.

alerque commented 4 years ago

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.

mcepl commented 4 years ago

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()
alerque commented 4 years ago

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

mcepl commented 4 years ago

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

One of many desperate attempts to switch educate on?

joshukraine commented 4 years ago

@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!

alerque commented 4 years ago

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

mcepl commented 4 years ago

No auto-pairs here.

alerque commented 4 years ago

@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.

mcepl commented 4 years ago

Sorry, the comma was a mistake.

mcepl commented 4 years ago

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.

alerque commented 4 years ago

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.

mcepl commented 4 years ago

OK

alerque commented 4 years ago

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.

ferki commented 2 years ago

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 “”.

alerque commented 2 years ago

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.