lifepillar / vim-mucomplete

Chained completion that works the way you want!
MIT License
913 stars 18 forks source link

Implement custom dict method #44

Closed lacygoill closed 7 years ago

lacygoill commented 7 years ago

Hello,

this is an attempt at implementing a custom dictmethod to get around the issue discussed here.

It seems to work, but the code is so similar to the file implementing the uspl method that it could be improved by creating only one file which would be used to give suggestions from various sources. It could be used as a kind of library, is that the correct term?

lacygoill commented 7 years ago

Sorry, I've just realised that the 'dictionary' option could contain several filepaths. I don't know how to handle that.

Maybe, instead of:

let l:suggestions = readfile(&l:dictionary)

One should write:

let l:suggestions = []
for l:list in map(split(&l:dictionary, ','), "readfile(v:val)")
     call extend(l:suggestions, l:list)
endfor
lacygoill commented 7 years ago

I think this should do it:

  let l:suggestions = []
  for l:list in map(split(&l:dictionary, ','), "readfile(v:val)")
      call extend(l:suggestions, l:list)
  endfor

  call filter(l:suggestions, 'stridx(v:val, l:word) == 0')
lacygoill commented 7 years ago

I added the option g:mucomplete#dict#match_at_start, similar to g:mucomplete#ultisnips#match_at_start. When it's set to 0, the method should suggest any word from the dictionary containing the word before the cursor, even if it's not at the beginning.

lacygoill commented 7 years ago

Well, I'm not sure this is a good idea, after all...

There are several problems to take care of. Like possible commas in the filename, spell entry, add the filename of the dictionary in the description field of the menu...

I think I could do that, but I'm not sure you would be interested in it. Let me know what you think.

lifepillar commented 7 years ago

I think that this is going towards a direction that is against µcomplete's philosophy. Also, the motivation for this, i.e., overcoming a limitation of some key mappings (https://github.com/lifepillar/vim-mucomplete/issues/43) is not so strong, because the key mappings may be redefined.

Thanks anyway for the effort you've put on it!

lifepillar commented 7 years ago

Thinking more about this, a plugin that collects several custom completion methods (abbrev, extended dict, snippets, etc…) might be interesting independent of µcomplete. It could easily provide integration with µcomplete, but also work for other plugins (or without other plugins), and it would allow me to keep µcomplete as minimal as it deserves.

If you decide to take such an endeavour, let me know!