From a7a47fb7375ca0d87a007f3ca8684259260141ce Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Mon, 30 Jun 2008 20:58:52 +0000 Subject: [PATCH] Thrift: Add enum snippet and accompanying enum field macro git-svn-id: http://svn.textmate.org/trunk/Bundles/Thrift.tmbundle@10084 dfb7d73b-c2ec-0310-8fea-fb051d288c6d --- Commands/enum field.tmCommand | 38 ++++++++++++++++++++ Commands/struct field.tmCommand | 7 +++- Macros/enum field.tmMacro | 62 +++++++++++++++++++++++++++++++++ Macros/struct field.tmMacro | 18 ++++++++-- Snippets/enum.tmSnippet | 18 ++++++++++ info.plist | 10 ++++-- 6 files changed, 148 insertions(+), 5 deletions(-) create mode 100644 Commands/enum field.tmCommand create mode 100644 Macros/enum field.tmMacro create mode 100644 Snippets/enum.tmSnippet diff --git a/Commands/enum field.tmCommand b/Commands/enum field.tmCommand new file mode 100644 index 0000000..89ddcde --- /dev/null +++ b/Commands/enum field.tmCommand @@ -0,0 +1,38 @@ + + + + + beforeRunningCommand + nop + command + #!/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" + + fallbackInput + line + input + none + name + enum field + output + insertAsSnippet + scope + meta.enum.thrift + uuid + 841E598E-C872-4A98-A4D5-F13272F51B6F + + diff --git a/Commands/struct field.tmCommand b/Commands/struct field.tmCommand index c60e2ee..7e44d9c 100644 --- a/Commands/struct field.tmCommand +++ b/Commands/struct field.tmCommand @@ -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" fallbackInput line diff --git a/Macros/enum field.tmMacro b/Macros/enum field.tmMacro new file mode 100644 index 0000000..3b695e6 --- /dev/null +++ b/Macros/enum field.tmMacro @@ -0,0 +1,62 @@ + + + + + commands + + + command + moveToEndOfParagraph: + + + argument + + beforeRunningCommand + nop + command + #!/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" + + fallbackInput + line + input + none + keyEquivalent +  + name + enum field + output + insertAsSnippet + scope + meta.enum.thrift + uuid + 841E598E-C872-4A98-A4D5-F13272F51B6F + + command + executeCommandWithOptions: + + + keyEquivalent +  + name + enum field + scope + meta.enum.thrift + uuid + C334A09A-D090-4EC1-AD14-23FB9AF4D287 + + diff --git a/Macros/struct field.tmMacro b/Macros/struct field.tmMacro index 2e6f611..a93735a 100644 --- a/Macros/struct field.tmMacro +++ b/Macros/struct field.tmMacro @@ -16,20 +16,34 @@ command #!/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" fallbackInput line input none + name + struct field output insertAsSnippet + scope + meta.struct.thrift + uuid + 9240E318-0643-4BF7-8EBA-DD947C8CB7B9 command executeCommandWithOptions: @@ -42,6 +56,6 @@ print "${1:#{i}}${1/.+/: /m}${2:i32} ${3:field}${4/.+/ = /m}${4:value},$0" scope meta.struct.thrift uuid - ED84802A-BD69-4810-9F0B-547A9DA70033 + 908FD647-26E2-4A8E-BBC9-084233EFA5B7 diff --git a/Snippets/enum.tmSnippet b/Snippets/enum.tmSnippet new file mode 100644 index 0000000..3e7306b --- /dev/null +++ b/Snippets/enum.tmSnippet @@ -0,0 +1,18 @@ + + + + + content + enum ${1:Name} { + ${2:FIELD} = ${3:1},$0 +} + name + enum + scope + source.thrift -meta + tabTrigger + enu + uuid + C1341136-77B4-433A-A17D-C0ECE06A3402 + + diff --git a/info.plist b/info.plist index 4639e25..6100cd7 100644 --- a/info.plist +++ b/info.plist @@ -12,12 +12,15 @@ excludedItems + 841E598E-C872-4A98-A4D5-F13272F51B6F 9240E318-0643-4BF7-8EBA-DD947C8CB7B9 - ED84802A-BD69-4810-9F0B-547A9DA70033 + 908FD647-26E2-4A8E-BBC9-084233EFA5B7 + C334A09A-D090-4EC1-AD14-23FB9AF4D287 items FA5FBCA2-12D6-4C3B-A9A0-5B9C9AD141AD + C1341136-77B4-433A-A17D-C0ECE06A3402 submenus @@ -26,10 +29,13 @@ Thrift ordering - ED84802A-BD69-4810-9F0B-547A9DA70033 9E5704AC-54ED-4D7C-946C-6DC3727BDC4C FA5FBCA2-12D6-4C3B-A9A0-5B9C9AD141AD + 908FD647-26E2-4A8E-BBC9-084233EFA5B7 9240E318-0643-4BF7-8EBA-DD947C8CB7B9 + C1341136-77B4-433A-A17D-C0ECE06A3402 + C334A09A-D090-4EC1-AD14-23FB9AF4D287 + 841E598E-C872-4A98-A4D5-F13272F51B6F uuid 503C9BCE-892F-420D-86B5-B6B8E34F6742