Skip to content

Commit

Permalink
Version 0.6955
Browse files Browse the repository at this point in the history
Actually fixed the supertab bug (thanks Asher VanBrunt); also added some more Objective-C snippets, and fixed another bug with expanding snippets before text introduced in the previous version.
  • Loading branch information
Michael Sanders authored and vim-scripts committed Nov 16, 2010
1 parent af041ab commit 7ce3516
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
24 changes: 19 additions & 5 deletions after/ftplugin/objc_snips.vim
@@ -1,7 +1,7 @@
if !exists('loaded_snips') || exists('b:did_js_snips')
if !exists('loaded_snips') || exists('b:did_objc_snips')
fini
en
let b:did_js_snips = 1
let b:did_objc_snips = 1

" #import <...>
exe 'Snipp imp #import <${1:Cocoa/Cocoa.h}>${2}'
Expand All @@ -15,26 +15,40 @@ exe 'Snipp log NSLog(@"${1}"${2});${3}'
exe "Snipp objc @interface ${1:`Filename('', 'object')`} : ${2:NSObject}\n{\n}\n@end\n\n@implementation $1\n- (id) init\n{\n\tif (self = [super init])"
\."\n\t{${3}\n\t}\n\treturn self\n}\n@end"
" Class Interface
exe "Snipp cli @interface ${1:ClassName} : ${2:NSObject}\n{${3}\n}\n${4}\n@end"
exe "Snipp clh @interface ${1:ClassName} : ${2:NSObject}\n{${3}\n}\n${4}\n@end"
exe 'Snipp ibo IBOutlet ${1:NSSomeClass} *${2:$1};'
" Category
exe "Snipp cat @interface ${1:NSObject} (${2:Category})\n@end\n\n@implementation $1 ($2)\n${3}\n@end"
" Category Interface
exe "Snipp cati @interface ${1:NSObject} (${2:Category})\n${3}\n@end"
exe "Snipp cath @interface ${1:NSObject} (${2:Category})\n${3}\n@end"
" NSArray
exe 'Snipp array NSMutableArray *${1:array} = [NSMutable array];${2}'
" NSDictionary
exe 'Snipp dict NSMutableDictionary *${1:dict} = [NSMutableDictionary dictionary];${2}'
" NSBezierPath
exe 'Snipp bez NSBezierPath *${1:path} = [NSBezierPath bezierPath];${2}'
" Method
exe "Snipp m - (${1:id})${2:method}\n{\n\t${3:return self;}\n}"
" Method declaration
exe "Snipp md - (${1:id})${2:method};${3}"
" Class Method
exe "Snipp M + (${1:id})${2:method}\n{${3}\n\treturn nil;\n}"
" Sub-method (Call super)
exe "Snipp sm - (${1:id})${2:method}:(${3:id})${4:anArgument}\n{\n\t$1 res = [super $2:$4];${5}\n\treturn res;\n}"
exe "Snipp sm - (${1:id})${2:method}\n{\n\t[super $2];${3}\n\treturn self;\n}"
" Method: Initialize
exe "Snipp I + (void) initialize\n{\n\t[[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWIthObjectsAndKeys:\n\t\t${1}@\"value\", @\"key\",\n\t\tnil]];\n}"
" Accessor Methods For:
" Object
exe "Snipp objacc - (${1:id})${2:thing}\n{\n\treturn $2;\n}\n\n- (void) set$2:($1)\n{\n\t$1 old$2 = $2;\n\t$2 = [aValue retain];\n\t[old$2 release];\n}"
exe "Snipp forarray unsigned int\t${1:object}Count = [${2:array} count];\n\nfor (unsigned int index = 0; index < $1Count; index++)\n{\n\t${3:id}\t$1 = [$2 $1AtIndex:index];\n\t${4}\n}"
" IBOutlet
" @property (Objective-C 2.0)
exe "Snipp prop @property (${1:retain}) ${2:NSSomeClass} *${3:$2};${4}"
" @synthesize (Objective-C 2.0)
exe "Snipp syn @synthesize ${1:NSSomeClass};${2}"
" [[ alloc] init]
exe 'Snipp alloc [[${1:foo} alloc] init]${2};${3}'
" retain
exe 'Snipp ret [${1:foo} retain];${2}'
" release
exe 'Snipp rel [${1:foo} release];${2}'
19 changes: 10 additions & 9 deletions plugin/snipMate.vim
@@ -1,6 +1,6 @@
" File: snipMate.vim
" Author: Michael Sanders
" Version: 0.6954
" Version: 0.6955
" Description: snipMate.vim implements some of TextMate's snippets features in
" Vim. A snippet is a piece of often-typed text that you can
" insert into your document using a trigger word followed by a "<tab>".
Expand Down Expand Up @@ -149,16 +149,16 @@ fun s:Count(haystack, needle)
endf

fun! ExpandSnippet()
if !exists('s:sid') && exists('g:SuperTabMappingForward')
\ && g:SuperTabMappingForward == "<tab>"
cal s:GetSuperTabSID()
en
if pumvisible() " update snippet if completion is used, or deal with supertab
if exists('s:sid') | retu {s:sid}_SuperTab('n') | en
if exists('s:sid') | retu "<c-n>" | en
cal feedkeys("\<esc>a", 'n') | cal s:UpdateChangedSnip(0)
en

if !exists('s:snipPos') " don't expand snippets within snippets
if !exists('s:sid') && exists('g:SuperTabMappingForward')
\ && g:SuperTabMappingForward == "<tab>"
cal s:GetSuperTabSID()
en
" get word before cursor
let origWord = matchstr(getline('.'), '\S\+\%'.col('.').'c')
let word = s:Hash(origWord)
Expand All @@ -179,10 +179,10 @@ fun! ExpandSnippet()
" if word is a trigger for a snippet, delete the trigger & expand
" the snippet
exe 'sil s/'.origWord.'\%#//'
let col -= len(origWord) | if col > 1 | let col -= 1 | en
let col -= len(origWord)

let afterCursor = strpart(getline('.'), col-1)
if afterCursor != "\t" && afterCursor != ' ' | sil s/\%#.*//
if afterCursor != "\t" && afterCursor != ' ' | sil exe 's/\%'.col.'c.*//'
el | let afterCursor = '' | en

" evaluate eval (`...`) expressions
Expand Down Expand Up @@ -218,10 +218,11 @@ fun! ExpandSnippet()

let snip = split(substitute(snippet, '$\d\|${\d.\{-}}', '', 'g'), "\n", 1)
if afterCursor != '' | let snip[-1] .= afterCursor | en
" let line = strpart(getline(lnum), 0, col-1)
let line = getline(lnum)
cal setline(lnum, line.snip[0])

if line != '' && afterCursor == '' && &ve != 'all' && &ve != 'onemore'
if line != '' && col == 1 && afterCursor == '' && &ve !~ 'all\|onemore'
let col += 1
en
" autoindent snippet according to previous indentation
Expand Down

0 comments on commit 7ce3516

Please sign in to comment.