[TxMt] Re: Cocoa Autocomplete

Hans-Joerg Bibiko bibiko at eva.mpg.de
Thu Jan 11 12:23:23 UTC 2007


Dear all,

I don't know whether I can follow the entire discussion but here  
comes my opinion.


First of all I find it quite useful that TM has its own completion  
based on terms occurring in the current document. Actually TM was  
written as an editor to write source code. By writing the name of a  
variable only once I can use the key 'ESC' to complete the name if I  
have to write it again instead of having all English words beginning  
with that I typed.

Nevertheless everybody knows TM is useful for thousand of things.  
Also for writing prose. To use a completion for all English words,  
for instance, you can write such a command very easily by yourself.

Here a fast written first approach in Ruby:

#!/usr/bin/ruby
require File.join(ENV['TM_SUPPORT_PATH'], "lib/exit_codes.rb")
require File.join(ENV['TM_SUPPORT_PATH'], "lib/dialog.rb")
require File.join(ENV['TM_SUPPORT_PATH'], 'lib/current_word.rb')

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

wrds = `cat /usr/share/dict/web2 | grep ^#{word}`

words = wrds.split("\n")
if words.size == 1
   out = words.first
else
   idx = Dialog.menu words
   TextMate.exit_discard if idx.nil?
   out = words[idx]
end

TextMate.exit_discard if words.empty?

print out[word.length..-1]
print " "


What I'm doing here is use the dict file of Webster's dictionary  
which should come out of each Mac OSX release. This file is located  
in /usr/share/dict/web2.

Then I use the system command:

cat /usr/share/dict/web2 | grep ^myword

The output is a list separated by a '\n' of all words beginning with  
'myword'. I put this list into a dialog and then you can select that  
one which you want to insert.

This script can be modified easily to use an other dictionary of course.

If you want to use a non-English dictionary then you have to manage  
the right encoding in beforehand, but this can be discussed later.


Attached is an example command 'AutoComplete' using this script. I  
bound this command to the key APPLE+ESC, but you can change it.

Maybe it helps. (and with this solution Allan hasn't to change TM's  
source code)


Best

-Hans

-------------- next part --------------
A non-text attachment was scrubbed...
Name: AutoComplete.tmCommand
Type: application/octet-stream
Size: 1205 bytes
Desc: not available
URL: <http://lists.macromates.com/textmate/attachments/20070111/38caeec5/attachment.tmCommand>


More information about the textmate mailing list