[TxMt] Spell checking using Google

Allan Odgaard throw-away-1 at macromates.com
Tue May 1 01:52:09 UTC 2007

On 1. May 2007, at 01:10, Hans-Jörg Bibiko wrote:

>> On the other hand I have a problem with '\n\n' in the text.
> OK. I solved this problem by replacing '\n' with a Japanese space ;)
> An other problem arose with many spaces '     '. I also solved it  
> with a Japanese character ;)

Attached is my take on it (based on yours and Andy’s code).

I use the offset and length given back by Google to figure out where  
the corrections should go.

Google seems to a) give the count in “code points” (regardless of  
encoding) and b) collapse all successive whitespace into one  
character. Here is the helper I use to adjust for that:

   def substr(str, idx, len = 10000)
     $1 if str =~ /^(?:\s+|.){#{idx}}((?:\s+|.){0,#{len}})/m

When Google returns multiple suggestions, the command will show a  
menu, with the original word at the top. It does this for every  
misspelled word in the text. When there is only one suggestion, the  
command uses that, and makes the word a tab-stop.

Personally I think the menu is generally not wanted, so that part  
should probably be removed (and the first suggestion should always be  

I gave it a key equivalent of ⌥⇧F2 which is analogous with ⌥F2  
for the regular context menu (which has spelling suggestions).

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Google Spell Check Selection : Word.tmCommand
Type: application/octet-stream
Size: 2669 bytes
Desc: not available
URL: <http://lists.macromates.com/textmate/attachments/20070501/6cffd474/attachment.tmCommand>
-------------- next part --------------

More information about the textmate mailing list