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.
 
 

64 lines
2.2 KiB

  1. "=============================================================================
  2. " FILE: snippets.vim
  3. " AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
  4. " Last Modified: 21 Oct 2012.
  5. " License: MIT license {{{
  6. " Permission is hereby granted, free of charge, to any person obtaining
  7. " a copy of this software and associated documentation files (the
  8. " "Software"), to deal in the Software without restriction, including
  9. " without limitation the rights to use, copy, modify, merge, publish,
  10. " distribute, sublicense, and/or sell copies of the Software, and to
  11. " permit persons to whom the Software is furnished to do so, subject to
  12. " the following conditions:
  13. "
  14. " The above copyright notice and this permission notice shall be included
  15. " in all copies or substantial portions of the Software.
  16. "
  17. " THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  18. " OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. " MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  20. " IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  21. " CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  22. " TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  23. " SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. " }}}
  25. "=============================================================================
  26. " Only load this indent file when no other was loaded.
  27. if exists('b:did_indent')
  28. finish
  29. endif
  30. let b:did_indent = 1
  31. let s:save_cpo = &cpo
  32. set cpo&vim
  33. if !exists('b:undo_indent')
  34. let b:undo_indent = ''
  35. else
  36. let b:undo_indent = '|'
  37. endif
  38. setlocal indentexpr=SnippetsIndent()
  39. function! SnippetsIndent() "{{{
  40. let line = getline('.')
  41. let prev_line = (line('.') == 1)? '' : getline(line('.')-1)
  42. if prev_line =~ '^\s*$'
  43. return 0
  44. elseif prev_line =~ '^\%(include\|snippet\|abbr\|prev_word\|delete\|alias\|options\)'
  45. \&& line !~ '^\s*\%(include\|snippet\|abbr\|prev_word\|delete\|alias\|options\)'
  46. return &shiftwidth
  47. else
  48. return match(line, '\S')
  49. endif
  50. endfunction"}}}
  51. let b:undo_indent .= '
  52. \ setlocal indentexpr<
  53. \'
  54. let &cpo = s:save_cpo
  55. unlet s:save_cpo