Sha256: 11e227747552a8f923d03b64dd1f894686d52a568e1536b3af26f7bcf2ec7cb3

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

# Encoding: UTF-8

[{beforeRunningCommand: "nop",
  command: 
   "#!/usr/bin/env ruby\nrequire 'strscan'\n\ndef indent\n  \" \" * $indent * 4\nend\n\ns = StringScanner.new(STDIN.read)\nbrace_stack = []\ncomma_needed = false\nfirst_line = true\n$indent = 0\nuntil s.eos?\n  if s.scan(/\\{/m)\n    if comma_needed then puts \",\" else puts end\n    comma_needed = false\n    print indent + \"{\"\n    first_line = false\n    $indent += 1\n    brace_stack.push \"{\"\n  elsif s.scan(/\\}/m)\n    $indent -= 1\n    print \"\\n\" + indent + \"}\"\n    if (b = brace_stack.pop) != \"{\"\n      puts \"Expected '}' (\#{brace_stack.inspect} / \#{b})\"\n      exit -1\n    end\n  elsif s.scan(/\\[/m)\n    if comma_needed then puts \",\" else puts end\n    comma_needed = false\n    print indent + \"[\"\n    $indent += 1\n    brace_stack.push \"[\"\n  elsif s.scan(/\\]/m)\n    $indent -= 1\n    print \"\\n\" + indent + \"]\"\n    if (b = brace_stack.pop) != \"[\"\n      puts \"Expected ']' (\#{brace_stack.inspect} / \#{b})\"\n      exit -2\n    end\n  elsif s.scan(/,/m)\n    comma_needed = true\n    #print \"==\#{brace_stack.inspect}==\"\n    #puts (brace_stack.last == \"{\" ? \"\" : indent) + \",\"\n  else\n    if comma_needed then puts \",\" else puts end\n    comma_needed = false\n    print indent + s.scan(/[^{}\\[\\],]+/m)\n  end\nend",
  input: "selection",
  keyEquivalent: "^H",
  name: "Reformat Document / Selection",
  output: "replaceSelectedText",
  scope: "source.json",
  uuid: "4B74F2DE-E051-4E8D-9124-EBD90A2CDD2B"}]

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ver-2010.08 config/commands/JSON.rb