Skip to content

Commit

Permalink
added content
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Gouessan committed Apr 30, 2012
1 parent 4a0b8f6 commit 0e76250
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Default (Linux).sublime-keymap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
{ "keys": ["alt+ctrl+d"], "command": "xtoy"}
]
3 changes: 3 additions & 0 deletions Default (OSX).sublime-keymap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
{ "keys": ["alt+ctrl+d"], "command": "xtoy"}
]
3 changes: 3 additions & 0 deletions Default (Windows).sublime-keymap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
{ "keys": ["alt+ctrl+d"], "command": "xtoy"}
]
26 changes: 26 additions & 0 deletions XtoY.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import sublime, sublime_plugin, re

class XtoyCommand(sublime_plugin.TextCommand):
def run(self, edit):
for region in self.view.sel():
if region.empty():
line = self.view.line(region)
line_contents = '\n' + self.view.substr(line)
self.view.insert(edit, line.end(), self.replace(line_contents))
else:
self.view.insert(edit, region.end(), self.replace(self.view.substr(region)))

def replace(self, content):
patterns = {
"WIDTH" :"HEIGHT",
"HEIGHT" :"WIDTH",
"X" :"Y",
"Y" :"X",
"width" :"height",
"Width" :"Height",
"Height" :"Width",
"x" :"y",
"y" :"x"
}
regex = re.compile("|".join(map(re.escape, patterns.keys())))
return regex.sub(lambda match: patterns[match.group(0)], content)

0 comments on commit 0e76250

Please sign in to comment.