Skip to content

Commit

Permalink
Thrift: Add enum snippet and accompanying enum field macro
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.textmate.org/trunk/Bundles/Thrift.tmbundle@10084 dfb7d73b-c2ec-0310-8fea-fb051d288c6d
  • Loading branch information
lilyball committed Jun 30, 2008
1 parent 111a13c commit a7a47fb
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 5 deletions.
38 changes: 38 additions & 0 deletions Commands/enum field.tmCommand
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>nop</string>
<key>command</key>
<string>#!/usr/bin/env ruby
if ENV['TM_CURRENT_LINE'] =~ /^\s*[\w.]+\s*=\s*(\d+)\s*[,;]?\s*$/
idx = $1.to_i + 1
else
idx = 1
end
if ENV['TM_CURRENT_LINE'] =~ /^\s+/
indent = ''
else
indent = "\t"
end
puts
print "#{indent}${1:FIELD} = ${2:#{idx}},$0"
</string>
<key>fallbackInput</key>
<string>line</string>
<key>input</key>
<string>none</string>
<key>name</key>
<string>enum field</string>
<key>output</key>
<string>insertAsSnippet</string>
<key>scope</key>
<string>meta.enum.thrift</string>
<key>uuid</key>
<string>841E598E-C872-4A98-A4D5-F13272F51B6F</string>
</dict>
</plist>
7 changes: 6 additions & 1 deletion Commands/struct field.tmCommand
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ if ENV['TM_CURRENT_LINE'] =~ /^\s*(\d+):/
i = $1.to_i + 1
end
indent = ''
if ENV['TM_CURRENT_LINE'] !~ /^\s+/
indent = "\t"
end
puts
print "${1:#{i}}${1/.+/: /m}${2:i32} ${3:field}${4/.+/ = /m}${4:value},$0"
print "#{indent}${1:#{i}}${1/.+/: /m}${2:i32} ${3:field}${4/.+/ = /m}${4:value},$0"
</string>
<key>fallbackInput</key>
<string>line</string>
Expand Down
62 changes: 62 additions & 0 deletions Macros/enum field.tmMacro
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>commands</key>
<array>
<dict>
<key>command</key>
<string>moveToEndOfParagraph:</string>
</dict>
<dict>
<key>argument</key>
<dict>
<key>beforeRunningCommand</key>
<string>nop</string>
<key>command</key>
<string>#!/usr/bin/env ruby

if ENV['TM_CURRENT_LINE'] =~ /^\s*[\w.]+\s*=\s*(\d+)\s*[,;]?\s*$/
idx = $1.to_i + 1
else
idx = 1
end

if ENV['TM_CURRENT_LINE'] =~ /^\s+/
indent = ''
else
indent = "\t"
end

puts
print "#{indent}${1:FIELD} = ${2:#{idx}},$0"
</string>
<key>fallbackInput</key>
<string>line</string>
<key>input</key>
<string>none</string>
<key>keyEquivalent</key>
<string></string>
<key>name</key>
<string>enum field</string>
<key>output</key>
<string>insertAsSnippet</string>
<key>scope</key>
<string>meta.enum.thrift</string>
<key>uuid</key>
<string>841E598E-C872-4A98-A4D5-F13272F51B6F</string>
</dict>
<key>command</key>
<string>executeCommandWithOptions:</string>
</dict>
</array>
<key>keyEquivalent</key>
<string></string>
<key>name</key>
<string>enum field</string>
<key>scope</key>
<string>meta.enum.thrift</string>
<key>uuid</key>
<string>C334A09A-D090-4EC1-AD14-23FB9AF4D287</string>
</dict>
</plist>
18 changes: 16 additions & 2 deletions Macros/struct field.tmMacro
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,34 @@
<key>command</key>
<string>#!/usr/bin/env ruby

# this command is intended to be used to generate the struct field macro
# the struct field macro is ^E followed by this command.

i = 1
if ENV['TM_CURRENT_LINE'] =~ /^\s*(\d+):/
i = $1.to_i + 1
end

indent = ''
if ENV['TM_CURRENT_LINE'] !~ /^\s+/
indent = "\t"
end

puts
print "${1:#{i}}${1/.+/: /m}${2:i32} ${3:field}${4/.+/ = /m}${4:value},$0"
print "#{indent}${1:#{i}}${1/.+/: /m}${2:i32} ${3:field}${4/.+/ = /m}${4:value},$0"
</string>
<key>fallbackInput</key>
<string>line</string>
<key>input</key>
<string>none</string>
<key>name</key>
<string>struct field</string>
<key>output</key>
<string>insertAsSnippet</string>
<key>scope</key>
<string>meta.struct.thrift</string>
<key>uuid</key>
<string>9240E318-0643-4BF7-8EBA-DD947C8CB7B9</string>
</dict>
<key>command</key>
<string>executeCommandWithOptions:</string>
Expand All @@ -42,6 +56,6 @@ print "${1:#{i}}${1/.+/: /m}${2:i32} ${3:field}${4/.+/ = /m}${4:value},$0"
<key>scope</key>
<string>meta.struct.thrift</string>
<key>uuid</key>
<string>ED84802A-BD69-4810-9F0B-547A9DA70033</string>
<string>908FD647-26E2-4A8E-BBC9-084233EFA5B7</string>
</dict>
</plist>
18 changes: 18 additions & 0 deletions Snippets/enum.tmSnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>content</key>
<string>enum ${1:Name} {
${2:FIELD} = ${3:1},$0
}</string>
<key>name</key>
<string>enum</string>
<key>scope</key>
<string>source.thrift -meta</string>
<key>tabTrigger</key>
<string>enu</string>
<key>uuid</key>
<string>C1341136-77B4-433A-A17D-C0ECE06A3402</string>
</dict>
</plist>
10 changes: 8 additions & 2 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
<dict>
<key>excludedItems</key>
<array>
<string>841E598E-C872-4A98-A4D5-F13272F51B6F</string>
<string>9240E318-0643-4BF7-8EBA-DD947C8CB7B9</string>
<string>ED84802A-BD69-4810-9F0B-547A9DA70033</string>
<string>908FD647-26E2-4A8E-BBC9-084233EFA5B7</string>
<string>C334A09A-D090-4EC1-AD14-23FB9AF4D287</string>
</array>
<key>items</key>
<array>
<string>FA5FBCA2-12D6-4C3B-A9A0-5B9C9AD141AD</string>
<string>C1341136-77B4-433A-A17D-C0ECE06A3402</string>
</array>
<key>submenus</key>
<dict/>
Expand All @@ -26,10 +29,13 @@
<string>Thrift</string>
<key>ordering</key>
<array>
<string>ED84802A-BD69-4810-9F0B-547A9DA70033</string>
<string>9E5704AC-54ED-4D7C-946C-6DC3727BDC4C</string>
<string>FA5FBCA2-12D6-4C3B-A9A0-5B9C9AD141AD</string>
<string>908FD647-26E2-4A8E-BBC9-084233EFA5B7</string>
<string>9240E318-0643-4BF7-8EBA-DD947C8CB7B9</string>
<string>C1341136-77B4-433A-A17D-C0ECE06A3402</string>
<string>C334A09A-D090-4EC1-AD14-23FB9AF4D287</string>
<string>841E598E-C872-4A98-A4D5-F13272F51B6F</string>
</array>
<key>uuid</key>
<string>503C9BCE-892F-420D-86B5-B6B8E34F6742</string>
Expand Down

0 comments on commit a7a47fb

Please sign in to comment.