Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gaogao1030 committed Jun 29, 2014
0 parents commit b2e618f
Show file tree
Hide file tree
Showing 5 changed files with 258 additions and 0 deletions.
19 changes: 19 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (C) 2011 Andrew Stone

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
vim-slim
===

slim syntax highlighting for vim.

Install with pathogen
---------------------

If you are already using pathogen, you can skip to step 3.

1. Install pathogen (if you haven't already)

mkdir -p ~/.vim/autoload ~/.vim/bundle; \
curl -so ~/.vim/autoload/pathogen.vim \
https://raw.github.com/tpope/vim-pathogen/master/autoload/pathogen.vim

2. Edit `~/.vimrc` to run pathogen as the first line of the file (if you haven't already)

```vim
call pathogen#infect()
syntax enable
filetype plugin indent on
```
3. Install slim-vim
pushd ~/.vim/bundle; \
git clone git://github.com/slim-template/vim-slim.git; \
popd
Install with vbundle
--------------------
1. [Install Vundle] into `~/.vim/bundle/`.
[Install Vundle]: https://github.com/gmarik/vundle#quick-start
mkdir -p ~/.vim/bundle; pushd ~/.vim/bundle; \
git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle
popd
2. Configure your vimrc for Vundle. Here's a bare-minimum vimrc that enables vim-slim :
```vim
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
Bundle 'slim-template/vim-slim.git'
syntax enable
filetype plugin indent on
```
If you're adding Vundle to a built-up vimrc, just make sure all these calls
are in there and that they occur in this order.
3. Open vim and run `:BundleInstall`.
To update, open vim and run `:BundleInstall!` (notice the bang!)
1 change: 1 addition & 0 deletions ftdetect/skim.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
autocmd BufNewFile,BufRead *.skim set filetype=skim
75 changes: 75 additions & 0 deletions indent/skim.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
" Vim indent file
" Language: Skim

if exists("b:did_indent")
finish
endif
runtime! indent/ruby.vim
unlet! b:did_indent
let b:did_indent = 1

setlocal autoindent sw=2 et
setlocal indentexpr=GetskimIndent()
setlocal indentkeys=o,O,*<Return>,},],0),!^F,=end,=else,=elsif,=rescue,=ensure,=when

" Only define the function once.
if exists("*GetskimIndent")
finish
endif

let s:attributes = '\%({.\{-\}}\|\[.\{-\}\]\)'
let s:tag = '\%([%.#][[:alnum:]_-]\+\|'.s:attributes.'\)*[<>]*'

if !exists('g:haml_self_closing_tags')
let g:haml_self_closing_tags = 'meta|link|img|hr|br'
endif

function! GetskimIndent()
let lnum = prevnonblank(v:lnum-1)
if lnum == 0
return 0
endif
let line = substitute(getline(lnum),'\s\+$','','')
let cline = substitute(substitute(getline(v:lnum),'\s\+$','',''),'^\s\+','','')
let lastcol = strlen(line)
let line = substitute(line,'^\s\+','','')
let indent = indent(lnum)
let cindent = indent(v:lnum)
if cline =~# '\v^-\s*%(elsif|else|when)>'
let indent = cindent < indent ? cindent : indent - &sw
endif
let increase = indent + &sw
if indent == indent(lnum)
let indent = cindent <= indent ? -1 : increase
endif

let group = synIDattr(synID(lnum,lastcol,1),'name')

if line =~ '^doctype'
return indent
elseif line =~ '^/\%(\[[^]]*\]\)\=$'
return increase
elseif line =~ '^[\.#]'
return increase
elseif line =~? '^div'
return increase
elseif group == 'hamlFilter'
return increase
elseif line =~ '^'.s:tag.'[&!]\=[=~-]\s*\%(\%(if\|else\|elsif\|unless\|case\|when\|while\|until\|for\|begin\|module\|class\|def\)\>\%(.*\<end\>\)\@!\|.*do\%(\s*|[^|]*|\)\=\s*$\)'
return increase
elseif line =~ '^'.s:tag.'[&!]\=[=~-].*,\s*$'
return increase
elseif line == '-#'
return increase
elseif group =~? '\v^(hamlSelfCloser)$' || line =~? '^\v('.g:haml_self_closing_tags.')>'
return indent
elseif group =~? '\v^(hamlTag|hamlAttributesDelimiter|hamlObjectDelimiter|hamlClass|hamlId|htmlTagName|htmlSpecialTagName)$'
return increase
elseif synIDattr(synID(v:lnum,1,1),'name') ==? 'hamlRubyFilter'
return GetRubyIndent()
else
return indent
endif
endfunction

" vim:set sw=2:
101 changes: 101 additions & 0 deletions syntax/skim.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
" Vim syntax file
" Language: Skim
" Maintainer: Andrew Stone <[email protected]>
" Version: 1
" Last Change: 2010 Sep 25
" TODO: Feedback is welcomed.

" Quit when a syntax file is already loaded.
if exists("b:current_syntax")
finish
endif

if !exists("main_syntax")
let main_syntax = 'skim'
endif

" Allows a per line syntax evaluation.
let b:ruby_no_expensive = 1

" Include Ruby syntax highlighting
syn include @skimRubyTop syntax/ruby.vim
unlet! b:current_syntax
" Include Haml syntax highlighting
syn include @skimHaml syntax/haml.vim
unlet! b:current_syntax

syn match skimBegin "^\s*\(&[^= ]\)\@!" nextgroup=skimTag,skimClassChar,skimIdChar,skimRuby

syn region rubyCurlyBlock start="{" end="}" contains=@skimRubyTop contained
syn cluster skimRubyTop add=rubyCurlyBlock

syn cluster skimComponent contains=skimClassChar,skimIdChar,skimWrappedAttrs,skimRuby,skimAttr,skimInlineTagChar

syn keyword skimDocType contained html 5 1.1 strict frameset mobile basic transitional
syn match skimDocTypeKeyword "^\s*\(doctype\)\s\+" nextgroup=skimDocType

syn keyword skimTodo FIXME TODO NOTE OPTIMIZE XXX contained
syn keyword htmlTagName contained script

syn match skimTag "\w\+[><]*" contained contains=htmlTagName nextgroup=@skimComponent
syn match skimIdChar "#{\@!" contained nextgroup=skimId
syn match skimId "\%(\w\|-\)\+" contained nextgroup=@skimComponent
syn match skimClassChar "\." contained nextgroup=skimClass
syn match skimClass "\%(\w\|-\)\+" contained nextgroup=@skimComponent
syn match skimInlineTagChar "\s*:\s*" contained nextgroup=skimTag,skimClassChar,skimIdChar

syn region skimWrappedAttrs matchgroup=skimWrappedAttrsDelimiter start="\s*{\s*" skip="}\s*\"" end="\s*}\s*" contained contains=skimAttr nextgroup=skimRuby
syn region skimWrappedAttrs matchgroup=skimWrappedAttrsDelimiter start="\s*\[\s*" end="\s*\]\s*" contained contains=skimAttr nextgroup=skimRuby
syn region skimWrappedAttrs matchgroup=skimWrappedAttrsDelimiter start="\s*(\s*" end="\s*)\s*" contained contains=skimAttr nextgroup=skimRuby

syn match skimAttr "\s*\%(\w\|-\)\+\s*" contained contains=htmlArg nextgroup=skimAttrAssignment
syn match skimAttrAssignment "\s*=\s*" contained nextgroup=skimWrappedAttrValue,skimAttrString

syn region skimWrappedAttrValue matchgroup=skimWrappedAttrValueDelimiter start="{" end="}" contained contains=skimAttrString,@skimRubyTop nextgroup=skimAttr,skimRuby,skimInlineTagChar
syn region skimWrappedAttrValue matchgroup=skimWrappedAttrValueDelimiter start="\[" end="\]" contained contains=skimAttrString,@skimRubyTop nextgroup=skimAttr,skimRuby,skimInlineTagChar
syn region skimWrappedAttrValue matchgroup=skimWrappedAttrValueDelimiter start="(" end=")" contained contains=skimAttrString,@skimRubyTop nextgroup=skimAttr,skimRuby,skimInlineTagChar

syn region skimAttrString start=+\s*"+ skip=+\%(\\\\\)*\\"+ end=+"\s*+ contained contains=skimInterpolation,skimInterpolationEscape nextgroup=skimAttr,skimRuby,skimInlineTagChar
syn region skimAttrString start=+\s*'+ skip=+\%(\\\\\)*\\"+ end=+'\s*+ contained contains=skimInterpolation,skimInterpolationEscape nextgroup=skimAttr,skimRuby,skimInlineTagChar

syn region skimInnerAttrString start=+\s*"+ skip=+\%(\\\\\)*\\"+ end=+"\s*+ contained contains=skimInterpolation,skimInterpolationEscape nextgroup=skimAttr
syn region skimInnerAttrString start=+\s*'+ skip=+\%(\\\\\)*\\"+ end=+'\s*+ contained contains=skimInterpolation,skimInterpolationEscape nextgroup=skimAttr

syn region skimInterpolation matchgroup=skimInterpolationDelimiter start="#{" end="}" contains=@hamlRubyTop containedin=javascriptStringS,javascriptStringD,skimWrappedAttrs
syn region skimInterpolation matchgroup=skimInterpolationDelimiter start="#{{" end="}}" contains=@hamlRubyTop containedin=javascriptStringS,javascriptStringD,skimWrappedAttrs
syn match skimInterpolationEscape "\\\@<!\%(\\\\\)*\\\%(\\\ze#{\|#\ze{\)"

syn region skimRuby matchgroup=skimRubyOutputChar start="\s*[=]\==[']\=" skip=",\s*$" end="$" contained contains=@skimRubyTop keepend
syn region skimRuby matchgroup=skimRubyChar start="\s*-" skip=",\s*$" end="$" contained contains=@skimRubyTop keepend

syn match skimComment /^\(\s*\)[/].*\(\n\1\s.*\)*/ contains=skimTodo
syn match skimText /^\(\s*\)[`|'].*\(\n\1\s.*\)*/

syn match skimFilter /\s*\w\+:\s*/ contained
syn match skimHaml /^\(\s*\)\<haml:\>.*\(\n\1\s.*\)*/ contains=@skimHaml,skimFilter

syn match skimIEConditional "\%(^\s*/\)\@<=\[\s*if\>[^]]*]" contained containedin=skimComment

hi def link skimAttrString String
hi def link skimBegin String
hi def link skimClass Type
hi def link skimAttr Type
hi def link skimClassChar Type
hi def link skimComment Comment
hi def link skimDocType Identifier
hi def link skimDocTypeKeyword Keyword
hi def link skimFilter Keyword
hi def link skimIEConditional SpecialComment
hi def link skimId Identifier
hi def link skimIdChar Identifier
hi def link skimInnerAttrString String
hi def link skimInterpolationDelimiter Delimiter
hi def link skimRubyChar Special
hi def link skimRubyOutputChar Special
hi def link skimText String
hi def link skimTodo Todo
hi def link skimWrappedAttrValueDelimiter Delimiter
hi def link skimWrappedAttrsDelimiter Delimiter
hi def link skimInlineTagChar Delimiter

let b:current_syntax = "skim"

0 comments on commit b2e618f

Please sign in to comment.