Skip to content
Browse files

Improved insertion based on current context.

  • Loading branch information...
1 parent c2ab88c commit b2a91b5a134a7368255c2b7bfcc52e1760eb5554 @infininight infininight committed Oct 5, 2011
Showing with 12 additions and 3 deletions.
  1. +12 −3 Commands/Wrap in Braces.tmCommand
View
15 Commands/Wrap in Braces.tmCommand
@@ -6,6 +6,7 @@
<string>nop</string>
<key>command</key>
<string>#!/usr/bin/env ruby -wKU
+require "pp"
def indent(text)
text.split(/\n/).collect { |str| $&amp; if str =~ /^\s*/ }.reject { |e| e == "" }.min { |a, b| a.length &lt;=&gt; b.length }
@@ -17,7 +18,7 @@ end
code = STDIN.read
-if code =~ /\n/ then
+if code =~ /\n/ &amp;&amp; ENV['TM_INPUT_START_LINE_INDEX'].to_i == 0 then
STDOUT &lt;&lt; indent(code) &lt;&lt; "{\n"
STDOUT &lt;&lt; code.gsub(/^(?=.)/, "#{tab}")
STDOUT &lt;&lt; indent(code) &lt;&lt; "}\n"
@@ -27,15 +28,23 @@ end
</string>
<key>input</key>
<string>selection</string>
+ <key>inputFormat</key>
+ <string>text</string>
<key>keyEquivalent</key>
<string>{</string>
<key>name</key>
<string>Wrap in Braces</string>
- <key>output</key>
- <string>replaceSelectedText</string>
+ <key>outputCaret</key>
+ <string>heuristic</string>
+ <key>outputFormat</key>
+ <string>text</string>
+ <key>outputLocation</key>
+ <string>replaceInput</string>
<key>scope</key>
<string>source &amp; dyn.selection.continuous</string>
<key>uuid</key>
<string>52DA9EF9-6D1A-4E55-BFB9-BCB85C250715</string>
+ <key>version</key>
+ <integer>2</integer>
</dict>
</plist>

0 comments on commit b2a91b5

Please sign in to comment.
Something went wrong with that request. Please try again.