[TxMt] Re: Cocoa Autocomplete

Adam R. Maxwell amaxwell at mac.com
Fri Jan 12 01:23:26 UTC 2007


 
On Thursday, January 11, 2007, at 03:08PM, "Hans-Jörg Bibiko" <bibiko at eva.mpg.de> wrote:
>>> If, however, there was a way to interface with the Cocoa  
>>> "complete:", then it would solve these problems. Perhaps there may  
>>> be a way of doing this using an AppleScript.
>>
>> I think you could write a Foundation command-line tool that calls  
>> [[NSSpellChecker sharedSpellChecker]  
>> completionsForPartialWordRange:inString:language:inSpellDocumentWithTa 
>> g:] and provides its results via tm_dialog.  I did a similar thing  
>> in writing a tool that asks BibDesk for citation completions, and  
>> it works pretty well.
>
>Well, that's a good idea, but I have a small problem with that.
>
>The function
>
>[[NSSpellChecker sharedSpellChecker]  
>completionsForPartialWordRange:inString:language:inSpellDocumentWithTag: 
>]
>
>needs a inSpellDocumentWithTag and a language.
>
>But, there is a problem. I invoke this command by writing a tmCommand  
>which calls BASH. The used NSSpellChecker has no info about TM's  
>spelling language and there's also no unique inSpellDocumentWithTag.
>In other words you loose the nice feature of having a ranked output  
>and you have to set the language by yourself.

Not sure what you mean by "ranked output", but yes, you would have to pass the appropriate language setting as an argument.  For the tag, I think you should use [NSSpellChecker uniqueSpellDocumentTag] instead of passing 0, but it may not matter; it's not clear to me if you should use closeSpellDocumentWithTag: when done.

>I don't know whether I'm right, but I believe that NSSpellChecker can  
>only invoke inside of TM or, maybe, by putting it into a tmPlugin to  
>get this nice feature.

Sure, there are numerous features of the spelling system that won't be integrated correctly unless it's in the application, and maybe a tmPlugin would solve that.  I was just suggesting a possible way for someone to get dictionary completions.

>Here is my humble test script 'a.m':
>
>#import <AppKit/AppKit.h>

[...]

Interesting...did you need [NSApplication sharedApplication]?

>You can replace this command within the Ruby script.
>Hint: This code (Ruby) is not utf-8 save!

If you're referring to my example, I borrowed the Ruby script from elsewhere in TextMate.  What part of it isn't UTF-8 safe?

-- Adam



More information about the textmate mailing list