/
Paste Implementation : Interface.tmCommand
74 lines (66 loc) · 2.15 KB
/
Paste Implementation : Interface.tmCommand
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?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 -wKU
#
# Possible improvements:
# • Preserve empty lines between methods taken from the clipboard
# • Make the “parser” conform to the actual Objective-C spec
#
require ENV['TM_SUPPORT_PATH'] + '/lib/exit_codes'
methods = []
%x{ pbpaste }.scan(/^
\s*
([-+]) # Class or object method
(\s* \( ([^\)]+) \))? # Optional return type
(\s* [a-z0-9_]+) # Method name
# Zero or more parameters:
( (\s* [a-z0-9_]*) # Optional name of parameter
: # Mandatory colon
(\s* \( [^\)]+ \))? # Optional type of parameter
(\s* [a-z0-9_]+) # Parameter name (might be optional)
(\s* , \s* ...)? # Optional var-args notation
)*
(?=\s* ;?) # Optional semicolon
/ix) do
rettype = $3.to_s.strip
methods << [$&.strip.gsub(' *)', (ENV['TM_C_POINTER'] || ' *').rstrip + ')'), rettype]
end
TextMate::exit_show_tool_tip('No methods found on the clipboard') if methods.empty?
if ENV['TM_SCOPE'] !~ /meta.implementation.objc/
methods.each { |(proto, rettype)| puts "#{proto};" }
else
tabstop = 0
puts(methods.map do |(proto, rettype)|
ret = case rettype
when "void", "IBAction"
""
when "BOOL"
"\treturn ${#{tabstop+=1}:Y}${1/^(?:(Y)|(N)|.*)/(?1:ES:(?2:O))/};\n"
else
"\treturn ${#{tabstop+=1}:nil};\n"
end
"#{proto}\n{\n#{ret}}\n"
end.join("\n"))
end
</string>
<key>fallbackInput</key>
<string>line</string>
<key>input</key>
<string>none</string>
<key>keyEquivalent</key>
<string>^V</string>
<key>name</key>
<string>Paste Implementation / Interface</string>
<key>output</key>
<string>insertAsSnippet</string>
<key>scope</key>
<string>meta.interface-or-protocol.objc, meta.implementation.objc</string>
<key>uuid</key>
<string>CB5EC7EC-35B7-4FD8-9045-31CCC379D474</string>
</dict>
</plist>