From 8d720b8932eb3830ef484a255a7fb5fddac53cdd Mon Sep 17 00:00:00 2001 From: Israel Chauca Fuentes Date: Tue, 11 May 2010 01:27:40 -0500 Subject: [PATCH] Implemented command to switch on/off. --- autoload/delimitMate.vim | 119 +++++++++++++++++++++++++++++++++++ doc/delimitMate.txt | 18 +++--- plugin/delimitMate.vim | 133 ++++----------------------------------- 3 files changed, 140 insertions(+), 130 deletions(-) diff --git a/autoload/delimitMate.vim b/autoload/delimitMate.vim index 701cc10..4af2fd2 100644 --- a/autoload/delimitMate.vim +++ b/autoload/delimitMate.vim @@ -6,6 +6,123 @@ " Manual: Read ":help delimitMate". " Utilities {{{ +function! delimitMate#Init() "{{{ + + " delimitMate_autoclose {{{ + if !exists("b:delimitMate_autoclose") && !exists("g:delimitMate_autoclose") + let b:delimitMate_autoclose = 1 + elseif !exists("b:delimitMate_autoclose") && exists("g:delimitMate_autoclose") + let b:delimitMate_autoclose = g:delimitMate_autoclose + else + " Nothing to do. + endif " }}} + + " delimitMate_matchpairs {{{ + if !exists("b:delimitMate_matchpairs") && !exists("g:delimitMate_matchpairs") + let s:matchpairs_temp = &matchpairs + elseif exists("b:delimitMate_matchpairs") + let s:matchpairs_temp = b:delimitMate_matchpairs + else + let s:matchpairs_temp = g:delimitMate_matchpairs + endif " }}} + + " delimitMate_quotes {{{ + if exists("b:delimitMate_quotes") + let s:quotes = split(b:delimitMate_quotes) + elseif exists("g:delimitMate_quotes") + let s:quotes = split(g:delimitMate_quotes) + else + let s:quotes = split("\" ' `") + endif + let b:delimitMate_quotes_list = s:quotes " }}} + + " delimitMate_excluded_regions {{{ + if exists("b:delimitMate_excluded_regions") + let s:excluded_regions = b:delimitMate_excluded_regions + elseif exists("g:delimitMate_excluded_regions") + let s:excluded_regions = g:delimitMate_excluded_regions + else + let s:excluded_regions = "Comment" + endif + let b:delimitMate_excluded_regions_list = split(s:excluded_regions, ',\s*') + let b:delimitMate_excluded_regions_enabled = len(b:delimitMate_excluded_regions_list) " }}} + + " delimitMate_visual_leader {{{ + if !exists("b:delimitMate_visual_leader") && !exists("g:delimitMate_visual_leader") + let b:delimitMate_visual_leader = exists('b:maplocalleader') ? b:maplocalleader : + \ exists('g:mapleader') ? g:mapleader : "\\" + elseif !exists("b:delimitMate_visual_leader") && exists("g:delimitMate_visual_leader") + let b:delimitMate_visual_leader = g:delimitMate_visual_leader + else + " Nothing to do. + endif " }}} + + " delimitMate_expand_space {{{ + if !exists("b:delimitMate_expand_space") && !exists("g:delimitMate_expand_space") + let b:delimitMate_expand_space = 0 + elseif !exists("b:delimitMate_expand_space") && exists("g:delimitMate_expand_space") + let b:delimitMate_expand_space = g:delimitMate_expand_space + else + " Nothing to do. + endif " }}} + + " delimitMate_expand_cr {{{ + if !exists("b:delimitMate_expand_cr") && !exists("g:delimitMate_expand_cr") + let b:delimitMate_expand_cr = 0 + elseif !exists("b:delimitMate_expand_cr") && exists("g:delimitMate_expand_cr") + let b:delimitMate_expand_cr = g:delimitMate_expand_cr + else + " Nothing to do. + endif " }}} + + " delimitMate_smart_quotes {{{ + if !exists("b:delimitMate_smart_quotes") && !exists("g:delimitMate_smart_quotes") + let b:delimitMate_smart_quotes = 1 + elseif !exists("b:delimitMate_smart_quotes") && exists("g:delimitMate_smart_quotes") + let b:delimitMate_smart_quotes = split(g:delimitMate_smart_quotes) + else + " Nothing to do. + endif " }}} + + " delimitMate_apostrophes {{{ + if !exists("b:delimitMate_apostrophes") && !exists("g:delimitMate_apostrophes") + "let s:apostrophes = split("n't:'s:'re:'m:'d:'ll:'ve:s'",':') + let s:apostrophes = [] + elseif !exists("b:delimitMate_apostrophes") && exists("g:delimitMate_apostrophes") + let s:apostrophes = split(g:delimitMate_apostrophes) + else + let s:apostrophes = split(b:delimitMate_apostrophes) + endif + let b:delimitMate_apostrophes_list = s:apostrophes " }}} + + " delimitMate_tab2exit {{{ + if !exists("b:delimitMate_tab2exit") && !exists("g:delimitMate_tab2exit") + let b:delimitMate_tab2exit = 1 + elseif !exists("b:delimitMate_tab2exit") && exists("g:delimitMate_tab2exit") + let b:delimitMate_tab2exit = g:delimitMate_tab2exit + else + " Nothing to do. + endif " }}} + + let b:delimitMate_matchpairs_list = split(s:matchpairs_temp, ',') + let b:delimitMate_left_delims = split(s:matchpairs_temp, ':.,\=') + let b:delimitMate_right_delims = split(s:matchpairs_temp, ',\=.:') + + let b:delimitMate_buffer = [] + + call delimitMate#UnMap() + if b:delimitMate_autoclose + call delimitMate#AutoClose() + else + call delimitMate#NoAutoClose() + endif + call delimitMate#VisualMaps() + call delimitMate#ExtraMappings() + + let b:loaded_delimitMate = 1 + let b:delimitMate_enabled = 1 +endfunction "}}} Init() + function! delimitMate#ShouldJump() "{{{ let col = col('.') let lcol = col('$') @@ -512,6 +629,8 @@ function! delimitMate#UnMap() " {{{ exec 'silent! vunmap ' . vleader . map endif endfor + + let b:delimitMate_enabled = 0 endfunction " }}} delimitMate#UnMap() "}}} diff --git a/doc/delimitMate.txt b/doc/delimitMate.txt index c0fc9f2..b581225 100644 --- a/doc/delimitMate.txt +++ b/doc/delimitMate.txt @@ -488,12 +488,12 @@ This script was inspired by the auto-completion of delimiters of TextMate. Version Date Release notes ~ |---------|------------|-----------------------------------------------------| - 2.1 2010-05-10 - Most of the functions have been moved to an + 2.1 2010-05-10 * - Most of the functions have been moved to an autoload script to avoid loading unnecessary ones. - Fixed a problem with the redo command. - Many small fixes. |---------|------------|-----------------------------------------------------| - 2.0 2010-04-01 New features: + 2.0 2010-04-01 * New features: - All features are redo/undo-wise safe. - A single quote typed after an alphanumeric character is considered an apostrophe and one @@ -512,24 +512,24 @@ This script was inspired by the auto-completion of delimiters of TextMate. - s:vars were being used to store buffer options. |---------|------------|-----------------------------------------------------| - 1.6 2009-10-10 Now delimitMate tries to fix the balancing of single + 1.6 2009-10-10 * Now delimitMate tries to fix the balancing of single quotes when used as apostrophes. You can read |delimitMate_apostrophes| for details. Fixed an error when |b:delimitMate_expand_space| wasn't set but |delimitMate_expand_space| wasn't. |---------|------------|-----------------------------------------------------| - 1.5 2009-10-05 Fix: delimitMate should work correctly for files + 1.5 2009-10-05 * Fix: delimitMate should work correctly for files passed as arguments to Vim. Thanks to Ben Beuchler for helping to nail this bug. |---------|------------|-----------------------------------------------------| - 1.4 2009-09-27 Fix: delimitMate is now enabled on new buffers even + 1.4 2009-09-27 * Fix: delimitMate is now enabled on new buffers even if they don't have set the file type option or were opened directly from the terminal. |---------|------------|-----------------------------------------------------| - 1.3 2009-09-24 Now local options can be used along with autocmd + 1.3 2009-09-24 * Now local options can be used along with autocmd for specific file type configurations. Fixes: - Unnamed register content is not lost on visual @@ -538,7 +538,7 @@ This script was inspired by the auto-completion of delimiters of TextMate. - Wrapping a single empty line works as expected. |---------|------------|-----------------------------------------------------| - 1.2 2009-09-07 Fixes: + 1.2 2009-09-07 * Fixes: - When inside nested empty pairs, deleting the innermost left delimiter would delete all right contiguous delimiters. @@ -549,12 +549,12 @@ This script was inspired by the auto-completion of delimiters of TextMate. have the mappings set. |---------|------------|-----------------------------------------------------| - 1.1 2009-08-25 Fixed an error that ocurred when mapleader wasn't + 1.1 2009-08-25 * Fixed an error that ocurred when mapleader wasn't set and added support for GetLatestScripts auto-detection. |---------|------------|-----------------------------------------------------| - 1.0 2009-08-23 Initial upload. + 1.0 2009-08-23 * Initial upload. |---------|------------|-----------------------------------------------------| diff --git a/plugin/delimitMate.vim b/plugin/delimitMate.vim index 073020d..9795a08 100644 --- a/plugin/delimitMate.vim +++ b/plugin/delimitMate.vim @@ -30,123 +30,6 @@ let delimitMate_version = '2.1' "}}} " Tools: {{{ -function! s:Init() "{{{ - - let b:loaded_delimitMate = 1 - - " delimitMate_autoclose {{{ - if !exists("b:delimitMate_autoclose") && !exists("g:delimitMate_autoclose") - let b:delimitMate_autoclose = 1 - elseif !exists("b:delimitMate_autoclose") && exists("g:delimitMate_autoclose") - let b:delimitMate_autoclose = g:delimitMate_autoclose - else - " Nothing to do. - endif " }}} - - " delimitMate_matchpairs {{{ - if !exists("b:delimitMate_matchpairs") && !exists("g:delimitMate_matchpairs") - let s:matchpairs_temp = &matchpairs - elseif exists("b:delimitMate_matchpairs") - let s:matchpairs_temp = b:delimitMate_matchpairs - else - let s:matchpairs_temp = g:delimitMate_matchpairs - endif " }}} - - " delimitMate_quotes {{{ - if exists("b:delimitMate_quotes") - let s:quotes = split(b:delimitMate_quotes) - elseif exists("g:delimitMate_quotes") - let s:quotes = split(g:delimitMate_quotes) - else - let s:quotes = split("\" ' `") - endif - let b:delimitMate_quotes_list = s:quotes " }}} - - " delimitMate_excluded_regions {{{ - if exists("b:delimitMate_excluded_regions") - let s:excluded_regions = b:delimitMate_excluded_regions - elseif exists("g:delimitMate_excluded_regions") - let s:excluded_regions = g:delimitMate_excluded_regions - else - let s:excluded_regions = "Comment" - endif - let b:delimitMate_excluded_regions_list = split(s:excluded_regions, ',\s*') - let b:delimitMate_excluded_regions_enabled = len(b:delimitMate_excluded_regions_list) " }}} - - " delimitMate_visual_leader {{{ - if !exists("b:delimitMate_visual_leader") && !exists("g:delimitMate_visual_leader") - let b:delimitMate_visual_leader = exists('b:maplocalleader') ? b:maplocalleader : - \ exists('g:mapleader') ? g:mapleader : "\\" - elseif !exists("b:delimitMate_visual_leader") && exists("g:delimitMate_visual_leader") - let b:delimitMate_visual_leader = g:delimitMate_visual_leader - else - " Nothing to do. - endif " }}} - - " delimitMate_expand_space {{{ - if !exists("b:delimitMate_expand_space") && !exists("g:delimitMate_expand_space") - let b:delimitMate_expand_space = 0 - elseif !exists("b:delimitMate_expand_space") && exists("g:delimitMate_expand_space") - let b:delimitMate_expand_space = g:delimitMate_expand_space - else - " Nothing to do. - endif " }}} - - " delimitMate_expand_cr {{{ - if !exists("b:delimitMate_expand_cr") && !exists("g:delimitMate_expand_cr") - let b:delimitMate_expand_cr = 0 - elseif !exists("b:delimitMate_expand_cr") && exists("g:delimitMate_expand_cr") - let b:delimitMate_expand_cr = g:delimitMate_expand_cr - else - " Nothing to do. - endif " }}} - - " delimitMate_smart_quotes {{{ - if !exists("b:delimitMate_smart_quotes") && !exists("g:delimitMate_smart_quotes") - let b:delimitMate_smart_quotes = 1 - elseif !exists("b:delimitMate_smart_quotes") && exists("g:delimitMate_smart_quotes") - let b:delimitMate_smart_quotes = split(g:delimitMate_smart_quotes) - else - " Nothing to do. - endif " }}} - - " delimitMate_apostrophes {{{ - if !exists("b:delimitMate_apostrophes") && !exists("g:delimitMate_apostrophes") - "let s:apostrophes = split("n't:'s:'re:'m:'d:'ll:'ve:s'",':') - let s:apostrophes = [] - elseif !exists("b:delimitMate_apostrophes") && exists("g:delimitMate_apostrophes") - let s:apostrophes = split(g:delimitMate_apostrophes) - else - let s:apostrophes = split(b:delimitMate_apostrophes) - endif - let b:delimitMate_apostrophes_list = s:apostrophes " }}} - - " delimitMate_tab2exit {{{ - if !exists("b:delimitMate_tab2exit") && !exists("g:delimitMate_tab2exit") - let b:delimitMate_tab2exit = 1 - elseif !exists("b:delimitMate_tab2exit") && exists("g:delimitMate_tab2exit") - let b:delimitMate_tab2exit = g:delimitMate_tab2exit - else - " Nothing to do. - endif " }}} - - let b:delimitMate_matchpairs_list = split(s:matchpairs_temp, ',') - let b:delimitMate_left_delims = split(s:matchpairs_temp, ':.,\=') - let b:delimitMate_right_delims = split(s:matchpairs_temp, ',\=.:') - - let b:delimitMate_buffer = [] - - call delimitMate#UnMap() - if b:delimitMate_autoclose - call delimitMate#AutoClose() - else - call delimitMate#NoAutoClose() - endif - call delimitMate#VisualMaps() - call delimitMate#ExtraMappings() - -endfunction "}}} Init() - function! s:TestMappingsDo() "{{{ if !exists("g:delimitMate_testing") silent call delimitMate#TestMappings() @@ -157,7 +40,7 @@ function! s:TestMappingsDo() "{{{ let b:delimitMate_expand_cr = i for a in [0,1] let b:delimitMate_autoclose = a - call s:Init() + call delimitMate#Init() call delimitMate#TestMappings() exec "normal i\" endfor @@ -187,12 +70,20 @@ function! s:DelimitMateDo() "{{{ let save_keymap = &keymap set keymap= set cpo&vim - call s:Init() + call delimitMate#Init() finally let &cpo = save_cpo let &keymap = save_keymap endtry endfunction "}}} + +function! s:DelimitMateSwitch() + if b:delimitMate_enabled + call delimitMate#UnMap() + else + call delimitMate#Init() + endif +endfunction "}}} " Commands: {{{ @@ -204,8 +95,8 @@ command! DelimitMateReload call s:DelimitMateDo() " Quick test: command! DelimitMateTest call s:TestMappingsDo() -"command! DelimitMateRegions echo s:excluded_regions -" Turn +" Switch On/Off: +command! DelimitMateSwitch call s:DelimitMateSwitch() " Run on file type events. "autocmd VimEnter * autocmd FileType * call DelimitMateDo()