6

(There might be an XY problem in the title, I let you judge.)

The default dictionary for French sets the (ASCII) hyphen - to be a word character, which is the right thing to do. The issue is that French also has some systematic ways of compounding certain words using hyphens¹, and the dictionary doesn’t provide these combinations (there would be really many of them). So a perfectly valid French text raises annoyingly many false positives.

The compounds I’m interested in are of the form XXX-YYY where XXX ranges over all dictionary words (of a certain category: verbs, nouns, etc.) but YYY is a known pattern. So I figured I would use regexes to disable spellchecking on words that end with -YYY, thanks to :syntax match ... contains=@NoSpell:

au Syntax * syn match SuffixedByYYY '\w\+-YYY' containedin=@AllSpell contains=@NoSpell
" (where `AllSpell` is a cluster that lists all matchgroups
" in which I want spelling to be done)

This works, but then the arbitrary string XXX is not spellchecked at all. I want XXX to be spellchecked as a word per se. I tried various things, such as applying contains=@NoSpell only to the suffix -YYY, or applying contains=@Spell only to the prefix XXX… To no avail. Here is an attempt that subsumes other attempts:

au Syntax * syn match SuffixedByYYY
  \ '\w\+-YYY'
  \ keepend
  \ contained
  \ containedin=@AllSpell
  \ contains=@NoSpell,XXX,YYY
au Syntax * syn match XXX '\w\+' keepend contained contains=@Spell
au Syntax * syn match YYY '-YYY' keepend contained contains=@NoSpell

It seems that spellchecking ignores the end of matchgroups: when enabled, it decides what is the next word to be spellchecked by consuming the maximal sequence of word-characters, even if it runs past the current matchgroup. So whatever I try, the whole compound XXX-YYY is signaled as a bad word, regardless of XXX being a good word or not.

Is there anything I can do to spellcheck just XXX in XXX-YYY when - is a word character?

Remark: the problem of spellchecking XXX in YYY-XXX² is simpler and can be achieved like this:

au Syntax * syn match PrefixYYY 'YYY-\(\w\+\)\@=' containedin=@AllSpell contains=@NoSpell

¹: The most notable class of such compounds are conjugated verbs followed by one or several pronouns (e.g. donne-les-moi, “give them to me”). That alone makes up for tens of possible compounds per verb. There are also some adverbs that can be appended to any noun (e.g. ce jour-là, “on that day”). And probably other stuff I can’t think of right now.
²: Which is also useful for French, for elisions (e.g. l'apostrophe or j'aime or qu'a-t-il…).

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.