CLI config/dotfiles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.7 KiB

  1. " Vim indent file
  2. " Language: Pug
  3. " Maintainer: Joshua Borton
  4. " Credits: Tim Pope (vim-pug)
  5. " Last Change: 2010 Sep 22
  6. if exists("b:did_indent")
  7. finish
  8. endif
  9. unlet! b:did_indent
  10. let b:did_indent = 1
  11. setlocal autoindent
  12. setlocal indentexpr=GetPugIndent()
  13. setlocal indentkeys=o,O,*<Return>,},],0),!^F
  14. " Only define the function once.
  15. if exists("*GetPugIndent")
  16. finish
  17. endif
  18. let s:attributes = '\%((.\{-\})\)'
  19. let s:tag = '\([%.#][[:alnum:]_-]\+\|'.s:attributes.'\)*[<>]*'
  20. if !exists('g:pug_self_closing_tags')
  21. let g:pug_self_closing_tags = 'meta|link|img|hr|br|input'
  22. endif
  23. setlocal formatoptions+=r
  24. setlocal comments+=n:\|
  25. function! GetPugIndent()
  26. let lnum = prevnonblank(v:lnum-1)
  27. if lnum == 0
  28. return 0
  29. endif
  30. let line = substitute(getline(lnum),'\s\+$','','')
  31. let cline = substitute(substitute(getline(v:lnum),'\s\+$','',''),'^\s\+','','')
  32. let lastcol = strlen(line)
  33. let line = substitute(line,'^\s\+','','')
  34. let indent = indent(lnum)
  35. let cindent = indent(v:lnum)
  36. let increase = indent + &sw
  37. if indent == indent(lnum)
  38. let indent = cindent <= indent ? -1 : increase
  39. endif
  40. let group = synIDattr(synID(lnum,lastcol,1),'name')
  41. if line =~ '^!!!'
  42. return indent
  43. elseif line =~ '^/\%(\[[^]]*\]\)\=$'
  44. return increase
  45. elseif line =~ '^\%(if\|else\|unless\|for\|each\|block\|mixin\|append\|case\|when\)'
  46. return increase
  47. elseif line =~ '^'.s:tag.'[&!]\=[=~-].*,\s*$'
  48. return increase
  49. elseif line == '-#'
  50. return increase
  51. elseif line =~? '^\v%('.g:pug_self_closing_tags.')>'
  52. return indent
  53. elseif group =~? '\v^%(pugAttributesDelimiter|pugClass|pugId|htmlTagName|htmlSpecialTagName|pugFilter|pugTagBlockChar)$'
  54. return increase
  55. else
  56. return indent
  57. endif
  58. endfunction
  59. " vim:set sw=2: