mirror of
https://github.com/Raimondi/delimitMate.git
synced 2025-12-07 21:24:51 +08:00
Add :DelimitMateOn, :DelimitMateOff & remove s:DelimitMateSwitch().
This commit is contained in:
@@ -24,6 +24,10 @@ endif
|
|||||||
let s:loaded_delimitMate = 1
|
let s:loaded_delimitMate = 1
|
||||||
let delimitMate_version = "2.7"
|
let delimitMate_version = "2.7"
|
||||||
|
|
||||||
|
"}}}
|
||||||
|
|
||||||
|
" Functions: {{{
|
||||||
|
|
||||||
function! s:option_init(name, default) "{{{
|
function! s:option_init(name, default) "{{{
|
||||||
let b = exists("b:delimitMate_" . a:name)
|
let b = exists("b:delimitMate_" . a:name)
|
||||||
let g = exists("g:delimitMate_" . a:name)
|
let g = exists("g:delimitMate_" . a:name)
|
||||||
@@ -141,10 +145,6 @@ function! s:init() "{{{
|
|||||||
return 1
|
return 1
|
||||||
endfunction "}}} Init()
|
endfunction "}}} Init()
|
||||||
|
|
||||||
"}}}
|
|
||||||
|
|
||||||
" Functions: {{{
|
|
||||||
|
|
||||||
function! s:g(...) " {{{
|
function! s:g(...) " {{{
|
||||||
return call('delimitMate#Get', a:000)
|
return call('delimitMate#Get', a:000)
|
||||||
endfunction " }}}
|
endfunction " }}}
|
||||||
@@ -177,7 +177,6 @@ function! s:Map() "{{{
|
|||||||
endtry
|
endtry
|
||||||
|
|
||||||
let b:delimitMate_enabled = 1
|
let b:delimitMate_enabled = 1
|
||||||
|
|
||||||
endfunction "}}} Map()
|
endfunction "}}} Map()
|
||||||
|
|
||||||
function! s:Unmap() " {{{
|
function! s:Unmap() " {{{
|
||||||
@@ -216,49 +215,49 @@ function! s:TestMappingsDo() "{{{
|
|||||||
0
|
0
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
function! s:DelimitMateDo(...) "{{{
|
function! s:setup(...) "{{{
|
||||||
|
let swap = a:0 && a:1 == 2
|
||||||
|
let enable = a:0 && a:1
|
||||||
|
let disable = a:0 && !a:1
|
||||||
" First, remove all magic, if needed:
|
" First, remove all magic, if needed:
|
||||||
if exists("b:delimitMate_enabled") && b:delimitMate_enabled == 1
|
if get(b:, 'delimitMate_enabled', 0)
|
||||||
call s:Unmap()
|
call s:Unmap()
|
||||||
|
" Switch
|
||||||
|
if swap
|
||||||
|
echo "delimitMate is disabled."
|
||||||
|
return
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
" Check if this file type is excluded:
|
if disable
|
||||||
if exists("g:delimitMate_excluded_ft") &&
|
" Just disable the mappings.
|
||||||
\ index(split(g:delimitMate_excluded_ft, ','), &filetype, 0, 1) >= 0
|
return
|
||||||
" Finish here:
|
|
||||||
return 1
|
|
||||||
endif
|
endif
|
||||||
" Check if user tried to disable using b:loaded_delimitMate
|
if !a:0
|
||||||
if exists("b:loaded_delimitMate")
|
" Check if this file type is excluded:
|
||||||
return 1
|
if exists("g:delimitMate_excluded_ft") &&
|
||||||
|
\ index(split(g:delimitMate_excluded_ft, ','), &filetype, 0, 1) >= 0
|
||||||
|
" Finish here:
|
||||||
|
return 1
|
||||||
|
endif
|
||||||
|
" Check if user tried to disable using b:loaded_delimitMate
|
||||||
|
if exists("b:loaded_delimitMate")
|
||||||
|
return 1
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
" Initialize settings:
|
" Initialize settings:
|
||||||
if ! s:init()
|
if ! s:init()
|
||||||
" Something went wrong.
|
" Something went wrong.
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
" Now, add magic:
|
if enable || swap || !get(g:, 'delimitMate_offByDefault', 0)
|
||||||
if !exists("g:delimitMate_offByDefault") || !g:delimitMate_offByDefault
|
" Now, add magic:
|
||||||
call s:Map()
|
call s:Map()
|
||||||
endif
|
if a:0
|
||||||
if a:0 > 0
|
echo "delimitMate is enabled."
|
||||||
echo "delimitMate has been reset."
|
endif
|
||||||
endif
|
endif
|
||||||
endfunction "}}}
|
endfunction "}}}
|
||||||
|
|
||||||
function! s:DelimitMateSwitch() "{{{
|
|
||||||
if exists("b:delimitMate_enabled") && b:delimitMate_enabled
|
|
||||||
call s:Unmap()
|
|
||||||
echo "delimitMate has been disabled."
|
|
||||||
else
|
|
||||||
call s:Unmap()
|
|
||||||
call s:init()
|
|
||||||
call s:Map()
|
|
||||||
echo "delimitMate has been enabled."
|
|
||||||
endif
|
|
||||||
endfunction "}}}
|
|
||||||
"}}}
|
|
||||||
|
|
||||||
" Mappers: {{{
|
|
||||||
function! s:TriggerAbb() "{{{
|
function! s:TriggerAbb() "{{{
|
||||||
if v:version < 703
|
if v:version < 703
|
||||||
\ || ( v:version == 703 && !has('patch489') )
|
\ || ( v:version == 703 && !has('patch489') )
|
||||||
@@ -364,16 +363,17 @@ endfunction "}}}
|
|||||||
|
|
||||||
" Commands: {{{
|
" Commands: {{{
|
||||||
|
|
||||||
call s:DelimitMateDo()
|
|
||||||
|
|
||||||
" Let me refresh without re-loading the buffer:
|
" Let me refresh without re-loading the buffer:
|
||||||
command! -bar DelimitMateReload call s:DelimitMateDo(1)
|
command! -bar DelimitMateReload call s:setup(1)
|
||||||
|
|
||||||
" Quick test:
|
" Quick test:
|
||||||
command! -bar DelimitMateTest call s:TestMappingsDo()
|
command! -bar DelimitMateTest call s:TestMappingsDo()
|
||||||
|
|
||||||
" Switch On/Off:
|
" Switch On/Off:
|
||||||
command! -bar DelimitMateSwitch call s:DelimitMateSwitch()
|
command! -bar DelimitMateSwitch call s:setup(2)
|
||||||
|
" Enable mappings:
|
||||||
|
command! -bar DelimitMateOn call s:setup(1)
|
||||||
|
" Disable mappings:
|
||||||
|
command! -bar DelimitMateOff call s:setup(0)
|
||||||
|
|
||||||
"}}}
|
"}}}
|
||||||
|
|
||||||
" Autocommands: {{{
|
" Autocommands: {{{
|
||||||
@@ -381,13 +381,14 @@ command! -bar DelimitMateSwitch call s:DelimitMateSwitch()
|
|||||||
augroup delimitMate
|
augroup delimitMate
|
||||||
au!
|
au!
|
||||||
" Run on file type change.
|
" Run on file type change.
|
||||||
"autocmd VimEnter * autocmd FileType * call <SID>DelimitMateDo()
|
au FileType * call <SID>setup()
|
||||||
autocmd FileType * call <SID>DelimitMateDo()
|
|
||||||
|
au VimEnter * call <SID>setup()
|
||||||
|
|
||||||
" Run on new buffers.
|
" Run on new buffers.
|
||||||
autocmd BufNewFile,BufRead,BufEnter *
|
au BufNewFile,BufRead,BufEnter *
|
||||||
\ if !exists('b:delimitMate_was_here') |
|
\ if !exists('b:delimitMate_was_here') |
|
||||||
\ call <SID>DelimitMateDo() |
|
\ call <SID>setup() |
|
||||||
\ let b:delimitMate_was_here = 1 |
|
\ let b:delimitMate_was_here = 1 |
|
||||||
\ endif
|
\ endif
|
||||||
augroup END
|
augroup END
|
||||||
|
|||||||
Reference in New Issue
Block a user