[TxMt] Re: LaTeX Bundle

Alain Matthes alain.matthes at mac.com
Sun Dec 6 16:02:19 UTC 2009


Le 6 déc. 2009 à 02:09, Alex Ross a écrit :

> Hey Alain,
> 
> I modified you command as follows:
> 
>> #!/usr/bin/env ruby
>> 
>> require "#{ENV['TM_SUPPORT_PATH']}/lib/exit_codes"
>> require "#{ENV['TM_BUNDLE_SUPPORT']}/lib/config_helper.rb"
>> 
>> symbols = Config.load['symbols']
>> word = STDIN.read
>> 
>> if symbols.has_key? word and not ENV['TM_SCOPE'].match(/math/)
>>  print "\\\$#{symbols[word]}$0\\\$"
>> else
>>  TextMate.exit_discard
>> end
> 
> If you have any questions about the semantics feel free to ask.

@Caius thanks for your remarks

@Hans The code

#!/usr/bin/env ruby

require "#{ENV['TM_SUPPORT_PATH']}/lib/exit_codes"
require "#{ENV['TM_BUNDLE_SUPPORT']}/lib/config_helper.rb"

symbols = Config.load['symbols']
word = STDIN.read

if symbols.has_key? word and not ENV['TM_SCOPE'].match(/math/)
 print "\\\$#{symbols[word]}$0\\\$"
else
 TextMate.exit_discard
end 

 does not work.

If I use Replace Selected Text and § for the shortcut

a§ gives \$\alpha$0\$   

and $ a§ $ gives nothing 


Now if I use insert as snippet,I get \alpha and not $\alpha$

If found a solution with 

#!/usr/bin/env ruby
require "#{ENV['TM_SUPPORT_PATH']}/lib/exit_codes"
require "#{ENV['TM_BUNDLE_SUPPORT']}/lib/config_helper.rb"
shortcutHash =  Config.load['symbols']
currentWord = STDIN.read

if (shortcutHash.has_key?(currentWord)) then
currentWord = shortcutHash[currentWord]
currentWord = "\\\$#{currentWord}$0\\\$" unless ENV['TM_SCOPE'].match(/math/)
TextMate.exit_insert_snippet currentWord else
TextMate.exit_discard
end 

I use Replace Selected Text and TextMate.exit_insert_snippet instead of puts and print
but perhaps it's possible to simplify.

Now a§ ---> $\alpha $ and $\alpha + b§ $ -->$\alpha + \beta$

The command works but I  understand  only  little things.
I found TextMate.exit_insert_snippet in another command and I make a try

For example, why in some macros we have

@plist = Config.load
shortcuts = @plist['commands']

if it's possible to write    shortcuts = Config.load['commands']

Best regards

Alain Matthes






More information about the textmate mailing list