Skip to content

Commit

Permalink
Allow all forms of method names in New Method (⇧↩)
Browse files Browse the repository at this point in the history
Before we just used the current word which doesn't match all possible method names (self.foo or foo! for instance). Now uses the current_word library to allow any possible method name with the expression taken from the grammar. Fixes #59.
  • Loading branch information
infininight committed Nov 25, 2013
1 parent d2ea9f9 commit da63813
Showing 1 changed file with 33 additions and 11 deletions.
44 changes: 33 additions & 11 deletions Commands/New Method.plist
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!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>
Expand All @@ -9,31 +9,53 @@
require "#{ENV['TM_SUPPORT_PATH']}/lib/exit_codes"
require "#{ENV['TM_SUPPORT_PATH']}/lib/escape"
require "#{ENV['TM_SUPPORT_PATH']}/lib/current_word"
method_name = ENV["TM_SELECTED_TEXT"] || ENV["TM_CURRENT_WORD"] or
TextMate.exit_show_tool_tip(
"Please type the new function's name or use the def⇥ snippet."
)
print &lt;&lt;END_SNIPPET
def #{e_sn method_name}\${1/.+/(/}\${1:args}\${1/.+/)/}
if ENV["TM_SELECTED_TEXT"]
print &lt;&lt;-END_SNIPPET
def #{e_sn ENV["TM_SELECTED_TEXT"]}\${1/.+/(/}\${1:args}\${1/.+/)/}
\$0
end
END_SNIPPET
else
word = Word.current_word(/([?!]?(?:\w(?=[a-zA-Z_]))*[a-zA-Z_](?:(?:\.|::)(?:\w(?=[a-zA-Z_]))*[a-zA-Z_])?)(.*$)/, :hash)
if word[:left].empty?
TextMate.exit_show_tool_tip(
"Please type the new function's name or use the def⇥ snippet."
)
end
indent = word[:before_match].match(/^\s*/)
print &lt;&lt;-END_SNIPPET
#{e_sn word[:before_match]}def #{e_sn word[:left]}\${1/.+/(/}\${1:args}\${1/.+/)/}
#{e_sn indent} \$0
#{e_sn indent}end#{e_sn word[:right]}#{e_sn word[:after_match]}
END_SNIPPET
end
</string>
<key>fallbackInput</key>
<string>word</string>
<string>line</string>
<key>input</key>
<string>selection</string>
<key>inputFormat</key>
<string>text</string>
<key>keyEquivalent</key>
<string>$</string>
<key>name</key>
<string>New Method</string>
<key>output</key>
<string>insertAsSnippet</string>
<key>outputCaret</key>
<string>afterOutput</string>
<key>outputFormat</key>
<string>snippet</string>
<key>outputLocation</key>
<string>replaceInput</string>
<key>scope</key>
<string>source.ruby</string>
<key>uuid</key>
<string>0275EF39-9357-408F-AF20-79E415CA9504</string>
<key>version</key>
<integer>2</integer>
</dict>
</plist>
Expand Down

0 comments on commit da63813

Please sign in to comment.