Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 1 | " Vim indent file |
Bram Moolenaar | 7a32991 | 2010-05-21 12:05:36 +0200 | [diff] [blame] | 2 | " Language: Sass |
| 3 | " Maintainer: Tim Pope <vimNOSPAM@tpope.org> |
Tim Pope | a907c91 | 2023-12-28 12:49:07 -0500 | [diff] [blame] | 4 | " Last Change: 2023 Dec 28 |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 5 | |
| 6 | if exists("b:did_indent") |
| 7 | finish |
| 8 | endif |
| 9 | let b:did_indent = 1 |
| 10 | |
Tim Pope | a907c91 | 2023-12-28 12:49:07 -0500 | [diff] [blame] | 11 | setlocal autoindent |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 12 | setlocal indentexpr=GetSassIndent() |
| 13 | setlocal indentkeys=o,O,*<Return>,<:>,!^F |
| 14 | |
Bram Moolenaar | 47c532e | 2022-03-19 15:18:53 +0000 | [diff] [blame] | 15 | let b:undo_indent = "setl ai< inde< indk<" |
| 16 | |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 17 | " Only define the function once. |
| 18 | if exists("*GetSassIndent") |
| 19 | finish |
| 20 | endif |
| 21 | |
Bram Moolenaar | 543b7ef | 2013-06-01 14:50:56 +0200 | [diff] [blame] | 22 | let s:property = '^\s*:\|^\s*[[:alnum:]#{}-]\+\%(:\|\s*=\)' |
| 23 | let s:extend = '^\s*\%(@extend\|@include\|+\)' |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 24 | |
| 25 | function! GetSassIndent() |
| 26 | let lnum = prevnonblank(v:lnum-1) |
| 27 | let line = substitute(getline(lnum),'\s\+$','','') |
| 28 | let cline = substitute(substitute(getline(v:lnum),'\s\+$','',''),'^\s\+','','') |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 29 | let line = substitute(line,'^\s\+','','') |
| 30 | let indent = indent(lnum) |
Bram Moolenaar | 543b7ef | 2013-06-01 14:50:56 +0200 | [diff] [blame] | 31 | if line !~ s:property && line !~ s:extend && cline =~ s:property |
Bram Moolenaar | 3ec574f | 2017-06-13 18:12:01 +0200 | [diff] [blame] | 32 | return indent + shiftwidth() |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 33 | else |
| 34 | return -1 |
| 35 | endif |
| 36 | endfunction |
| 37 | |
| 38 | " vim:set sw=2: |