* Start again the textmate snippet importations, with better

textmate_import.rb and yasnippet.el
This commit is contained in:
capitaomorte
2010-04-01 11:41:19 +00:00
parent 6b07c4b1d6
commit 5d9f7fb6b4
939 changed files with 0 additions and 7031 deletions

View File

@@ -1,58 +0,0 @@
;;; constants
(defvar yas/objc-void-regexp "\\(void\\|IBAction\\)")
;;; helper stuff
(defun yas/objc-guess-instance-name (text)
(if (string-match "NS\\(\\([AEIOQUY]\\)?[^ *]*\\)" text)
(if (match-beginning 2)
(concat "an" (capitalize (match-string-no-properties 1 text)))
(concat "a" (capitalize (match-string-no-properties 1 text))))
"arg"))
(defun yas/objc-guess-member-name (text)
"Turns FOOBARBaz to baz"
(let ((case-fold-search nil))
(if (string-match "[A-Z]+\\([A-Z]\\)\\(.*\\)" text)
(concat (downcase (match-string-no-properties 1 text))
(match-string-no-properties 2 text))
text)))
;;; cached conditions
(yas/define-condition-cache
yas/objc-interface-p
"Non-nil if point inside an objc @interface declaration."
(yas/objc-in-c-block-like "@interface"))
(yas/define-condition-cache
yas/objc-implementation-p
"Non-nil if point inside an objc @implementation declaration."
(yas/objc-in-c-block-like "@implementation"))
(yas/define-condition-cache
yas/objc-method-body-p
"Non-nil if point inside an objc method definition."
(yas/objc-in-c-block-like 'objc-method-intro))
;;; helpers for cached conditions
(defun yas/objc-in-c-block-like (symbol-or-regexp)
(let ((original-point (point))
(start-point nil))
(save-excursion
(cond ((symbolp symbol-or-regexp)
(c-beginning-of-defun)
(setq start-point (point))
(let ((syntax-info (c-guess-basic-syntax)))
(when (and syntax-info
(eq (caar syntax-info) symbol-or-regexp))
(c-end-of-defun)
(and (< start-point original-point)
(< original-point (point))))))
((stringp symbol-or-regexp)
(when (search-backward-regexp symbol-or-regexp
nil
t)
(setq start-point (point))
(when (search-forward-regexp "^@end" nil t)
(and (< start-point original-point)
(< original-point (point))))))))))

View File

@@ -1,17 +0,0 @@
# -*- mode: snippet -*-
# key: objacc
# contributor: Translated from TextMate Snippet
# name: Object
## condition: "(source.objc | source.objc++) & meta.scope.implementation.objc - meta.function-with-body"
# --
- (${1:id})${2:thing}
{
return $2;
}
- (void)set${2/./\u$0/}:($1)aValue
{
$0${1/( \*)?$/(?1:$1: )/}old${2/./\u$0/} = $2;
$2 = [aValue retain];
[old${2/./\u$0/} release];
}

View File

@@ -1,20 +0,0 @@
# -*- mode: snippet -*-
# key: cdacc
# contributor: Translated from TextMate Snippet
# name: CoreData
## condition: "source.objc, source.objc++"
# --
- (${1:id})${2:attribute}
{
[self willAccessValueForKey:@"${2: attribute}"];
${1:id} value = [self primitiveValueForKey:@"${2: attribute}"];
[self didAccessValueForKey:@"${2: attribute}"];
return value;
}
- (void)set${2/./\u$0/}:($1)aValue
{
[self willChangeValueForKey:@"${2: attribute}"];
[self setPrimitiveValue:aValue forKey:@"${2: attribute}"];
[self didChangeValueForKey:@"${2: attribute}"];
}

View File

@@ -1,45 +0,0 @@
# -*- mode: snippet -*-
# key: arracc
# contributor: Translated from TextMate Snippet
# name: KVC Array
## condition: "(source.objc | source.objc++) & meta.scope.implementation.objc - meta.function-with-body"
# --
- (void)addObjectTo${1:Things}:(${2:id})anObject
{
[${3:${1/./\l$0/}} addObject:anObject];
}
- (void)insertObject:($2)anObject in$1AtIndex:(unsigned int)i
{
[$3 insertObject:anObject atIndex:i];
}
- ($2)objectIn$1AtIndex:(unsigned int)i
{
return [$3 objectAtIndex:i];
}
- (unsigned int)indexOfObjectIn$1:($2)anObject
{
return [$3 indexOfObject:anObject];
}
- (void)removeObjectFrom$1AtIndex:(unsigned int)i
{
[$3 removeObjectAtIndex:i];
}
- (unsigned int)countOf$1
{
return [$3 count];
}
- (NSArray${TM_C_POINTER/(^(.+?)\s*$)?/(?1:$2: *)/})${1/./\l$0/}
{
return $3;
}
- (void)set$1:(NSArray${TM_C_POINTER/(^(.+?)\s*$)?/(?1:$2: *)/})new$1
{
[$3 setArray:new$1];
}

View File

@@ -1,7 +0,0 @@
# -*- mode: snippet -*-
# key: prop
# contributor: Translated from TextMate Snippet
# name: Property (Objective-C 2.0)
## condition: "source.objc meta.scope.interface, source.objc++ meta.scope.interface"
# --
@property (${1/^(e)$|.*/(?1:r)/}${1:r}${1/^(?:(r)|(e)|(c)|(a))$|.*/(?1:etain)(?2:adonly)(?3:opy)(?4:ssign)/}) ${2:NSSomeClass}${TM_C_POINTER: *}${3:${2/^[A-Z](?:[A-Z]+|[a-z]+)([A-Z]\w*)/\l$1/}};

View File

@@ -1,15 +0,0 @@
# -*- mode: snippet -*-
# key: acc
# contributor: Translated from TextMate Snippet
# name: Primitive Type
## condition: "(source.objc | source.objc++) & meta.scope.implementation.objc - meta.function-with-body"
# --
- (${1:unsigned int})${2:thing}
{
return ${3:$2};
}
- (void)set${2/./\u$0/}:(${1:unsigned int})new${2/./\u$0/}
{
$3 = new${2/./\u$0/};
}

View File

@@ -1,17 +0,0 @@
# -*- mode: snippet -*-
# key: stracc
# contributor: Translated from TextMate Snippet
# name: String
## condition: "(source.objc | source.objc++) & meta.scope.implementation.objc - meta.function-with-body"
# --
- (NSString${TM_C_POINTER/(^(.+?)\s*$)?/(?1:$2: *)/})${1:thing}
{
return ${2:$1};
}
- (void)set${1/.*/\u$0/}:(NSString${TM_C_POINTER/(^(.+?)\s*$)?/(?1:$2: *)/})${3:a${1/.*/\u$0/}}
{
$3 = [$3 copy];
[$2 release];
$2 = $3;
}

View File

@@ -1,7 +0,0 @@
# -*- mode: snippet -*-
# key: syn
# contributor: Translated from TextMate Snippet
# name: Synthesize Property
## condition: "(source.objc | source.objc++) & meta.scope.implementation.objc - meta.function-with-body"
# --
@synthesize ${1:property};

View File

@@ -1,7 +0,0 @@
# -*- mode: snippet -*-
# key: M
# contributor: Translated from TextMate Snippet
# name: Interface: Class Method
## condition: "source.objc meta.scope.interface, source.objc++ meta.scope.interface"
# --
+ (${1:id})${0:method};

View File

@@ -1,7 +0,0 @@
# -*- mode: snippet -*-
# key: thread
# contributor: Translated from TextMate Snippet
# name: Detach New NSThread
## condition: "source.objc, source.objc++"
# --
[NSThread detachNewThreadSelector:@selector(${1:method}:) toTarget:${2:aTarget} withObject:${3:anArgument}]

View File

@@ -1,7 +0,0 @@
# -*- mode: snippet -*-
# key: bind
# contributor: Translated from TextMate Snippet
# name: Bind Property to Key Path of Object
## condition: "source.objc, source.objc++"
# --
bind:@"${2:binding}" toObject:${3:observableController} withKeyPath:@"${4:keyPath}" options:${5:nil}

View File

@@ -1,8 +0,0 @@
# -*- mode: snippet -*-
# key: log
# contributor: Translated from TextMate Snippet
# name: NSLog(…)
# condition: (and (yas/objc-implementation-p) (yas/objc-method-body-p))
# --
NSLog(@"${1:%@}"${1:$(if (string-match "%" text) ", " ");")
}$2${1:$(if (string-match "%" text) ");" "")}$0

View File

@@ -1,15 +0,0 @@
# -*- mode: snippet -*-
# key: alert
# contributor: Translated from TextMate Snippet
# name: NSRunAlertPanel
## condition: "source.objc, source.objc++"
# --
int choice = NSRunAlertPanel(@"${1:Something important!}", @"${2:Something important just happend, and now I need to ask you, do you want to continue?}", @"${3:Continue}", @"${4:Cancel}", nil);
if(choice == NSAlertDefaultReturn) // "${3:Continue}"
{
$0;
}
else if(choice == NSAlertAlternateReturn) // "${4:Cancel}"
{
}

View File

@@ -1,7 +0,0 @@
# -*- mode: snippet -*-
# key: getprefs
# contributor: Translated from TextMate Snippet
# name: Read Defaults Value
## condition: "source.objc, source.objc++"
# --
[[NSUserDefaults standardUserDefaults] objectForKey:${1:key}];

View File

@@ -1,7 +0,0 @@
# -*- mode: snippet -*-
# key: obs
# contributor: Translated from TextMate Snippet
# name: Register for Notification
## condition: "source.objc meta.scope.implementation, source.objc++ meta.scope.implementation"
# --
[[NSNotificationCenter defaultCenter] addObserver:${1:self} selector:@selector(${3:${2/^([A-Z]{2})?(.+?)(Notification)?$/\l$2/}}:) name:${2:NSWindowDidBecomeMainNotification} object:${4:nil}];

View File

@@ -1,7 +0,0 @@
# -*- mode: snippet -*-
# key: setprefs
# contributor: Translated from TextMate Snippet
# name: Write Defaults Value
## condition: "source.objc, source.objc++"
# --
[[NSUserDefaults standardUserDefaults] setObject:${1:object} forKey:${2:key}];

View File

@@ -1,7 +0,0 @@
# -*- mode: snippet -*-
# type: command
# contributor: Translated from TextMate Snippet
# name: Reformat Method Signature
## binding: "^q"
## condition: "meta.function.objc"
# --

View File

@@ -1,13 +0,0 @@
# -*- mode: snippet -*-
# key: forarray
# contributor: Translated from TextMate Snippet
# name: NSArray Loop
## condition: "source.objc, source.objc++"
# --
unsigned int ${1:object}Count = [${2:array} count];
for(unsigned int index = 0; index < ${1}Count; index += 1)
{
${3:id} ${1} = [$2 objectAtIndex:index];
$0
}

View File

@@ -1,8 +0,0 @@
# -*- mode: snippet -*-
# key: delegate
# contributor: Translated from TextMate Snippet
# name: Delegate Responds to Selector
## condition: "source.objc, source.objc++"
# --
if([${1:[self delegate]} respondsToSelector:@selector(${2:selfDidSomething:})])
[$1 ${3:${2/((^\s*([A-Za-z0-9_]*:)\s*)|(:\s*$)|(:\s*))/(?2:$2self :\:<>)(?4::)(?5: :)/g}}];

View File

@@ -1,9 +0,0 @@
# -*- mode: snippet -*-
# key: focus
# contributor: Translated from TextMate Snippet
# name: Lock Focus
## condition: "source.objc, source.objc++"
# --
[self lockFocus];
$0
[self unlockFocus];

View File

@@ -1,9 +0,0 @@
# -*- mode: snippet -*-
# key: pool
# contributor: Translated from TextMate Snippet
# name: NSAutoreleasePool
## condition: "source.objc, source.objc++"
# --
NSAutoreleasePool${TM_C_POINTER: *}pool = [NSAutoreleasePool new];
$0
[pool drain];

View File

@@ -1,11 +0,0 @@
# -*- mode: snippet -*-
# key: responds
# contributor: Translated from TextMate Snippet
# name: Responds to Selector
## condition: "source.objc, source.objc++"
# --
${TM_COMMENT_START} ${4:Send $2 to $1, if $1 supports it}${TM_COMMENT_END}
if ([${1:self} respondsToSelector:@selector(${2:someSelector:})])
{
[$1 ${3:${2/((:\s*$)|(:\s*))/:<>(?3: )/g}}];
}

View File

@@ -1,9 +0,0 @@
# -*- mode: snippet -*-
# key: gsave
# contributor: Translated from TextMate Snippet
# name: Save and Restore Graphics Context
## condition: "source.objc, source.objc++"
# --
[NSGraphicsContext saveGraphicsState];
$0
[NSGraphicsContext restoreGraphicsState];

View File

@@ -1,7 +0,0 @@
# -*- mode: snippet -*-
# type: command
# key: super
# contributor: Translated from TextMate Snippet
# name: Insert Call to Super
## condition: "source.objc meta.scope.implementation, source.objc++ meta.scope.implementation"
# --

View File

@@ -1,7 +0,0 @@
# -*- mode: snippet -*-
# key: imp
# contributor: Translated from TextMate Snippet
# name: #import "…"
## condition: "source.objc, source.objc++"
# --
#import "${1:${TM_FILENAME/\...*$/.h/}}"

View File

@@ -1,7 +0,0 @@
# -*- mode: snippet -*-
# key: Imp
# contributor: Translated from TextMate Snippet
# name: #import <…>
## condition: "source.objc, source.objc++"
# --
#import <${1:Cocoa/Cocoa.h}>

View File

@@ -1,20 +0,0 @@
# -*- mode: snippet -*-
# key: cl
# contributor: Translated from TextMate Snippet
# name: Class
## condition: "source.objc, source.objc++ - meta.scope.implementation.objc"
# --
@interface ${1:${TM_FILENAME/\...*$|(^$)/(?1:object)/}} : ${2:NSObject}
{
}
@end
@implementation $1
- (id)init
{
if((self = [super init]))
{$0
}
return self;
}
@end

View File

@@ -1,10 +0,0 @@
# -*- mode: snippet -*-
# key: m
# contributor: Translated from TextMate Snippet
# name: Method
# binding: C-c m
# condition: (and (yas/objc-implementation-p) (not (yas/objc-method-body-p)))
# --
- (${1:id})${2:`(or yas/selected-text "method")`}${3::(${4:id})${5:${4:$(
yas/objc-guess-instance-name yas/text)}}} {$0${1:$(if (
string-match yas/objc-void-regexp text) "}" "\n return nil;\n}")}

View File

@@ -1,11 +0,0 @@
# -*- mode: snippet -*-
# key: sm
# contributor: Translated from TextMate Snippet
# name: Sub-method (Call Super)
# condition: (and (yas/objc-implementation-p) (not (yas/objc-method-body-p)))
# --
- (${1:id})${2:`(or yas/selected-text "method")`}${3::(${4:id})${5:${4:$(
yas/objc-guess-instance-name yas/text)}}} {
${1:$(if (string-match yas/objc-void-regexp text) "" "res = ")}[super $2${5:$(
if (string= yas/text "") "" (concat ":" yas/text))}];${1:$(if (string-match yas/objc-void-regexp text) "" "\n return res;")}
}

View File

@@ -1,12 +0,0 @@
# -*- mode: snippet -*-
# key: cat
# contributor: Translated from TextMate Snippet
# name: Category
## condition: "source.objc, source.objc++"
# --
@interface ${1:${TM_FILENAME/.*?(\w+).*|.*/(?1:$1:NSObject)/}} (${2:${TM_FILENAME/.*?\w+\W+(\w+).*\..+|.*/(?1:$1:Category)/}})
@end
@implementation $1 ($2)
$0
@end

View File

@@ -1,9 +0,0 @@
# -*- mode: snippet -*-
# key: catm
# contributor: Translated from TextMate Snippet
# name: Category Implementation
## condition: "source.objc, source.objc++"
# --
@implementation ${1:${TM_FILENAME/.*?(\w+).*|.*/(?1:$1:NSObject)/}} (${2:${TM_FILENAME/.*?\w+\W+(\w+).*\..+|.*/(?1:$1:Category)/}})
$0
@end

View File

@@ -1,9 +0,0 @@
# -*- mode: snippet -*-
# key: cath
# contributor: Translated from TextMate Snippet
# name: Category Interface
## condition: "source.objc, source.objc++"
# --
@interface ${1:${TM_FILENAME/.*?(\w+).*|.*/(?1:$1:NSObject)/}} (${2:${TM_FILENAME/.*?\w+\W+(\w+).*\..+|.*/(?1:$1:Category)/}})
$0
@end

View File

@@ -1,15 +0,0 @@
# -*- mode: snippet -*-
# key: clm
# contributor: Translated from TextMate Snippet
# name: Class Implementation
## condition: "source.objc, source.objc++"
# --
@implementation ${1:${TM_FILENAME/\...*$|(^$)/(?1:object)/}}
- (id)init
{
if((self = [super init]))
{$0
}
return self;
}
@end

View File

@@ -1,11 +0,0 @@
# -*- mode: snippet -*-
# key: clh
# contributor: Translated from TextMate Snippet
# name: Class Interface
## condition: "source.objc, source.objc++"
# --
@interface ${1:${TM_FILENAME/\...*$|(^$)/(?1:object)/}} : ${2:NSObject}
{$3
}
$0
@end

View File

@@ -1,9 +0,0 @@
# -*- mode: snippet -*-
# key: M
# contributor: Translated from TextMate Snippet
# name: Class Method
# condition: (and (yas/objc-implementation-p) (not (yas/objc-method-body-p)))
# --
+ (${1:id})${2:`(or yas/selected-text "method")`}${3::(${4:id})${5:${4:$(
yas/objc-guess-instance-name yas/text)}}} {$0${1:$(if (
string-match yas/objc-void-regexp text) "}" "\n return nil;\n}")}

View File

@@ -1,7 +0,0 @@
# -*- mode: snippet -*-
# key: ibo
# contributor: Translated from TextMate Snippet
# name: IBOutlet
# condition: (yas/objc-interface-p)
# --
IBOutlet ${1:NSSomeClass}*${2:${1:$(yas/objc-guess-member-name yas/text)}};

View File

@@ -1,12 +0,0 @@
# -*- mode: snippet -*-
# key: I
# contributor: Translated from TextMate Snippet
# name: Method: Initialize
# condition: (and (yas/objc-implementation-p) (not (yas/objc-method-body-p)))
# --
+ (void)initialize
{
[[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:
$0@"value", @"key",
nil]];
}

View File

@@ -1,14 +0,0 @@
# -*- mode: snippet -*-
# key: arracc
# contributor: Translated from TextMate Snippet
# name: Interface: Accessors for KVC Array
## condition: "source.objc meta.scope.interface, source.objc++ meta.scope.interface"
# --
- (void)addObjectTo${1:Things}:(${2:id})anObject;
- (void)insertObject:($2)anObject in$1AtIndex:(unsigned int)i;
- ($2)objectIn$1AtIndex:(unsigned int)i;
- (unsigned int)indexOfObjectIn$1:($2)anObject;
- (void)removeObjectFrom$1AtIndex:(unsigned int)i;
- (unsigned int)countOf$1;
- (NSArray${TM_C_POINTER/(^(.+?)\s*$)?/(?1:$2: *)/})${1/./\l$0/};
- (void)set$1:(NSArray${TM_C_POINTER/(^(.+?)\s*$)?/(?1:$2: *)/})new$1;

View File

@@ -1,7 +0,0 @@
# -*- mode: snippet -*-
# type: command
# contributor: Translated from TextMate Snippet
# name: Documentation for Word / Selection
## binding: "^h"
## condition: "source.c, source.c++, source.objc, source.objc++, (source.objc support | source.objc++ support) - support.function.any-method"
# --

View File

@@ -1,8 +0,0 @@
# -*- mode: snippet -*-
# key: m
# contributor: Translated from TextMate Snippet
# name: Interface: Method
# binding: "C-c m"
# condition: (yas/objc-interface-p)
# --
- (${1:id})${2:${TM_SELECTED_TEXT:method}}${3::(${4:id})${5:${4/(NS([AEIOQUY])?(\w+).*)|(.)?.*/(?1:a(?2:n$2)$3:(?4:anArgument))/}}};

View File

@@ -1,8 +0,0 @@
# -*- mode: snippet -*-
# key: objacc
# contributor: Translated from TextMate Snippet
# name: Interface: Accessors for Object
## condition: "source.objc meta.scope.interface, source.objc++ meta.scope.interface"
# --
- (${1:id})${2:thing};
- (void)set${2/./\u$0/}:($1)aValue;

View File

@@ -1,7 +0,0 @@
# -*- mode: snippet -*-
# key: array
# contributor: Translated from TextMate Snippet
# name: NSArray
## condition: "source.objc, source.objc++"
# --
NSMutableArray${TM_C_POINTER: *}${1:array} = [NSMutableArray array];

View File

@@ -1,7 +0,0 @@
# -*- mode: snippet -*-
# key: dict
# contributor: Translated from TextMate Snippet
# name: NSDictionary
## condition: "source.objc, source.objc++"
# --
NSMutableDictionary${TM_C_POINTER: *}${1:dict} = [NSMutableDictionary dictionary];

View File

@@ -1,8 +0,0 @@
# -*- mode: snippet -*-
# key: bez
# contributor: Translated from TextMate Snippet
# name: NSBezierPath
## condition: "source.objc, source.objc++"
# --
NSBezierPath${TM_C_POINTER: *}${1:path} = [NSBezierPath bezierPath];
$0

View File

@@ -1,7 +0,0 @@
# -*- mode: snippet -*-
# key: format
# contributor: Translated from TextMate Snippet
# name: NSString With Format
## condition: "source.objc, source.objc++"
# --
[NSString stringWithFormat:@"$1", $2]$0

View File

@@ -1,8 +0,0 @@
# -*- mode: snippet -*-
# key: acc
# contributor: Translated from TextMate Snippet
# name: Interface: Accessors for Primitive Type
## condition: "source.objc meta.scope.interface, source.objc++ meta.scope.interface"
# --
- (${1:unsigned int})${2:thing};
- (void)set${2/./\u$0/}:($1)new${2/./\u$0/};

View File

@@ -1,8 +0,0 @@
# -*- mode: snippet -*-
# key: stracc
# contributor: Translated from TextMate Snippet
# name: Interface: Accessors for String
## condition: "source.objc meta.scope.interface, source.objc++ meta.scope.interface"
# --
- (NSString${TM_C_POINTER/(^(.+?)\s*$)?/(?1:$2: *)/})${1:thing};
- (void)set${1/./\u$0/}:(NSString${TM_C_POINTER/(^(.+?)\s*$)?/(?1:$2: *)/})${2:a${1/.*/\u$0/}};

View File

@@ -1,7 +0,0 @@
# -*- mode: snippet -*-
# type: command
# key: alloc
# contributor: Translated from TextMate Snippet
# name: Insert [[[… alloc] init] autorelease]
## condition: "source.objc, source.objc++"
# --

View File

@@ -1,7 +0,0 @@
# -*- mode: snippet -*-
# key: sel
# contributor: Translated from TextMate Snippet
# name: @selector(…)
## condition: "source.objc, source.objc++"
# --
@selector(${1:method}:)