[TxMt] Re: Cocoa Autocomplete

Hans-Joerg Bibiko bibiko at eva.mpg.de
Fri Jan 12 09:20:18 UTC 2007


Hi,

>> 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.
>

By 'ranked output' I meant the following:
If I type, for instance, 'beef' and call the autocompete function. It  
will list:
beef
beef's
beefcake
beefcake's
....

Then I choose 'beefsteak'. After writing further stuff I type 'beef'  
again and call autocomplete. Now it will list:
beefsteak
beef
beef's
beefcake
...

'beefsteak' will listed at the top because NSSpellChecker remembers  
my last choice. And this is done via an unique inSpellDocumentWithTag.

If I write in 'a.m':

int utag = [NSSpellChecker uniqueSpellDocumentTag]

it causes an error because the program is started outside of a cocoa  
application; and there is no SpellDocument referring to.
Furthermore if the a.out is executed the NSSpellChecker is also  
closed, so there is no way to memorise my choices. (?)

I have no idea to pass the tag and language info from TM to a.out!

The same for language: If I type language:nil NSSpellChecker takes  
the language which is set in the document. But there is no document  
for a.out.

>> 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]?

Well, I don't know. If I leave it out the program doesn't run.

>
>> 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?
>

I tried it out with language "de". I wrote 'Vermö' but nothing  
returns because the Ruby line:

word = Word.current_word(/\w./)

interprets the 'ö' as word boundary. If I type 'Vermög' it lists all  
words beginning with 'g'.

If I use TM directly and type

/PATH/TO/a.out "Vermö" "de"

it works perfectly.

To solve this problem you have to write within the Ruby script  
instead of

word = Word.current_word(/\w./)

word = `cat`

and set the input behaviour of the command to 'Selection' or 'Word'

###########

I don't know but it seems to me that the easiest way to use this  
functionality is to wait for Allan. I guess to implement this in TM  
directly is the cleanest way (?)

Cheers,

Hans






More information about the textmate mailing list