Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

82 lines (72 sloc) 2.584 kB
<?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 ruby18
proto_re = /
^\s* # Start of the line and optional space
[+-]\s* # a plus or minus for method specifier
\([^)]+\) # the return type in brackets
((?:\n|[^@{])*)
(?m:[\s;]*)
\{
/x
previous_lines = STDIN.readlines[1..ENV['TM_LINE_NUMBER'].to_i - 1]
invocation_line = previous_lines[-1]
proto = previous_lines.join.scan(proto_re)[-1]
exit if proto.nil? or proto.empty?
last_proto_sel_with_types = proto[0].strip.sub(/^\s+/, '').sub(%r{\s*//.*$}, '').gsub(/\n\s*/, ' ')
params = []
params = last_proto_sel_with_types.scan(/(.+?)\s*:\s*\((.+?)\)\s*(\w+)/)
def format_specifier_for_type(type)
case type.gsub(/\s*const\s*/, '')
when /\b(int|bool|BOOL)\b/ then '%d'
when /\b(NSInteger|long)\b/ then '%ld'
when /\b(NSUInteger)\b/ then '%lu'
when /\b(size_t)\b/ then '%zu'
when /\b(ssize_t)\b/ then '%zd'
when /\b(float|double|CGFloat)\b/ then '%f'
when /\b(char\*|string\b)/ then '%s'
when /\b(char)\b/ then '%c'
when /\b(unichar)\b/ then '%C'
else '%@'
end
end
def transformer_for(type, name)
case type
when 'NSRect': "NSStringFromRect(#{name})"
when 'NSRange': "NSStringFromRange(#{name})"
when 'NSPoint': "NSStringFromPoint(#{name})"
when 'NSSize': "NSStringFromSize(#{name})"
when 'SEL': "NSStringFromSelector(#{name})"
when /string/: "#{name}.c_str()"
else name
end
end
print 'NSLog(@"[%@ '
if params.empty?
print last_proto_sel_with_types
else
print params.map { |param, type, name| param + ':' + format_specifier_for_type(type) }.join
end
print ']", [self class]'
print ', ' + params.map { |param, type, name| transformer_for(type, name) }.join(', ') unless params.empty?
print ");"
</string>
<key>input</key>
<string>document</string>
<key>name</key>
<string>Insert NSLog() for Current Method</string>
<key>output</key>
<string>insertAsSnippet</string>
<key>scope</key>
<string>source.objc meta.scope.implementation, source.objc++ meta.scope.implementation</string>
<key>tabTrigger</key>
<string>logm</string>
<key>uuid</key>
<string>C5624A26-E661-46EE-AA6A-14E6B678CFF9</string>
</dict>
</plist>
Jump to Line
Something went wrong with that request. Please try again.