3 Commits
1.3 ... 1.6

Author SHA1 Message Date
Israel Chauca Fuentes
6f0c91468a == 1.6 ==
Now delimitMate tries to fix the balancing of single quotes when used as apostrophes.
Fixed an error when b:delimitMate_expand_space wasn't set but g:delimitMate_expand_space was.
2009-10-15 23:59:54 -05:00
Israel Chauca Fuentes
75b4f3b520 == 1.5 ==
Fix: delimitMate should work as expected in files passed as arguments to Vim.
2009-10-05 05:48:09 -05:00
Israel Chauca Fuentes
3ce7f7ffcf === 1.4 ===
Fix: 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.
2009-09-27 16:49:03 -05:00
2 changed files with 205 additions and 74 deletions

View File

@@ -1,13 +1,13 @@
*delimitMate.txt* Trying to keep those beasts at bay! *delimitMate.txt* Trying to keep those beasts at bay! v.1.6
REFERENCE MANUAL * REFERENCE MANUAL *delimitMate*
============================================================================== ==============================================================================
0.- CONTENTS *delimitMate-contents* 0.- CONTENTS *delimitMate-contents*
1. Introduction____________________________|delimitMate| 1. Introduction____________________________|delimitMateIntro|
2. Functionality___________________________|delimitMateFunctionality| 2. Functionality___________________________|delimitMateFunctionality|
2.1 Automatic closing & exiting________|delimitMateAutoClose| 2.1 Automatic closing & exiting________|delimitMateAutoClose|
2.2 Expansion of space and CR__________|delimitMateExpansion| 2.2 Expansion of space and CR__________|delimitMateExpansion|
@@ -16,14 +16,14 @@
3. Customization___________________________|delimitMateOptions| 3. Customization___________________________|delimitMateOptions|
3.1 Option summary_____________________|delimitMateOptionSummary| 3.1 Option summary_____________________|delimitMateOptionSummary|
3.2 Options details____________________|delimitMateOptionDetails| 3.2 Options details____________________|delimitMateOptionDetails|
4. Public commands_________________________|delimitMatePublicCommands| 4. Commands________________________________|delimitMateCommands|
5. TODO list_______________________________|delimitMateTodo| 5. TODO list_______________________________|delimitMateTodo|
6. Maintainer______________________________|delimitMateMaintainer| 6. Maintainer______________________________|delimitMateMaintainer|
7. Credits_________________________________|delimitMateCredits| 7. Credits_________________________________|delimitMateCredits|
8. History_________________________________|delimitMateHistory| 8. History_________________________________|delimitMateHistory|
============================================================================== ==============================================================================
1.- INTRODUCTION *delimitMate* 1.- INTRODUCTION *delimitMateIntro*
The delimitMate plugin tries to provide some not so dumb help in the work with The delimitMate plugin tries to provide some not so dumb help in the work with
delimiters (brackets, quotes, etc.), with some optional auto-completions and delimiters (brackets, quotes, etc.), with some optional auto-completions and
@@ -41,7 +41,7 @@ expanded to follow your coding style, you just need to define a couple of
options with the desired mappings for them. options with the desired mappings for them.
============================================================================== ==============================================================================
2. FUNCTIONALITY PROVIDED *delimitMateFunctionality* 2. FUNCTIONALITY *delimitMateFunctionality*
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
2.1 AUTOMATIC CLOSING AND EXITING *delimitMateAutoClose* 2.1 AUTOMATIC CLOSING AND EXITING *delimitMateAutoClose*
@@ -56,7 +56,7 @@ closing delimiter, the cursor is placed outside the pair to the right of the
closing delimiter. closing delimiter.
Unless |'b:delimitMate_matchpairs'| and |'b:delimitMate_quotes'|is set, this Unless |'b:delimitMate_matchpairs'| and |'b:delimitMate_quotes'|is set, this
script uses the values in '&matchpirs' to identify the pairs, and "\" ' ` " script uses the values in '&matchpairs' to identify the pairs, and ", ' and `
for quotes respectively. for quotes respectively.
The following table shows the behaviour, this applies to quotes too (the final The following table shows the behaviour, this applies to quotes too (the final
@@ -122,7 +122,7 @@ will be welcome.
e.g. (selection represented between square brackets): > e.g. (selection represented between square brackets): >
Selected text | After q" Selected text | After \"
============================================= =============================================
An [absurd] example! | An "absurd" example! An [absurd] example! | An "absurd" example!
< <
@@ -157,10 +157,14 @@ specific file types, see |delimitMateOptionDetails| for examples.
|'delimitMate_excluded_ft'| Turns off the script for the given file types. |'delimitMate_excluded_ft'| Turns off the script for the given file types.
|'delimitMate_apostrophes'| Tells delimitMate how it should "fix"
balancing of single quotes when used as
apostrophes.
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
3.2 OPTIONS DETAILS *delimitMateOptionDetails* 3.2 OPTIONS DETAILS *delimitMateOptionDetails*
Add the shown lines to your vimrc files in order to set the below options. Add the shown lines to your vimrc file in order to set the below options.
Local options take precedence over global ones and can be used along with Local options take precedence over global ones and can be used along with
autocmd to modify delimitMate's behavior for specific file types. autocmd to modify delimitMate's behavior for specific file types.
@@ -174,8 +178,8 @@ e.g.: >
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
*'delimitMate_autoclose'* *'delimitMate_autoclose'*
*'b:delimitMate_autoclose'* *'b:delimitMate_autoclose'*
Values: 0 or 1. Values: 0 or 1. ~
Default: 1 Default: 1 ~
If this option is set to 0, delimitMate will not add a closing delimiter If this option is set to 0, delimitMate will not add a closing delimiter
automagically. See |delimitMateAutoClose| for details. automagically. See |delimitMateAutoClose| for details.
@@ -186,8 +190,8 @@ e.g.: >
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
*'delimitMate_matchpairs'* *'delimitMate_matchpairs'*
*'b:delimitMate_matchpairs'* *'b:delimitMate_matchpairs'*
Values: A string with |matchpairs| syntax. Values: A string with |matchpairs| syntax. ~
Default: &matchpairs Default: &matchpairs ~
Use this option to tell delimitMate which characters should be considered Use this option to tell delimitMate which characters should be considered
matching pairs. Read |delimitMateAutoClose| for details. matching pairs. Read |delimitMateAutoClose| for details.
@@ -198,8 +202,8 @@ e.g: >
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
*'delimitMate_quotes'* *'delimitMate_quotes'*
*'b:delimitMate_quotes'* *'b:delimitMate_quotes'*
Values: A string of characters separated by spaces. Values: A string of characters separated by spaces. ~
Default: "\" ' `" Default: "\" ' `" ~
Use this option to tell delimitMate which characters should be considered as Use this option to tell delimitMate which characters should be considered as
quotes. Read |delimitMateAutoClose| for details. quotes. Read |delimitMateAutoClose| for details.
@@ -210,8 +214,8 @@ e.g.: >
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
*'delimitMate_visual_leader'* *'delimitMate_visual_leader'*
*'b:delimitMate_visual_leader'* *'b:delimitMate_visual_leader'*
Values: Any character. Values: Any character. ~
Default: q Default: q ~
The value of this option will be used to wrap the selection in visual mode The value of this option will be used to wrap the selection in visual mode
when followed by a delimiter. Read |delimitMateVisualWrap| for details. when followed by a delimiter. Read |delimitMateVisualWrap| for details.
@@ -222,8 +226,8 @@ e.g: >
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
*'delimitMate_expand_cr'* *'delimitMate_expand_cr'*
*'b:delimitMate_expand_cr'* *'b:delimitMate_expand_cr'*
Values: A key mapping. Values: A key mapping. ~
Default: "\<CR>" Default: "\<CR>" ~
The value of this option will be used to expand the car return character when The value of this option will be used to expand the car return character when
typed inside an empty delimiter pair. Read |delimitMateExpansion| for details. typed inside an empty delimiter pair. Read |delimitMateExpansion| for details.
@@ -234,27 +238,41 @@ e.g.: >
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
*'delimitMate_expand_space'* *'delimitMate_expand_space'*
*'b:delimitMate_expand_space'* *'b:delimitMate_expand_space'*
Values: A key mapping. Values: A key mapping. ~
Default: "\<Space>" Default: "\<Space>" ~
The value of this option will be used to expand the space character when typed The value of this option will be used to expand the space character when typed
inside an empty delimiter pair. Read |delimitMateExpansion| for details. inside an empty delimiter pair. Read |delimitMateExpansion| for details.
e.g.: > e.g.: >
let delimitMate_expand_space = "\<Space>\<Space>\<Left>" let delimitMate_expand_space = "\<Space>\<Space>\<Left>"
au filetype tcl let b:delimitMate_expand_space = "\<Space>" au FileType tcl let b:delimitMate_expand_space = "\<Space>"
< <
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
*'delimitMate_excluded_ft'* *'delimitMate_excluded_ft'*
Values: A string of file type names separated by single commas. Values: A string of file type names separated by single commas. ~
Defaul: Empty. Default: Empty. ~
This options turns delimitMate off for the listed file types, use this option This options turns delimitMate off for the listed file types, use this option
only if don't want any of the features it provides. only if don't want any of the features it provides.
e.g.: > e.g.: >
let delimitMate_excluded_ft = "mail,txt" let delimitMate_excluded_ft = "mail,txt"
< <
------------------------------------------------------------------------------
*'delimitMate_apostrophes'*
Values: Strings separated by ":". ~
Default: "n't:'s:'re:'d:'ll:'ve:s'" ~
If auto-close is enabled, this option tells delimitMate how to try to fix the
balancing of single quotes when used as apostrophes. The values of this option
are strings of text where a single quote would be used as an apostrophe (e.g.:
the "n't" of wouldn't or can't) separated by ":". Set it to an empty string to
disable this feature.
e.g.: >
let delimitMate_apostrophes = ""
au FileType tcl let delimitMate_apostrophes = ""
<
============================================================================== ==============================================================================
4. PUBLIC COMMANDS *delimitMatePublicCommands* 4. COMMANDS *delimitMateCommands*
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
:DelimitMateReload *:DelimitMateReload* :DelimitMateReload *:DelimitMateReload*
@@ -371,7 +389,24 @@ This script was inspired by the auto-completion of delimiters of TextMate.
============================================================================== ==============================================================================
8. HISTORY *delimitMateHistory* 8. HISTORY *delimitMateHistory*
Version Date Release notes Version Date Release notes ~
|---------|------------|-----------------------------------------------------|
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
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
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. for specific file type configurations.
@@ -391,12 +426,15 @@ This script was inspired by the auto-completion of delimiters of TextMate.
the cursor would jump to the right. the cursor would jump to the right.
- New buffer inside the current window wouldn't - New buffer inside the current window wouldn't
have the mappings set. 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 set and added support for GetLatestScripts
auto-detection. auto-detection.
|---------|------------|-----------------------------------------------------| |---------|------------|-----------------------------------------------------|
1.0 2009-08-23 Initial upload. 1.0 2009-08-23 Initial upload.
|---------|------------|-----------------------------------------------------| |---------|------------|-----------------------------------------------------|
vim:tw=78:ts=8:ft=help:norl: vim:tw=78:ts=8:ft=help:norl:formatoptions+=tcroqn:autoindent:

View File

@@ -1,9 +1,10 @@
" ============================================================================ " ============================================================================
" File: delimitMate.vim " File: delimitMate.vim
" Version: 1.3 " Version: 1.6
" Description: This plugin tries to emulate the auto-completion of delimiters " Description: This plugin tries to emulate the auto-completion of delimiters
" that TextMate provides. " that TextMate provides.
" Maintainer: Israel Chauca F. <israelchauca@gmail.com> " Maintainer: Israel Chauca F. <israelchauca@gmail.com>
" Manual: Read ":help delimitMate".
" Credits: Some of the code is modified or just copied from the following: " Credits: Some of the code is modified or just copied from the following:
" "
" - Ian McCracken " - Ian McCracken
@@ -113,12 +114,19 @@ function! s:Init() "{{{1
if !exists("b:delimitMate_expand_space") && !exists("g:delimitMate_expand_space") " {{{ if !exists("b:delimitMate_expand_space") && !exists("g:delimitMate_expand_space") " {{{
let s:expand_space = "\<Space>" let s:expand_space = "\<Space>"
elseif b:delimitMate_expand_space == ""
let s:expand_space = "\<Space>"
elseif exists("b:delimitMate_expand_space") elseif exists("b:delimitMate_expand_space")
if b:delimitMate_expand_space == ""
let s:expand_space = "\<Space>"
else
let s:expand_space = b:delimitMate_expand_space let s:expand_space = b:delimitMate_expand_space
endif
else
if g:delimitMate_expand_space == ""
let s:expand_space = "\<Space>"
else else
let s:expand_space = g:delimitMate_expand_space let s:expand_space = g:delimitMate_expand_space
endif
endif " }}} endif " }}}
if !exists("b:delimitMate_expand_cr") && !exists("g:delimitMate_expand_cr") " {{{ if !exists("b:delimitMate_expand_cr") && !exists("g:delimitMate_expand_cr") " {{{
@@ -138,24 +146,34 @@ function! s:Init() "{{{1
endif " }}} endif " }}}
if !exists("b:delimitMate_apostrophes") && !exists("g:delimitMate_apostrophes") " {{{
let s:apostrophes = split("n't:'s:'re:'m:'d:'ll:'ve:s'",':')
elseif exists("b:delimitMate_apostrophes")
let s:apostrophes = split(b:delimitMate_apostrophes)
else
let s:apostrophes = split(g:delimitMate_apostrophes)
endif " }}}
let s:matchpairs = split(s:matchpairs_temp, ',') let s:matchpairs = split(s:matchpairs_temp, ',')
let s:left_delims = split(s:matchpairs_temp, ':.,\=') let s:left_delims = split(s:matchpairs_temp, ':.,\=')
let s:right_delims = split(s:matchpairs_temp, ',\=.:') let s:right_delims = split(s:matchpairs_temp, ',\=.:')
let s:VMapMsg = "delimitMate: delimitMate is disabled on blockwise visual mode." let s:VMapMsg = "delimitMate: delimitMate is disabled on blockwise visual mode."
call s:ResetMappings() call s:UnMap()
if s:autoclose if s:autoclose
call s:AutoClose() call s:AutoClose()
else else
call s:NoAutoClose() call s:NoAutoClose()
endif endif
call s:VisualMaps()
call s:ExtraMappings() call s:ExtraMappings()
let b:loaded_delimitMate = 1 let b:loaded_delimitMate = 1
endfunction "}}}1 endfunction "}}}1
function! s:ValidMatchpairs(str) "{{{1 function! s:ValidMatchpairs(str) "{{{1
if a:str !~ '^\(.:.\)\+\(,.:.\)*$' if a:str !~ '^.:.\(,.:.\)*$'
return 0 return 0
endif endif
for pair in split(a:str,',') for pair in split(a:str,',')
@@ -188,15 +206,19 @@ endfunction "}}}1
function! s:SkipDelim(char) "{{{1 function! s:SkipDelim(char) "{{{1
let cur = strpart( getline('.'), col('.')-2, 3 ) let cur = strpart( getline('.'), col('.')-2, 3 )
if cur[0] == "\\" if cur[0] == "\\"
" Escaped character
return a:char return a:char
elseif cur[1] == a:char elseif cur[1] == a:char
" Exit pair
return "\<Right>" return "\<Right>"
elseif cur[1] == ' ' && cur[2] == a:char elseif cur[1] == ' ' && cur[2] == a:char
" I'm leaving this in case someone likes it. " I'm leaving this in case someone likes it. Jump an space and delimiter.
return "\<Right>\<Right>" return "\<Right>\<Right>"
elseif s:IsEmptyPair( cur[0] . a:char ) elseif s:IsEmptyPair( cur[0] . a:char )
" Add closing delimiter and jump back to the middle.
return a:char . "\<Left>" return a:char . "\<Left>"
else else
" Nothing special here, return the same character.
return a:char return a:char
endif endif
endfunction "}}}1 endfunction "}}}1
@@ -205,21 +227,23 @@ function! s:QuoteDelim(char) "{{{1
let line = getline('.') let line = getline('.')
let col = col('.') let col = col('.')
if line[col - 2] == "\\" if line[col - 2] == "\\"
"Inserting a quoted quotation mark into the string " Seems like a escaped character, insert a single quotation mark.
return a:char return a:char
elseif line[col - 1] == a:char elseif line[col - 1] == a:char
"Escaping out of the string " Get out of the string.
return "\<Right>" return "\<Right>"
else else
"Starting a string " Insert a pair and jump to the middle.
return a:char.a:char."\<Left>" return a:char.a:char."\<Left>"
endif endif
endfunction "}}}1 endfunction "}}}1
function! s:ClosePair(char) "{{{1 function! s:ClosePair(char) "{{{1
if getline('.')[col('.') - 1] == a:char if getline('.')[col('.') - 1] == a:char
" Same character on the rigth, jump it.
return "\<Right>" return "\<Right>"
else else
" Insert character.
return a:char return a:char
endif endif
endfunction "}}}1 endfunction "}}}1
@@ -244,25 +268,6 @@ function! s:NoAutoClose() "{{{1
for delim in s:right_delims + s:quotes for delim in s:right_delims + s:quotes
exec 'inoremap <buffer> ' . delim . ' <C-R>=<SID>SkipDelim("' . escape(delim,'"') . '")<CR>' exec 'inoremap <buffer> ' . delim . ' <C-R>=<SID>SkipDelim("' . escape(delim,'"') . '")<CR>'
endfor endfor
" Wrap the selection with matching pairs, but do nothing if blockwise visual mode is active:
let s:i = 0
while s:i < len(s:matchpairs)
" Map left delimiter:
" vnoremap <buffer> <expr> q( visualmode() == "<C-V>" ? <SID>MapMsg("Message") : "s(\<C-R>\"\<Esc>"
exec 'vnoremap <buffer> <expr> ' . s:visual_leader . s:left_delims[s:i] . ' <SID>IsBlockVisual() ? <SID>MapMsg("' . s:VMapMsg . '") : "s' . s:left_delims[s:i] . '\<C-R>\"' . s:right_delims[s:i] . '\<Esc>:call <SID>RestoreRegister()<CR>"'
" Map right delimiter:
" vnoremap <buffer> <expr> q) visualmode() == "<C-V>" ? <SID>MapMsg("Message") : "s(\<C-R>\""\<Esc>"
exec 'vnoremap <buffer> <expr> ' . s:visual_leader . s:right_delims[s:i] . ' <SID>IsBlockVisual() ? <SID>MapMsg("' . s:VMapMsg . '") : "s' . s:left_delims[s:i] . '\<C-R>\"' . s:right_delims[s:i] . '\<Esc>:call <SID>RestoreRegister()<CR>"'
let s:i += 1
endwhile
" Wrap the selection with matching quotes, but do nothing if blockwise visual mode is active:
for quote in s:quotes
" vnoremap <buffer> <expr> q' visualmode() == "<C-V>" ? <SID>MapMsg("Message") : "s'\<C-R>\"'\<Esc>"
exec 'vnoremap <buffer> <expr> ' . s:visual_leader . quote . ' <SID>IsBlockVisual() ? <SID>MapMsg("' . s:VMapMsg . '") : "s' . escape(quote,'"') .'\<C-R>\"' . escape(quote,'"') . '\<Esc>:call <SID>RestoreRegister()<CR>"'
endfor
endfunction "}}}1 endfunction "}}}1
function! s:AutoClose() "{{{1 function! s:AutoClose() "{{{1
@@ -286,22 +291,31 @@ function! s:AutoClose() "{{{1
exec 'inoremap <buffer> ' . delim . ' <C-R>=<SID>ClosePair("\' . delim . '")<CR>' exec 'inoremap <buffer> ' . delim . ' <C-R>=<SID>ClosePair("\' . delim . '")<CR>'
endfor endfor
" Try to fix the use of apostrophes:
" inoremap <buffer> n't n't
for map in s:apostrophes
exec "inoremap <buffer> " . map . " " . map
endfor
endfunction "}}}1
function! s:VisualMaps() " {{{1
" Wrap the selection with matching pairs, but do nothing if blockwise visual mode is active: " Wrap the selection with matching pairs, but do nothing if blockwise visual mode is active:
let s:i = 0 let s:i = 0
while s:i < len(s:matchpairs) while s:i < len(s:matchpairs)
" Map left delimiter: " Map left delimiter:
" vnoremap <buffer> <expr> q( visualmode() == "<C-V>" ? <SID>MapMsg("Message") : "s(\<C-R>\"\<Esc>" " vnoremap <buffer> <expr> \( <SID>IsBlockVisual() ? <SID>MapMsg("Message") : "s(\<C-R>\")\<Esc>:call <SID>RestoreRegister()<CR>"
exec 'vnoremap <buffer> <expr> ' . s:visual_leader . s:left_delims[s:i] . ' <SID>IsBlockVisual() ? <SID>MapMsg("' . s:VMapMsg . '") : "s' . s:left_delims[s:i] . '\<C-R>\"' . s:right_delims[s:i] . '\<Esc>:call <SID>RestoreRegister()<CR>"' exec 'vnoremap <buffer> <expr> ' . s:visual_leader . s:left_delims[s:i] . ' <SID>IsBlockVisual() ? <SID>MapMsg("' . s:VMapMsg . '") : "s' . s:left_delims[s:i] . '\<C-R>\"' . s:right_delims[s:i] . '\<Esc>:call <SID>RestoreRegister()<CR>"'
" Map right delimiter: " Map right delimiter:
" vnoremap <buffer> <expr> q) visualmode() == "<C-V>" ? <SID>MapMsg("Message") : "s(\<C-R>\""\<Esc>" " vnoremap <buffer> <expr> \) <SID>IsBlockVisual() ? <SID>MapMsg("Message") : "s(\<C-R>\")\<Esc>:call <SID>RestoreRegister()<CR>"
exec 'vnoremap <buffer> <expr> ' . s:visual_leader . s:right_delims[s:i] . ' <SID>IsBlockVisual() ? <SID>MapMsg("' . s:VMapMsg . '") : "s' . s:left_delims[s:i] . '\<C-R>\"' . s:right_delims[s:i] . '\<Esc>:call <SID>RestoreRegister()<CR>"' exec 'vnoremap <buffer> <expr> ' . s:visual_leader . s:right_delims[s:i] . ' <SID>IsBlockVisual() ? <SID>MapMsg("' . s:VMapMsg . '") : "s' . s:left_delims[s:i] . '\<C-R>\"' . s:right_delims[s:i] . '\<Esc>:call <SID>RestoreRegister()<CR>"'
let s:i += 1 let s:i += 1
endwhile endwhile
" Wrap the selection with matching quotes, but do nothing if blockwise visual mode is active: " Wrap the selection with matching quotes, but do nothing if blockwise visual mode is active:
for quote in s:quotes for quote in s:quotes
" vnoremap <buffer> <expr> q' visualmode() == "<C-V>" ? <SID>MapMsg("Message") : "s'\<C-R>\"'\<Esc>" " vnoremap <buffer> <expr> \' <SID>IsBlockVisual() ? <SID>MapMsg("Message") : "s'\<C-R>\"'\<Esc>:call <SID>RestoreRegister()<CR>"
exec 'vnoremap <buffer> <expr> ' . s:visual_leader . quote . ' <SID>IsBlockVisual() ? <SID>MapMsg("' . s:VMapMsg . '") : "s' . escape(quote,'"') .'\<C-R>\"' . escape(quote,'"') . '\<Esc>:call <SID>RestoreRegister()<CR>"' exec 'vnoremap <buffer> <expr> ' . s:visual_leader . quote . ' <SID>IsBlockVisual() ? <SID>MapMsg("' . s:VMapMsg . '") : "s' . escape(quote,'"') .'\<C-R>\"' . escape(quote,'"') . '\<Esc>:call <SID>RestoreRegister()<CR>"'
endfor endfor
endfunction "}}}1 endfunction "}}}1
@@ -310,46 +324,56 @@ function! s:IsBlockVisual() " {{{1
if visualmode() == "<C-V>" if visualmode() == "<C-V>"
return 1 return 1
endif endif
" Store unnamed register values for later use in s:RestoreRegister().
let s:save_reg = getreg('"') let s:save_reg = getreg('"')
echomsg s:save_reg
let s:save_reg_mode = getregtype('"') let s:save_reg_mode = getregtype('"')
echomsg s:save_reg_mode
if len(getline('.')) == 0 if len(getline('.')) == 0
" This for proper wrap of empty lines.
let @" = "\n" let @" = "\n"
endif endif
return 0 return 0
endfunction " }}}1 endfunction " }}}1
function! s:RestoreRegister() " {{{1 function! s:RestoreRegister() " {{{1
" Restore unnamed register values store in s:IsBlockVisual().
call setreg('"', s:save_reg, s:save_reg_mode) call setreg('"', s:save_reg, s:save_reg_mode)
echo "" echo ""
endfunction " }}}1 endfunction " }}}1
function! s:ExpandReturn() "{{{1 function! s:ExpandReturn() "{{{1
if s:WithinEmptyPair() if s:WithinEmptyPair()
" Expand:
return s:expand_return return s:expand_return
else else
" Don't
return "\<CR>" return "\<CR>"
endif endif
endfunction "}}}1 endfunction "}}}1
function! s:ExpandSpace() "{{{1 function! s:ExpandSpace() "{{{1
if s:WithinEmptyPair() if s:WithinEmptyPair()
" Expand:
return s:expand_space return s:expand_space
else else
" Don't
return "\<Space>" return "\<Space>"
endif endif
endfunction "}}}1 endfunction "}}}1
function! s:ExtraMappings() "{{{1 function! s:ExtraMappings() "{{{1
" If pair is empty, delete both delimiters: " If pair is empty, delete both delimiters:
inoremap <buffer> <expr> <BS> <SID>WithinEmptyPair() ? "<Right><BS><BS>" : "\<BS>" inoremap <buffer> <expr> <BS> <SID>WithinEmptyPair() ? "\<Right>\<BS>\<BS>" : "\<BS>"
" Expand return if inside an empty pair: " Expand return if inside an empty pair:
if exists("b:delimitMate_expand_cr") || exists("g:delimitMate_expand_cr")
inoremap <buffer> <CR> <C-R>=<SID>ExpandReturn()<CR> inoremap <buffer> <CR> <C-R>=<SID>ExpandReturn()<CR>
endif
" Expand space if inside an empty pair: " Expand space if inside an empty pair:
if exists("b:delimitMate_expand_space") || exists("g:delimitMate_expand_space")
inoremap <buffer> <Space> <C-R>=<SID>ExpandSpace()<CR> inoremap <buffer> <Space> <C-R>=<SID>ExpandSpace()<CR>
endif
endfunction "}}}1 endfunction "}}}1
function! s:TestMappings() "{{{1 function! s:TestMappings() "{{{1
@@ -392,7 +416,7 @@ function! s:TestMappings() "{{{1
exec "normal A\<CR>Car return: " . s:quotes[i] . s:quotes[i] . "\<CR>|\<Esc>GGA\<CR>\<CR>" exec "normal A\<CR>Car return: " . s:quotes[i] . s:quotes[i] . "\<CR>|\<Esc>GGA\<CR>\<CR>"
endfor endfor
endif endif
exec "normal \<Esc>" exec "normal \<Esc>i"
endfunction "}}}1 endfunction "}}}1
function! s:SwitchAutoclose() "{{{1 function! s:SwitchAutoclose() "{{{1
@@ -406,6 +430,64 @@ function! s:SwitchAutoclose() "{{{1
DelimitMateReload DelimitMateReload
endfunction "}}}1 endfunction "}}}1
function! s:UnMap() " {{{
" No Autoclose Mappings:
for char in s:right_delims + s:quotes
if maparg(char,"i") =~? 'SkipDelim'
exec 'iunmap <buffer> ' . char
"echomsg 'iunmap <buffer> ' . char
endif
endfor
" Autoclose Mappings:
let s:i = 0
while s:i < len(s:matchpairs)
if maparg(s:left_delims[s:i],"i") =~? s:left_delims[s:i] . s:right_delims[s:i] . '<Left>'
exec 'iunmap <buffer> ' . s:left_delims[s:i]
"echomsg 'iunmap <buffer> ' . s:left_delims[s:i]
endif
let s:i += 1
endwhile
for char in s:quotes
if maparg(char, "i") =~? 'QuoteDelim'
exec 'iunmap <buffer> ' . char
"echomsg 'iunmap <buffer> ' . char
endif
endfor
for char in s:right_delims
if maparg(char, "i") =~? 'ClosePair'
exec 'iunmap <buffer> ' . char
"echomsg 'iunmap <buffer> ' . char
endif
endfor
for map in s:apostrophes
exec "silent! iunmap <buffer> " . map
endfor
" Visual Mappings:
for char in s:right_delims + s:left_delims + s:quotes
if maparg(s:visual_leader . char,"v") =~? 'IsBlock'
exec 'vunmap <buffer> ' . s:visual_leader . char
"echomsg 'vunmap <buffer> ' . s:visual_leader . char
endif
endfor
" Expansion Mappings:
if maparg('<BS>', "i") =~? 'WithinEmptyPair'
iunmap <buffer> <BS>
"echomsg "iunmap <buffer> <BS>"
endif
if maparg('<CR>',"i") =~? 'ExpandReturn'
iunmap <buffer> <CR>
"echomsg "iunmap <buffer> <CR>"
endif
if maparg('<Space>',"i") =~? 'ExpandSpace'
iunmap <buffer> <Space>
"echomsg "iunmap <buffer> <Space>"
endif
endfunction " }}}
function! s:TestMappingsDo() "{{{1 function! s:TestMappingsDo() "{{{1
if !exists("g:delimitMate_testing") if !exists("g:delimitMate_testing")
call s:DelimitMateDo() call s:DelimitMateDo()
@@ -421,25 +503,30 @@ endfunction "}}}1
function! s:DelimitMateDo() "{{{1 function! s:DelimitMateDo() "{{{1
if exists("g:delimitMate_excluded_ft") if exists("g:delimitMate_excluded_ft")
" Check if this file type is excluded:
for ft in split(g:delimitMate_excluded_ft,',') for ft in split(g:delimitMate_excluded_ft,',')
if ft ==? &filetype if ft ==? &filetype
echomsg "Excluded" if !exists("s:quotes")
return 1
endif
"echomsg "excluded"
call s:UnMap()
return 1 return 1
endif endif
endfor endfor
endif endif
try try
"echomsg "included"
let save_cpo = &cpo let save_cpo = &cpo
set cpo&vim set cpo&vim
call s:Init() call s:Init()
finally finally
let &cpo = save_cpo let &cpo = save_cpo
endtry endtry
let &cpo = save_cpo
endfunction "}}}1 endfunction "}}}1
" Do the real work: {{{1 " Set some commands: {{{1
"call s:DelimitMateDo() call s:DelimitMateDo()
" Let me refresh without re-loading the buffer: " Let me refresh without re-loading the buffer:
command! DelimitMateReload call s:DelimitMateDo() command! DelimitMateReload call s:DelimitMateDo()
@@ -447,8 +534,14 @@ command! DelimitMateReload call s:DelimitMateDo()
" Quick test: " Quick test:
command! DelimitMateTest call s:TestMappingsDo() command! DelimitMateTest call s:TestMappingsDo()
"autocmd BufNewFile,BufRead,BufEnter * if !exists("b:loaded_delimitMate") || &filetype !=? "mailapp" | call <SID>DelimitMateDo() | endif " Run on file type events.
autocmd VimEnter * autocmd FileType * if !exists("b:loaded_delimitMate") | call <SID>DelimitMateDo() | endif "autocmd VimEnter * autocmd FileType * call <SID>DelimitMateDo()
autocmd FileType * call <SID>DelimitMateDo()
" Run on new buffers.
autocmd BufNewFile,BufRead,BufEnter * if !exists("b:loaded_delimitMate") | call <SID>DelimitMateDo() | endif
"function! s:GetSynRegion () | echo synIDattr(synIDtrans(synID(line('.'), col('.'), 1)), 'name') | endfunction
" GetLatestVimScripts: 2754 1 :AutoInstall: delimitMate.vim " GetLatestVimScripts: 2754 1 :AutoInstall: delimitMate.vim
" vim:foldmethod=marker:foldcolumn=2 " vim:foldmethod=marker:foldcolumn=2