Add objc syntax highlighting, closes #77
This commit is contained in:
parent
08ea94e011
commit
b4b054ebf5
@ -64,6 +64,7 @@ Optionally download one of the [releases](https://github.com/sheerun/vim-polyglo
|
||||
- [liquid](https://github.com/tpope/vim-liquid) (syntax, indent, ftplugin, ftdetect)
|
||||
- [markdown](https://github.com/tpope/vim-markdown) (syntax, ftplugin, ftdetect)
|
||||
- [nginx](https://github.com/nginx/nginx) (syntax, indent, ftdetect)
|
||||
- [objc](https://github.com/b4winckler/vim-objc) (ftplugin, syntax, indent)
|
||||
- [ocaml](https://github.com/jrk/vim-ocaml) (syntax, indent, ftplugin)
|
||||
- [octave](https://github.com/vim-scripts/octave.vim--) (syntax)
|
||||
- [opencl](https://github.com/petRUShka/vim-opencl) (syntax, indent, ftplugin, ftdetect)
|
||||
|
97
after/indent/objc.vim
Normal file
97
after/indent/objc.vim
Normal file
@ -0,0 +1,97 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'objc') == -1
|
||||
|
||||
" Vim indent file
|
||||
" Language: Objective-C
|
||||
" Maintainer: Bjorn Winckler <bjorn.winckler@gmail.com>
|
||||
" Last Change: 2012 Jan 01
|
||||
|
||||
" Ensure 'cpo' is set to Vim default values and restore later
|
||||
let s:save_cpo = &cpo
|
||||
set cpo&vim
|
||||
|
||||
" Only load this indent file when no other was loaded.
|
||||
"if exists("b:did_indent")
|
||||
" finish
|
||||
"endif
|
||||
"let b:did_indent = 1
|
||||
"setlocal cindent
|
||||
|
||||
setl indentkeys=0{,0},:,0#,!^F,o,O,e,<:>
|
||||
|
||||
setlocal indentexpr=GetObjCIndentImproved()
|
||||
|
||||
" Top level statements which should not be indented, and which should not
|
||||
" cause next (non-blank) line to be indented either.
|
||||
let s:topLev = '^\s*@\%(class\|end\|implementation\|interface\|protocol\|\)\>'
|
||||
|
||||
function! GetObjCIndentImproved()
|
||||
" NOTE: Ignore leading white space to avoid having to deal with space vs.
|
||||
" tab issues. Rely on the indent() function instead.
|
||||
let thisLine = substitute(getline(v:lnum), '^\s*', '', '')
|
||||
|
||||
if thisLine =~# s:topLev || getline(prevnonblank(v:lnum - 1)) =~# s:topLev
|
||||
return 0
|
||||
endif
|
||||
|
||||
" If current line looks like an argument to a message dispatch, then line
|
||||
" up colon with previous line. This will indent the second line so that
|
||||
" the colons line up in
|
||||
"
|
||||
" [obj firstParameter:value
|
||||
" paramB:value2];
|
||||
"
|
||||
" but it will not line up colons in
|
||||
"
|
||||
" if ([obj something:here])
|
||||
" [obj other:here];
|
||||
"
|
||||
let thisColon = match(thisLine, '^\s*\K\k*\zs:')
|
||||
if thisColon > 0
|
||||
let prevLine = substitute(getline(v:lnum - 1), '^\s*', '', '')
|
||||
let prevColon = match(prevLine, ':')
|
||||
if prevColon > 0
|
||||
" Try to align colons, always making sure line is indented at least
|
||||
" one shiftwidth more than the indentation at the beginning of the
|
||||
" message. Avoids situations like this:
|
||||
"
|
||||
" if ([obj a:x
|
||||
" aLongParameter:y])
|
||||
"
|
||||
let [lnum,lcol] = searchpairpos('\[', '', '\]', 'b', 0,
|
||||
\ max([1, v:lnum - 10]))
|
||||
let minInd = &sw + (lnum > 0 ? indent(lnum) : 0)
|
||||
let alignedInd = indent(v:lnum - 1) + prevColon - thisColon
|
||||
return alignedInd > minInd ? alignedInd : minInd
|
||||
endif
|
||||
endif
|
||||
|
||||
let prevLnum = v:lnum - 1
|
||||
let ind = indent(prevLnum)
|
||||
|
||||
" Indent one shiftwidth after opening block, e.g.:
|
||||
"
|
||||
" call_func_with_block(param, ^{
|
||||
" do_stuff();
|
||||
" });
|
||||
"
|
||||
let blockPat = '\^\s*\(([^)]*)\)\?\s*{$'
|
||||
if thisLine =~ '^}'
|
||||
norm '^%'
|
||||
if getline(".") =~ blockPat
|
||||
return indent(".")
|
||||
endif
|
||||
endif
|
||||
|
||||
if getline(prevLnum) =~ blockPat
|
||||
return ind + &sw
|
||||
endif
|
||||
|
||||
return cindent(v:lnum)
|
||||
endfunction
|
||||
|
||||
|
||||
" Restore 'cpo' options
|
||||
let &cpo = s:save_cpo
|
||||
unlet s:save_cpo
|
||||
|
||||
endif
|
23
after/syntax/objc.vim
Normal file
23
after/syntax/objc.vim
Normal file
@ -0,0 +1,23 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'objc') == -1
|
||||
|
||||
" ARC type modifiers
|
||||
syn keyword objcTypeModifier __bridge __bridge_retained __bridge_transfer __autoreleasing __strong __weak __unsafe_unretained
|
||||
|
||||
" Block modifiers
|
||||
syn keyword objcTypeModifier __block
|
||||
|
||||
" Remote messaging modifiers
|
||||
syn keyword objcTypeModifier byref
|
||||
|
||||
" Property keywords - these are only highlighted inside '@property (...)'
|
||||
syn keyword objcPropertyAttribute contained getter setter readwrite readonly strong weak copy assign retain nonatomic
|
||||
syn match objcProperty display "^\s*@property\>\s*([^)]*)" contains=objcPropertyAttribute
|
||||
|
||||
" The @property directive must be defined after objcProperty or it won't be
|
||||
" highlighted
|
||||
syn match objcDirective "@property\|@synthesize\|@dynamic\|@package"
|
||||
|
||||
" Highlight property attributes as if they were type modifiers
|
||||
hi def link objcPropertyAttribute objcTypeModifier
|
||||
|
||||
endif
|
1
build
1
build
@ -135,6 +135,7 @@ PACKS="
|
||||
liquid:tpope/vim-liquid
|
||||
markdown:tpope/vim-markdown
|
||||
nginx:nginx/nginx::/contrib/vim/
|
||||
objc:b4winckler/vim-objc
|
||||
ocaml:jrk/vim-ocaml
|
||||
octave:vim-scripts/octave.vim--
|
||||
opencl:petRUShka/vim-opencl
|
||||
|
10
ftplugin/objc.vim
Normal file
10
ftplugin/objc.vim
Normal file
@ -0,0 +1,10 @@
|
||||
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'objc') == -1
|
||||
|
||||
" Use C++ style comment strings with commentary.vim
|
||||
setl commentstring=//%s
|
||||
|
||||
" Search for include files inside frameworks (used for gf etc.)
|
||||
setl includeexpr=substitute(v:fname,'\\([^/]\\+\\)/\\(.\\+\\)','/System/Library/Frameworks/\\1.framework/Headers/\\2','')
|
||||
|
||||
|
||||
endif
|
Loading…
Reference in New Issue
Block a user