neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

css.vim (1813B)


      1 " Vim indent file
      2 " Language:		CSS
      3 " Maintainer:		Doug Kearns <dougkearns@gmail.com>
      4 " Previous Maintainer:	Nikolai Weibull <now@bitwi.se>
      5 " Last Change:		24 Sep 2021
      6 
      7 " Use of shiftwidth() added by Oleg Zubchenko.
      8 
      9 if exists("b:did_indent")
     10  finish
     11 endif
     12 let b:did_indent = 1
     13 
     14 setlocal indentexpr=GetCSSIndent()
     15 setlocal indentkeys=0{,0},!^F,o,O
     16 setlocal nosmartindent
     17 
     18 let b:undo_indent = "setl inde< indk< si<"
     19 
     20 if exists("*GetCSSIndent")
     21  finish
     22 endif
     23 let s:keepcpo= &cpo
     24 set cpo&vim
     25 
     26 function s:prevnonblanknoncomment(lnum)
     27  let lnum = a:lnum
     28  while lnum > 1
     29    let lnum = prevnonblank(lnum)
     30    let line = getline(lnum)
     31    if line =~ '\*/'
     32      while lnum > 1 && line !~ '/\*'
     33        let lnum -= 1
     34      endwhile
     35      if line =~ '^\s*/\*'
     36        let lnum -= 1
     37      else
     38        break
     39      endif
     40    else
     41      break
     42    endif
     43  endwhile
     44  return lnum
     45 endfunction
     46 
     47 function s:count_braces(lnum, count_open)
     48  let n_open = 0
     49  let n_close = 0
     50  let line = getline(a:lnum)
     51  let pattern = '[{}]'
     52  let i = match(line, pattern)
     53  while i != -1
     54    if synIDattr(synID(a:lnum, i + 1, 0), 'name') !~ 'css\%(Comment\|StringQ\{1,2}\)'
     55      if line[i] == '{'
     56        let n_open += 1
     57      elseif line[i] == '}'
     58        if n_open > 0
     59          let n_open -= 1
     60        else
     61          let n_close += 1
     62        endif
     63      endif
     64    endif
     65    let i = match(line, pattern, i + 1)
     66  endwhile
     67  return a:count_open ? n_open : n_close
     68 endfunction
     69 
     70 function GetCSSIndent()
     71  let line = getline(v:lnum)
     72  if line =~ '^\s*\*'
     73    return cindent(v:lnum)
     74  endif
     75 
     76  let pnum = s:prevnonblanknoncomment(v:lnum - 1)
     77  if pnum == 0
     78    return 0
     79  endif
     80 
     81  return indent(pnum) + s:count_braces(pnum, 1) * shiftwidth()
     82        \ - s:count_braces(v:lnum, 0) * shiftwidth()
     83 endfunction
     84 
     85 let &cpo = s:keepcpo
     86 unlet s:keepcpo