Is it possible to change loaded dictionary dynamically based `filetype` change?
tzws opened this issue · 7 comments
Is it possible to change loaded dictionary dynamically based filetype
change?
I've 2 workflows.
- use
tabnnew
to create a scratch window/buffer to do some work, such as edit/format a message before sending, drop the buffer after paste the message to IM. In this case, the &filetype is an empty string.
Is it possible to define some dict for &filetype is empty string in the config something like:
dic = {
[""] = string.format('%s/site/pack/packer/start/vim-dict/dict/text.dict',vim.fn.stdpath('data')),
["text"] = string.format('%s/site/pack/packer/start/vim-dict/dict/text.dict',vim.fn.stdpath('data')),
["javascript,typescript"] = { string.format('%s/site/pack/packer/start/vim-dict/dict/javascript.dict',vim.fn.stdpath('data')) },
["lua"] = { string.format('%s/site/pack/packer/start/vim-dict/dict/lua.dict',vim.fn.stdpath('data')) },
["vim"] = { string.format('%s/site/pack/packer/start/vim-dict/dict/vim.dict',vim.fn.stdpath('data')) },
}
- I'm working on some combined file type project, such as AWS cloudformation YAML file, it can contain shell/json code fragments.
I have defined some key binding to change the &filetype on the fly
nnoremap <leader>1 :set filetype=html<CR>
nnoremap <leader>2 :set filetype=javascript<CR>
nnoremap <leader>3 :set filetype=json<CR>
nnoremap <leader>4 :set filetype=sh<CR>
nnoremap <leader>5 :set filetype=sql<CR>
nnoremap <leader>6 :set filetype=vim<CR>
nnoremap <leader>7 :set filetype=txt<CR>
nnoremap <leader>8 :set filetype=lua<CR>
nnoremap <leader>9 :set filetype=tdx<CR>
nnoremap <leader>f1 :set filetype=log<CR>
nnoremap <leader>f2 :set filetype=txt<CR>
nnoremap <leader>f3 :set filetype=markdown<CR>
" Set buffer filetype
nnoremap <Leader>f= :set filetype=
For example, when I'm editing a yaml file which contains a lot of shell code, I press 4 to change the filetype to shell, take advantage of shell syntax highlighting.
After the &filetype changed, is it possible to detect the change, and load the specific dicts based on the changed filetype?
I think lua table can work fine with empty strings, since you can use anything as a key.
The second issue can also be solved. Since this is the default dictionary update, you can set it for au FileType *
as well.
autocmd FileType * lua require("cmp_dictionary.caches").update()
I can't reproduce. Is the problem caused by the above settings? In other words, is it a phenomenon that does not occur when you update to the latest version and disable the above settings, but occurs when you enable them?
I know that the display is not working properly. I can't help you if I don't know if it's a bug in this plugin, a hacky setting that caused it, a problem with cmp itself, or a problem with your settings that I don't know about.
No reply, so I'll close it.
Thanks. I think the 3rd column 'belong to javascript.dict' is the "preview" of nvim-cmp. Since a dict entry is itself, nothing behind this dict entry, nothing need to preview, unless we can define something for it to preview, like wordnet or wordweb, organize the dict into a json format like:
{ "child": { "plural": "children" , "singular": "" , "antonym": "parent" , "synonym": "kid" , "meaning": "a son or daughter" } }