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.
 
 

58 lines
1.4 KiB

  1. "=============================================================================
  2. " FILE: snippets.vim
  3. " AUTHOR: Shougo Matsushita <Shougo.Matsu at gmail.com>
  4. " License: MIT license
  5. "=============================================================================
  6. " Only load this indent file when no other was loaded.
  7. if exists('b:did_indent')
  8. finish
  9. endif
  10. let b:did_indent = 1
  11. if !exists('b:undo_indent')
  12. let b:undo_indent = ''
  13. else
  14. let b:undo_indent .= '|'
  15. endif
  16. setlocal autoindent
  17. setlocal indentexpr=SnippetsIndent()
  18. setlocal indentkeys=o,O,=include\ ,=snippet\ ,=abbr\ ,=prev_word\ ,=delete\ ,=alias\ ,=options\ ,=regexp\ ,!^F
  19. let b:undo_indent .= 'setlocal
  20. \ autoindent<
  21. \ indentexpr<
  22. \ indentkeys<
  23. \'
  24. function! SnippetsIndent() abort "{{{
  25. let line = getline('.')
  26. let prev_line = (line('.') == 1)? '' : getline(line('.')-1)
  27. let syntax = '\%(include\|snippet\|abbr\|prev_word\|delete\|alias\|options\|regexp\)\s'
  28. let defining = '\%(snippet\|abbr\|prev_word\|alias\|options\|regexp\)\s'
  29. "for indentkeys o,O
  30. if s:is_empty(line)
  31. if prev_line =~ '^' . defining
  32. return shiftwidth()
  33. else
  34. return -1
  35. endif
  36. "for indentkeys =words
  37. else
  38. if line =~ '^\s*' . syntax
  39. \ && (s:is_empty(prev_line)
  40. \ || prev_line =~ '^' . defining)
  41. return 0
  42. else
  43. return -1
  44. endif
  45. endif
  46. endfunction"}}}
  47. function! s:is_empty(line)
  48. return a:line =~ '^\s*$'
  49. endfunction