mirror of
https://github.com/kennethreitz-archive/kJS.tmbundle.git
synced 2026-06-05 23:50:19 +00:00
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:
@@ -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" << 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>
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user