Ron89 / thesaurus_query.vim

Multi-language Thesaurus Query and Replacement plugin for Vim/NeoVim
http://www.vim.org/scripts/script.php?script_id=5341
Apache License 2.0
220 stars 23 forks source link

Support for native vim auto-complete and mappings (eg ^X - ^T) #7

Open petRUShka opened 8 years ago

petRUShka commented 8 years ago

There is native vim support for thesaurus:

'thesaurus' 'tsr' string (default "") global or local to buffer global-local List of file names, separated by commas, that are used to lookup words for thesaurus completion commands i_CTRL-X_CTRL-T. Each line in the file should contain words with similar meaning, separated by non-keyword characters (white space is preferred). Maximum line length is 510 bytes.

It would be great for that plugin to replace that functionality. Because sometimes it much better for speed and convenience to have autocomplete list.

Ron89 commented 8 years ago

Hmm. Actually, one of the original motivation for me to create this plugin is that I don't like the menu-like synonym choosing interface, browsing dozens or even hundreds of synonyms one by one could be a very painful experience. I intended to design it to be similar to Vim's spell check function rather than auto-completion functionality, so that all options are displayed nice and clean. And you can choose the synonym with a simple number. But if you want, I guess sending the query result back to Vim's auto-completion is doable. I'll need some time to read-up on how, though.

There is one issue I can think of. If user choose to use this plugin's query result as a source for Vim's auto-completion(after it's made possible). Each auto-complete invoking key-stroke will invoke online query function, which can take seconds to complete. That might pose significant lagging. With async feature provided by NeoVim or Vim 8+, it is possible to reduce the lag time. But that is still yet to be seen.

Ron89 commented 8 years ago

Insert-mode auto-completion is added through completefunc (commit 98a3d20). That is, by <ctrl-x ctrl-u> in insert mode, online-query functionality will be invoked.

petRUShka commented 8 years ago

Great! I'll try it!

petRUShka commented 8 years ago

By the way. Is it impossible to bind ctrl-X ctrl-T?

petRUShka commented 8 years ago

When I try to use ctrl-x ctrl-u for Enlish word I catch an error:

WARNING: one or more query backends report error. Please check on thesaurus source(s).    
Error detected while processing function thesaurus_query#auto_complete_integrate:    
line 23:     
Traceback (most recent call last):    
Error detected while processing function thesaurus_query#auto_complete_integrate:    
line 23:     
 File "<string>", line 8, in <module>    
Error detected while processing function thesaurus_query#auto_complete_integrate:    
line 23:     
vim.error: Vim(let):E121: Undefined variable: u 

When I use it for Russian word it is just:

User defined completion (^U^N^P) Pattern not found

When I use <Leader>-cs it works perfectly both for Russian and English.

Ron89 commented 8 years ago

The issue is likely caused by:

  1. the decoding of utf-8 characters. Implementing it was an afterthought, so there were a lot of inconsistencies in the code.
  2. Vim 7.3 don't accept decoded unicode string return from Python while Vim 7.4 do, hence when there are Russian words, Vim 7.3 tend to report error when result is returned from Python.

In latest commits(1b323a6), I have systematically went through all the encoding details within modules. It should work fine at this point(I have already tested it on OS X and Linux, both Vim 7.3 and Vim 7.4).


Your

User defined completion (^U^N^P) Pattern not found

for Russian query is possibly caused by not setting g:tq_language or buffer specific b:tq_language correctly. You should set it to either ['ru', 'en'] or 'ru' in your ~/.vimrc to activate Russian synonym query.


I don't know if overriding ctrl-X ctrl-T is possible. As far as I know, the documentation of Vim didn't cover it. And I don't believe it's as simple as remapping. But after reading Vim's documentation, I find completefunc flexible enough for me to implement the insert-mode autocompletion functionality, so I coded as such.

Hope you find the fixed plugin better suited your working style. :D