Skip to content

Instantly share code, notes, and snippets.

@laurent22
Forked from coldnebo/Default (Linux).sublime-keymap
Last active December 13, 2015 18:58

Revisions

  1. laurent22 revised this gist Feb 15, 2013. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions tidy_xml.py
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,8 @@

    class TidyXmlCommand(sublime_plugin.TextCommand):
    def run(self, edit):
    self.view.run_command('select_all')

    command = 'tidy -xml -i -utf8 -w -q'

    # help from http://www.sublimetext.com/forum/viewtopic.php?f=2&p=12451
  2. @coldnebo coldnebo revised this gist Nov 3, 2011. 2 changed files with 20 additions and 3 deletions.
    22 changes: 19 additions & 3 deletions prettify_json.py
    Original file line number Diff line number Diff line change
    @@ -2,11 +2,27 @@

    class PrettifyJsonCommand(sublime_plugin.TextCommand):
    def run(self, edit):
    # requires rubygems json: 'gem install json'
    command = '/local/rvm/bin/rvm exec prettify_json.rb'
    command = 'python -mjson.tool'

    # help from http://www.sublimetext.com/forum/viewtopic.php?f=2&p=12451
    p = subprocess.Popen(command, bufsize=-1, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, shell=True)
    result, err = p.communicate(self.view.substr(self.view.sel()[0]).encode('utf-8'))

    self.view.replace(edit, self.view.sel()[0], result.decode('utf-8'))
    # gave up trying this approach: result always has '\n' strings in it that refuse to render
    #result = json.dumps( self.view.substr(self.view.sel()[0]), indent=2)

    # http://code.activestate.com/recipes/65211/ seems to say that Python "ruins" non-raw strings by
    # actually placing '\','n' in the friggin string unless it's marked 'raw'? Is that true? Shouldn't a string be a string
    # and the raw/not raw output be a function of the runtime? Why does "print" have some magic to reescape these strings and
    # yet there are no other buffer objects that seem to do it (aka StringIO or BytesIO).

    if result != "":
    self.view.replace(edit, self.view.sel()[0], result.decode('utf-8'))
    sublime.set_timeout(self.clear,0)
    else:
    self.view.set_status('tidyjson', "tidyjson: "+err)
    sublime.set_timeout(self.clear,10000)


    def clear(self):
    self.view.erase_status('tidyjson')
    1 change: 1 addition & 0 deletions tidy_xml.py
    Original file line number Diff line number Diff line change
    @@ -13,6 +13,7 @@ def run(self, edit):
    sublime.set_timeout(self.clear,10000)
    else:
    self.view.replace(edit, self.view.sel()[0], result.decode('utf-8'))
    sublime.set_timeout(self.clear,0)


    def clear(self):
  3. @coldnebo coldnebo revised this gist Nov 3, 2011. 1 changed file with 9 additions and 1 deletion.
    10 changes: 9 additions & 1 deletion tidy_xml.py
    Original file line number Diff line number Diff line change
    @@ -8,4 +8,12 @@ def run(self, edit):
    p = subprocess.Popen(command, bufsize=-1, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, shell=True)
    result, err = p.communicate(self.view.substr(self.view.sel()[0]).encode('utf-8'))

    self.view.replace(edit, self.view.sel()[0], result.decode('utf-8'))
    if err != "":
    self.view.set_status('tidyxml', "tidyxml: "+err)
    sublime.set_timeout(self.clear,10000)
    else:
    self.view.replace(edit, self.view.sel()[0], result.decode('utf-8'))


    def clear(self):
    self.view.erase_status('tidyxml')
  4. @coldnebo coldnebo revised this gist Aug 10, 2011. 2 changed files with 23 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions prettify_json.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    import sublime, sublime_plugin, subprocess

    class PrettifyJsonCommand(sublime_plugin.TextCommand):
    def run(self, edit):
    # requires rubygems json: 'gem install json'
    command = '/local/rvm/bin/rvm exec prettify_json.rb'

    # help from http://www.sublimetext.com/forum/viewtopic.php?f=2&p=12451
    p = subprocess.Popen(command, bufsize=-1, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, shell=True)
    result, err = p.communicate(self.view.substr(self.view.sel()[0]).encode('utf-8'))

    self.view.replace(edit, self.view.sel()[0], result.decode('utf-8'))
    11 changes: 11 additions & 0 deletions tidy_xml.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    import sublime, sublime_plugin, subprocess

    class TidyXmlCommand(sublime_plugin.TextCommand):
    def run(self, edit):
    command = 'tidy -xml -i -utf8 -w -q'

    # help from http://www.sublimetext.com/forum/viewtopic.php?f=2&p=12451
    p = subprocess.Popen(command, bufsize=-1, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, shell=True)
    result, err = p.communicate(self.view.substr(self.view.sel()[0]).encode('utf-8'))

    self.view.replace(edit, self.view.sel()[0], result.decode('utf-8'))
  5. @coldnebo coldnebo created this gist Aug 10, 2011.
    4 changes: 4 additions & 0 deletions Default (Linux).sublime-keymap
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    [
    { "keys": ["ctrl+shift+x"], "command": "tidy_xml" },
    { "keys": ["ctrl+shift+j"], "command": "prettify_json" }
    ]