Split Init() and simplify the set-up process.

This commit is contained in:
Israel Chauca Fuentes
2010-06-16 01:37:08 -05:00
parent 740fc90ae7
commit 3652ba24e3
2 changed files with 33 additions and 18 deletions

View File

@@ -103,10 +103,12 @@ function! delimitMate#Init() "{{{
let b:delimitMate_buffer = []
" }}}
let b:loaded_delimitMate = 1
" Set mappings: {{{
call delimitMate#UnMap()
endfunction "}}} Init()
function! delimitMate#Map() "{{{
" Set mappings:
try
let save_cpo = &cpo
let save_keymap = &keymap
@@ -124,11 +126,9 @@ function! delimitMate#Init() "{{{
let &keymap = save_keymap
endtry
let b:loaded_delimitMate = 1
let b:delimitMate_enabled = 1
" }}}
endfunction "}}} Init()
endfunction "}}} Map()
function! delimitMate#ShouldJump() "{{{
" Returns 1 if the next character is a closing delimiter.

View File

@@ -43,6 +43,8 @@ function! s:TestMappingsDo() "{{{
for a in [0,1]
let b:delimitMate_autoclose = a
call delimitMate#Init()
call delimitMate#UnMap()
call delimitMate#Map()
call delimitMate#TestMappings()
exec "normal i\<CR>"
endfor
@@ -56,28 +58,41 @@ function! s:TestMappingsDo() "{{{
endfunction "}}}
function! s:DelimitMateDo(...) "{{{
if exists("g:delimitMate_excluded_ft")
" Check if this file type is excluded:
if index(split(g:delimitMate_excluded_ft, ','), &filetype, 0, 1) >= 0
if !exists('b:delimitMate_enabled')
call delimitMate#Init()
endif
call delimitMate#UnMap()
return 1
endif
endif
" Initialize settings:
call delimitMate#Init()
" Check if this file type is excluded:
if exists("g:delimitMate_excluded_ft") &&
\ index(split(g:delimitMate_excluded_ft, ','), &filetype, 0, 1) >= 0
" Remove any magic:
call delimitMate#UnMap()
" Finish here:
return 1
endif
" First, remove all magic, if needed:
if exists("b:delimitMate_enabled") && b:delimitMate_enabled == 1
call delimitMate#UnMap()
endif
" Now, add magic:
call delimitMate#Map()
if a:0 > 0
echo "delimitMate has been reset."
endif
endfunction "}}}
function! s:DelimitMateSwitch() "{{{
if b:delimitMate_enabled
call delimitMate#Init()
if exists("b:delimitMate_enabled") && b:delimitMate_enabled
call delimitMate#UnMap()
echo "delimitMate has been disabled."
else
call delimitMate#Init()
call delimitMate#UnMap()
call delimitMate#Map()
echo "delimitMate has been enabled."
endif
endfunction "}}}