preservim / vim-textobj-quote

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

adapt educate to &spelllang #2

Open Konfekt opened 10 years ago

Konfekt commented 10 years ago

A feature request: If Educate is set, it changes quotes according to the current &spelllang. That is, if for example &spelllang = "de", the setting

let g:textobj#quote#doubleDefault = '„“' " „doppel“ let g:textobj#quote#singleDefault = '‚‘' " ‚einzel‘

is used.

reedes commented 10 years ago

The defaults could be set from &spelllang, but we'd need a good mapping of possible &spelllang values to the corresponding quotes for each language.

Here is one reference, but I can't vouch for its accuracy: http://en.wikipedia.org/wiki/International_variation_in_quotation_marks

For example, on that page under "Spanish" guillemets  are the primary, but an Argentinian friend said they aren't that common.

Without a verified mapping, I'm hesitant to force arbitrary defaults on users.

Konfekt commented 10 years ago

Ok,

So something that would not enforce anything but would still be helpful is a global dictionary variable between languages and quotation marks. Set to sensible defaults, but as a global variable modifiable by the user.

Then your educate function, as well as i/aq would look up the quotes corresponding to the current spellcheck language by this dictionary.

mcepl commented 7 years ago

Without a verified mapping, I'm hesitant to force arbitrary defaults on users.

And how do you propose we would make such list? (BTW, as a native Czech, I can confirm that the Wikipedia page is correct for Czech, except the alternative quotes (»«) are really archaic, and I saw them used like twice in my life in old books.

reedes commented 7 years ago

As another temporary option you can define a command that'll change a number of settings, as shown in my Lexical plugin...

https://github.com/reedes/vim-lexical/blob/master/README.markdown#define-your-own-commands

mcepl commented 7 years ago

The defaults could be set from &spelllang, but we'd need a good mapping of possible &spelllang values to the corresponding quotes for each language.

Also, what kind of event one should use when the &spelllang is set in the modeline (FileType is too early, isn't it?). Could I do something horrible like:

function! TextObjSettings()
  if &spelllang == 'cs'
     call textobj#quote#init({ 'double':'„“', 'single':'‚‘' })
  elseif &spelllang == 'en'
      call textobj#quote#init({ 'double':'“”', 'single':'‘’' })
  endif
endfunction

autocmd FileType markdown, rst :au InsertEnter :call TextObjSettings()<CR>

(this particularly doesn't work; why?)

Konfekt commented 7 years ago

That's the new OptionSet autocmd that takes hold of settings set in the mode line.

mcepl commented 6 years ago

Note, that OptionSet is not activated on entering the buffer, so one needs as well to add

autocmd OptionSet spelllang call TextObjSettings()
autocmd BufEnter *.rst call TextObjSettings()
alerque commented 2 years ago

I believe this information be derived from Unicode CLDR data, but it will take bit of fiddling. Unless we want to add a Lua dependency (e.g. I could add this data to cldr-lua) the thing to do is probably have an update script that fetches and parses the data and stores it in something cheap to process from viml.

If somebody wants to work on making this configurable so that instead of using a value it calls a function for the desired language, uses the function return value if present, or falls back to a default — then I would help with getting the lang → quotation character map imported.