Skip to content
Browse files

Improve by using Python to reformat.

Fixes #1, #3
  • Loading branch information...
1 parent c7f2f58 commit fbb2dcd2668338b4d3df61dce51d902138cd4733 @infininight infininight committed Nov 13, 2011
Showing with 3 additions and 49 deletions.
  1. +3 −49 Commands/Reformat Document : Selection.tmCommand
View
52 Commands/Reformat Document : Selection.tmCommand
@@ -1,60 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<!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
-require 'strscan'
-def indent
- " " * $indent * 4
-end
-
-s = StringScanner.new(STDIN.read)
-brace_stack = []
-comma_needed = false
-first_line = true
-$indent = 0
-until s.eos?
- if s.scan(/\{/m)
- if comma_needed then puts "," else puts end
- comma_needed = false
- print indent + "{"
- first_line = false
- $indent += 1
- brace_stack.push "{"
- elsif s.scan(/\}/m)
- $indent -= 1
- print "\n" + indent + "}"
- if (b = brace_stack.pop) != "{"
- puts "Expected '}' (#{brace_stack.inspect} / #{b})"
- exit -1
- end
- elsif s.scan(/\[/m)
- if comma_needed then puts "," else puts end
- comma_needed = false
- print indent + "["
- $indent += 1
- brace_stack.push "["
- elsif s.scan(/\]/m)
- $indent -= 1
- print "\n" + indent + "]"
- if (b = brace_stack.pop) != "["
- puts "Expected ']' (#{brace_stack.inspect} / #{b})"
- exit -2
- end
- elsif s.scan(/,/m)
- comma_needed = true
- #print "==#{brace_stack.inspect}=="
- #puts (brace_stack.last == "{" ? "" : indent) + ","
- else
- if comma_needed then puts "," else puts end
- comma_needed = false
- print indent + s.scan(/[^{}\[\],]+/m)
- end
-end</string>
+puts `python -m json.tool`
+</string>
<key>input</key>
<string>selection</string>
<key>keyEquivalent</key>

0 comments on commit fbb2dcd

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