Sublime Forum

How to customize spell check with "spelling_selector" setting

#1

I’m interested in getting the spell check function to ignore code blocks within markdown documents. I attempted to utilize the spelling_selector setting within syntax specific settings, but I’m having trouble understanding the syntax.

The current value is:

"spelling_selector": "markup.raw, source string.quoted - punctuation - meta.preprocessor.include, source comment - source comment.block.preprocessor, -(source, constant, keyword, storage, support, variable, markup.underline.link, meta.tag, text.html.markdown - markup.raw.code-fence)",

I know that I can use ctrl+shift+alt+p to examine the cursor scope which yields:
image

What should I add to the spelling selector setting that would ignore all language code blocks?

0 Likes

#2

To learn more about selectors, please refer to https://www.sublimetext.com/docs/selectors.html.

In short:

rule 1

markup.raw,

… includes all raw blocks, regardless content type

rule 2

source string.quoted - punctuation - meta.preprocessor.include, source comment - source comment.block.preprocessor, 

… includes strings and comments within source code. (That’s an exception for #3)

rule 3

-(source, constant, keyword, storage, support, variable, markup.underline.link, meta.tag)

…excludes everything which looks like source code.

That being said, you’d probably want to remove rule #1 because it enables spell check for all fenced code blocks regardless their scope (source).

If you also want to disable spell checking in comments and strings, remove #2.

0 Likes

#3

Thank you @deathaxe, that was exactly what I was looking for. I had looked at the customization options described in the Spell Checking section but gave up after not seeing any mention of spell_selector on that page. It seems obvious in retrospect that I should have popped down to the general selectors documentation, but it might be worth a cross link to the spell checking page.

For my preference of keeping spell checking on comments within the source blocks, I did a combination of modifying rule 1 and removing part of rule 2. There may have been a better way to do this but I didn’t spend much time further understanding after getting the desired result. If anyone is interested this was my final value:

"spelling_selector": "markup.raw - source, source comment - source comment.block.preprocessor, -(source, constant, keyword, storage, support, variable, markup.underline.link, meta.tag)",
0 Likes