diff --git a/extras/imported/objc-mode/.yas-setup.el b/extras/imported/objc-mode/.yas-setup.el index 289b345..88d9575 100644 --- a/extras/imported/objc-mode/.yas-setup.el +++ b/extras/imported/objc-mode/.yas-setup.el @@ -1,4 +1,24 @@ -;;; conditions +;;; 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." @@ -11,10 +31,10 @@ (yas/define-condition-cache yas/objc-method-body-p - "Non-nil if point inside an objc @implementation declaration." + "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)) diff --git a/extras/imported/objc-mode/Common Method Calls/NSLog (log) 2.yasnippet b/extras/imported/objc-mode/Common Method Calls/NSLog (log) 2.yasnippet index 7fc8893..ea86a20 100644 --- a/extras/imported/objc-mode/Common Method Calls/NSLog (log) 2.yasnippet +++ b/extras/imported/objc-mode/Common Method Calls/NSLog (log) 2.yasnippet @@ -2,6 +2,7 @@ # key: log # contributor: Translated from TextMate Snippet # name: NSLog(…) -## condition: "source.objc, source.objc++" +# condition: (and (yas/objc-implementation-p) (yas/objc-method-body-p)) # -- -NSLog(@"$1"${1/[^%]*(%)?.*/(?1:, :\);)/}$2${1/[^%]*(%)?.*/(?1:\);)/} \ No newline at end of file +NSLog(@"${1:%@}"${1:$(if (string-match "%" text) ", " ");") +}$2${1:$(if (string-match "%" text) ");" "")}$0 diff --git a/extras/imported/objc-mode/Language Boilerplate/050 Method (m).yasnippet b/extras/imported/objc-mode/Language Boilerplate/050 Method (m).yasnippet index 5b655e2..623cb3e 100644 --- a/extras/imported/objc-mode/Language Boilerplate/050 Method (m).yasnippet +++ b/extras/imported/objc-mode/Language Boilerplate/050 Method (m).yasnippet @@ -2,10 +2,9 @@ # key: m # contributor: Translated from TextMate Snippet # name: Method -## binding: "^M" -## condition: "(source.objc | source.objc++) & meta.scope.implementation.objc - meta.function-with-body" +# binding: C-c m +# condition: (and (yas/objc-implementation-p) (not (yas/objc-method-body-p))) # -- -- (${1:id})${2:${TM_SELECTED_TEXT:method}}${3::(${4:id})${5:${4/(NS([AEIOQUY])?(\w+).*)|(.)?.*/(?1:a(?2:n$2)$3:(?4:anArgument))/}}} -{$0${1/^(void|IBAction)$|(.*)/(?2: - return nil;)/} -} \ No newline at end of file +- (${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}")} \ No newline at end of file diff --git a/extras/imported/objc-mode/Language Boilerplate/060 SubMethod (sm).yasnippet b/extras/imported/objc-mode/Language Boilerplate/060 SubMethod (sm).yasnippet index 38346b9..696bb9a 100644 --- a/extras/imported/objc-mode/Language Boilerplate/060 SubMethod (sm).yasnippet +++ b/extras/imported/objc-mode/Language Boilerplate/060 SubMethod (sm).yasnippet @@ -2,10 +2,10 @@ # key: sm # contributor: Translated from TextMate Snippet # name: Sub-method (Call Super) -## condition: "(source.objc | source.objc++) & meta.scope.implementation.objc - meta.function-with-body" +# condition: (and (yas/objc-implementation-p) (not (yas/objc-method-body-p))) # -- -- (${1:id})${2:method}${3::(${4:id})${5:${4/(NS([AEIOQUY])?(\w+).*)|(.)?.*/(?1:a(?2:n$2)$3:(?4:anArgument))/}}} -{ - ${1/^(void|IBAction)$|(.*)/(?2:$2 res = )/}[super ${2:method}${5/.+/:$0/}];$0${1/^(void|IBAction)$|(.*)/(?2: - return res;)/} -} \ No newline at end of file +- (${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;")} +} diff --git a/extras/imported/objc-mode/Language Boilerplate/Class Method (M).yasnippet b/extras/imported/objc-mode/Language Boilerplate/Class Method (M).yasnippet index 59c5f81..0da8282 100644 --- a/extras/imported/objc-mode/Language Boilerplate/Class Method (M).yasnippet +++ b/extras/imported/objc-mode/Language Boilerplate/Class Method (M).yasnippet @@ -2,9 +2,8 @@ # key: M # contributor: Translated from TextMate Snippet # name: Class Method -## condition: "(source.objc | source.objc++) & meta.scope.implementation.objc - meta.function-with-body" +# condition: (and (yas/objc-implementation-p) (not (yas/objc-method-body-p))) # -- -+ (${1:id})${2:method}${3::(${4:id})${5:${4/(NS([AEIOQUY])?(\w+).*)|(.)?.*/(?1:a(?2:n$2)$3:(?4:anArgument))/}}} -{$0${1/^(void|IBAction)$|(.*)/(?2: - return nil;)/} -} \ No newline at end of file ++ (${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}")} diff --git a/extras/imported/objc-mode/Language Boilerplate/IBOutlet (ibo).yasnippet b/extras/imported/objc-mode/Language Boilerplate/IBOutlet (ibo).yasnippet index d2e246d..d43fc09 100644 --- a/extras/imported/objc-mode/Language Boilerplate/IBOutlet (ibo).yasnippet +++ b/extras/imported/objc-mode/Language Boilerplate/IBOutlet (ibo).yasnippet @@ -2,6 +2,6 @@ # key: ibo # contributor: Translated from TextMate Snippet # name: IBOutlet -## condition: "source.objc, source.objc++" +# condition: (yas/objc-interface-p) # -- -IBOutlet ${1:NSSomeClass}${TM_C_POINTER: *}${2:${1/^[A-Z](?:[A-Z]+|[a-z]+)([A-Z]\w*)/\l$1/}}; \ No newline at end of file +IBOutlet ${1:NSSomeClass}*${2:${1:$(yas/objc-guess-member-name yas/text)}}; \ No newline at end of file diff --git a/extras/imported/objc-mode/Language Boilerplate/Initialize Implementation (I).yasnippet b/extras/imported/objc-mode/Language Boilerplate/Initialize Implementation (I).yasnippet index 4b66416..1ed949e 100644 --- a/extras/imported/objc-mode/Language Boilerplate/Initialize Implementation (I).yasnippet +++ b/extras/imported/objc-mode/Language Boilerplate/Initialize Implementation (I).yasnippet @@ -2,7 +2,7 @@ # key: I # contributor: Translated from TextMate Snippet # name: Method: Initialize -## condition: "(source.objc | source.objc++) & meta.scope.implementation.objc - meta.function-with-body" +# condition: (and (yas/objc-implementation-p) (not (yas/objc-method-body-p))) # -- + (void)initialize { diff --git a/extras/imported/objc-mode/Method Interface (m).yasnippet b/extras/imported/objc-mode/Method Interface (m).yasnippet index dc228a4..53f8e3b 100644 --- a/extras/imported/objc-mode/Method Interface (m).yasnippet +++ b/extras/imported/objc-mode/Method Interface (m).yasnippet @@ -2,7 +2,7 @@ # key: m # contributor: Translated from TextMate Snippet # name: Interface: Method -## binding: "^M" -## condition: "source.objc meta.scope.interface, source.objc++ meta.scope.interface" +# 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))/}}}; \ No newline at end of file diff --git a/extras/imported/objc-mode/NSLog(.., _cmd) (log).yasnippet b/extras/imported/objc-mode/NSLog(.., _cmd) (log).yasnippet deleted file mode 100644 index cd05e25..0000000 --- a/extras/imported/objc-mode/NSLog(.., _cmd) (log).yasnippet +++ /dev/null @@ -1,7 +0,0 @@ -# -*- mode: snippet -*- -# key: log -# contributor: Translated from TextMate Snippet -# name: NSLog(.., _cmd) -## condition: "source.objc meta.scope.implementation, source.objc++ meta.scope.implementation" -# -- -NSLog(@"%s$1", _cmd${1/[^%]*(%)?.*/(?1:, :\);)/}$2${1/[^%]*(%)?.*/(?1:\);)/} \ No newline at end of file