Spell Checker

12 views
Skip to first unread message

anmar

unread,
Nov 28, 2007, 10:28:45 PM11/28/07
to vim_mac
Hello Guys:

Is the spell checker in MacVim the same as other Cocoa applications.
Meaning does it use Mac OS X dictionary or does it use its own?

Nico Weber

unread,
Nov 29, 2007, 2:49:57 AM11/29/07
to vim...@googlegroups.com
Hi,

> Is the spell checker in MacVim the same as other Cocoa applications.
> Meaning does it use Mac OS X dictionary or does it use its own?

it uses its own :-\

Nico

anmar

unread,
Nov 29, 2007, 2:55:26 AM11/29/07
to vim_mac
Hmm... are you guys planning on it using Mac OS X dictionary instead?

Nico Weber

unread,
Nov 29, 2007, 3:04:21 AM11/29/07
to vim...@googlegroups.com
> Hmm... are you guys planning on it using Mac OS X dictionary instead?

I took a very look at that some time ago. Here are the notes I made:

<notes>
Adding system spell checker to vim on osx
=========================================

Mac OS X includes a spell checker and a grammar checker on os x. It'd
be nice
if one could do `:set spelllang=system` and vim would use the system
spell
checker (in whatever language it's currently supported to run).

Spell suggestions should use the suggestions of the system spell
checker, and
if words are added to the dictionary, they should be added to the
system spell
checker as well.

Vim does its spell checking in `spell.c`, the important function
prototypes
can be found in `proto/spell.pro`.

Cocoa uses `NSSpellChecker`. Carbon apps are expected to write a C
wrapper
around the Cocoa api.

> The `checkSpellingOfString:startingAt:` method checks the spelling
of the
> words in the specified string beginning at the specified offset (this
> example uses 0 to start at the beginning of the string) until it
finds a
> word that is misspelled. Then it returns an `NSRange` to indicate the
> location of the misspelled word.
>
> In a graphical application, whenever a misspelled word is found,
you’ll
> probably want to highlight the word in the document, using the
`NSRange`
> that `checkSpellingOfString:startingAt:` returns to determine the
text to
> highlight. Then you should show the misspelled word in the
Spelling panel’s
> misspelled-word field by calling
`updateSpellingPanelWithMisspelledWord:.`
> If `checkSpellingOfString:startingAt:` does not find a misspelled
word, you
> should call `updateSpellingPanelWithMisspelledWord:` with the empty
string.
> This causes the system to beep, letting the user know that the
spell check
> is complete and no misspelled words were found. None of these steps
is
> required, but if you do one, you should do them all.

It's a bit problematic that `NSSpellChecker` needs `NSString`s...

The main spell checking function in vim is `spell_check()`, which gets a
pointer to a word, sets the highlighting attribute for it and returns
the
number of bytes checked (a word). I'd probably have to set up an
autorelease
pool at the beginning of the function and tear it down again at the end.

When `spelllang` is changed, `did_set_spelllang()` is called.

vim:set tw=78:
</notes>


I guess doing this is possible, but it might be expensive because
every string has to be converted to an NSString before it can be sent
to the spell checker. How expensive this turns out to be depends on
NSString's implementation (I guess it's not too bad). Supporting
grammar checking as well might be a bit harder.

So this is kinda on my todo list, but that doesn't mean it's going to
happen ;-)

Nico

Reply all
Reply to author
Forward
0 new messages