blob: d87b371fdd6bfb36d558e03e3840419d095fee16 [file] [log] [blame]
Bram Moolenaarc236c162008-07-13 17:41:49 +00001" Vim indent file
Bram Moolenaar7a329912010-05-21 12:05:36 +02002" Language: Sass
3" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
Bram Moolenaar89bcfda2016-08-30 23:26:57 +02004" Last Change: 2016 Aug 29
Bram Moolenaarc236c162008-07-13 17:41:49 +00005
6if exists("b:did_indent")
7 finish
8endif
9let b:did_indent = 1
10
11setlocal autoindent sw=2 et
12setlocal indentexpr=GetSassIndent()
13setlocal indentkeys=o,O,*<Return>,<:>,!^F
14
15" Only define the function once.
16if exists("*GetSassIndent")
17 finish
18endif
19
Bram Moolenaar543b7ef2013-06-01 14:50:56 +020020let s:property = '^\s*:\|^\s*[[:alnum:]#{}-]\+\%(:\|\s*=\)'
21let s:extend = '^\s*\%(@extend\|@include\|+\)'
Bram Moolenaarc236c162008-07-13 17:41:49 +000022
23function! GetSassIndent()
24 let lnum = prevnonblank(v:lnum-1)
25 let line = substitute(getline(lnum),'\s\+$','','')
26 let cline = substitute(substitute(getline(v:lnum),'\s\+$','',''),'^\s\+','','')
27 let lastcol = strlen(line)
28 let line = substitute(line,'^\s\+','','')
29 let indent = indent(lnum)
30 let cindent = indent(v:lnum)
Bram Moolenaar543b7ef2013-06-01 14:50:56 +020031 if line !~ s:property && line !~ s:extend && cline =~ s:property
Bram Moolenaar89bcfda2016-08-30 23:26:57 +020032 return indent + (exists('*shiftwidth') ? shiftwidth() : &sw)
Bram Moolenaarc236c162008-07-13 17:41:49 +000033 else
34 return -1
35 endif
36endfunction
37
38" vim:set sw=2: