vim-textobj-quote icon indicating copy to clipboard operation
vim-textobj-quote copied to clipboard

adapt educate to &spelllang

Open Konfekt opened this issue 11 years ago • 8 comments

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.

Konfekt avatar Apr 10 '14 10:04 Konfekt

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.

reedes avatar Apr 10 '14 18:04 reedes

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.

Konfekt avatar Apr 12 '14 08:04 Konfekt

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.

mcepl avatar Jan 11 '17 11:01 mcepl

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

reedes avatar Jan 12 '17 00:01 reedes

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?)

mcepl avatar Jun 16 '17 11:06 mcepl

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

Konfekt avatar Jun 16 '17 11:06 Konfekt

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()

mcepl avatar Jan 18 '18 15:01 mcepl

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.

alerque avatar Feb 11 '22 16:02 alerque