Skip to content
Find file
117d848 Jun 18, 2014
@ciaran @infininight @joachimm @sorbits
82 lines (72 sloc) 2.52 KB
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
<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
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 '%@'
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
print 'NSLog(@"[%@ '
if params.empty?
print last_proto_sel_with_types
print { |param, type, name| param + ':' + format_specifier_for_type(type) }.join
print ']", [self class]'
print ', ' + { |param, type, name| transformer_for(type, name) }.join(', ') unless params.empty?
print ");"
<string>Insert NSLog() for Current Method</string>
<string>source.objc meta.scope.implementation, source.objc++ meta.scope.implementation</string>
Something went wrong with that request. Please try again.