neosnippet.vim/indent/neosnippet.vim

58 lines
1.4 KiB
VimL
Raw Permalink Normal View History

2012-02-02 04:33:35 +00:00
"=============================================================================
" FILE: snippets.vim
2017-06-15 00:11:15 +00:00
" AUTHOR: Shougo Matsushita <Shougo.Matsu at gmail.com>
" License: MIT license
2012-02-02 04:33:35 +00:00
"=============================================================================
" Only load this indent file when no other was loaded.
if exists('b:did_indent')
finish
endif
let b:did_indent = 1
if !exists('b:undo_indent')
2017-06-15 00:11:15 +00:00
let b:undo_indent = ''
2013-09-25 05:36:37 +00:00
else
2017-06-15 00:11:15 +00:00
let b:undo_indent .= '|'
2012-02-02 04:33:35 +00:00
endif
setlocal autoindent
2012-02-02 04:33:35 +00:00
setlocal indentexpr=SnippetsIndent()
2017-03-12 18:06:16 +00:00
setlocal indentkeys=o,O,=include\ ,=snippet\ ,=abbr\ ,=prev_word\ ,=delete\ ,=alias\ ,=options\ ,=regexp\ ,!^F
let b:undo_indent .= 'setlocal
\ autoindent<
\ indentexpr<
\ indentkeys<
\'
2012-02-02 04:33:35 +00:00
2016-02-08 12:48:14 +00:00
function! SnippetsIndent() abort "{{{
2017-06-15 00:11:15 +00:00
let line = getline('.')
let prev_line = (line('.') == 1)? '' : getline(line('.')-1)
let syntax = '\%(include\|snippet\|abbr\|prev_word\|delete\|alias\|options\|regexp\)\s'
let defining = '\%(snippet\|abbr\|prev_word\|alias\|options\|regexp\)\s'
"for indentkeys o,O
if s:is_empty(line)
if prev_line =~ '^' . defining
return shiftwidth()
else
return -1
endif
"for indentkeys =words
2017-06-15 00:11:15 +00:00
else
if line =~ '^\s*' . syntax
\ && (s:is_empty(prev_line)
\ || prev_line =~ '^' . defining)
return 0
2012-02-02 04:33:35 +00:00
else
2017-06-15 00:11:15 +00:00
return -1
2012-02-02 04:33:35 +00:00
endif
2017-06-15 00:11:15 +00:00
endif
2012-02-02 04:33:35 +00:00
endfunction"}}}
function! s:is_empty(line)
2017-06-15 00:11:15 +00:00
return a:line =~ '^\s*$'
endfunction