NEW Swap this to self command

Select some code and use this command to swap out the use of "this" with "self". The command also inserts a "var self = this;" line to the top and removes it when toggling off!
This commit is contained in:
Thomas Aylott
2009-10-05 12:37:00 -04:00
parent 72b2961084
commit 164adcf71f
2 changed files with 41 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!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
code = STDIN.read
if code =~ /\bself\b/
code.gsub!(/(\s*var\s+)?self\s+=\s+this\s*;?\s*$\n?/,'')
code.gsub!(/\bself\b/,'this')
else
code.gsub!(/\bthis\b/,'self')
indent = code.split("\n")[0].match(/^\s*/)[0]
code = "#{indent}var self = this;\n" &lt;&lt; code
end
print code
</string>
<key>fallbackInput</key>
<string>line</string>
<key>input</key>
<string>selection</string>
<key>keyEquivalent</key>
<string>^@S</string>
<key>name</key>
<string>convert this to self</string>
<key>output</key>
<string>replaceSelectedText</string>
<key>scope</key>
<string>source.js</string>
<key>uuid</key>
<string>F035D69A-8987-459C-8425-090752784BC4</string>
</dict>
</plist>
+1
View File
@@ -194,6 +194,7 @@
<string>2831C11D-1907-4BC1-9A4D-BEE70EAFD0CF</string>
<string>ED5F2161-F404-45EA-A8CD-5A4C0CB18DFF</string>
<string>1C062C73-8798-4794-8F4A-223012E42A07</string>
<string>F035D69A-8987-459C-8425-090752784BC4</string>
</array>
<key>uuid</key>
<string>AAB4FD74-73F9-11D9-B89A-000D93589AF6</string>