Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added ftplugin and indent files #6

Merged
2 commits merged into from

1 participant

@mtimkovich

Copied generously from vim-haml, but it gets the job done. Will need to be improved on, but it's a start.

@ghost ghost merged commit ab5f147 into slim-template:master
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 15, 2011
  1. @mtimkovich
  2. @mtimkovich
This page is out of date. Refresh to see the latest.
Showing with 82 additions and 0 deletions.
  1. +7 −0 ftplugin/slim.vim
  2. +75 −0 indent/slim.vim
View
7 ftplugin/slim.vim
@@ -0,0 +1,7 @@
+setlocal tabstop=2
+setlocal softtabstop=2
+setlocal shiftwidth=2
+setlocal textwidth=80
+setlocal smarttab
+setlocal expandtab
+setlocal smartindent
View
75 indent/slim.vim
@@ -0,0 +1,75 @@
+" Vim indent file
+" Language: Slim
+
+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=GetSlimIndent()
+setlocal indentkeys=o,O,*<Return>,},],0),!^F,=end,=else,=elsif,=rescue,=ensure,=when
+
+" Only define the function once.
+if exists("*GetSlimIndent")
+ 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! GetSlimIndent()
+ 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:
Something went wrong with that request. Please try again.