mirror of
https://github.com/Raimondi/delimitMate.git
synced 2025-12-06 20:54:31 +08:00
== 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.
This commit is contained in:
@@ -1,13 +1,13 @@
|
|||||||
*delimitMate.txt* Trying to keep those beasts at bay! v.1.5
|
*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!
|
||||||
<
|
<
|
||||||
@@ -155,12 +155,16 @@ specific file types, see |delimitMateOptionDetails| for examples.
|
|||||||
|'delimitMate_expand_space'| Sets the expansion for <Space> inside an
|
|'delimitMate_expand_space'| Sets the expansion for <Space> inside an
|
||||||
empty pair of matching delimiters or quotes.
|
empty pair of matching delimiters or quotes.
|
||||||
|
|
||||||
|'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.
|
||||||
|
|
||||||
@@ -241,20 +245,34 @@ 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*
|
||||||
@@ -372,6 +390,13 @@ 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
|
1.5 2009-10-05 Fix: delimitMate should work correctly for files
|
||||||
passed as arguments to Vim. Thanks to Ben Beuchler
|
passed as arguments to Vim. Thanks to Ben Beuchler
|
||||||
@@ -412,4 +437,4 @@ This script was inspired by the auto-completion of delimiters of TextMate.
|
|||||||
|
|
||||||
|---------|------------|-----------------------------------------------------|
|
|---------|------------|-----------------------------------------------------|
|
||||||
|
|
||||||
vim:tw=78:ts=8:ft=help:norl:
|
vim:tw=78:ts=8:ft=help:norl:formatoptions+=tcroqn:autoindent:
|
||||||
|
|||||||
105
delimitMate.vim
105
delimitMate.vim
@@ -1,9 +1,10 @@
|
|||||||
" ============================================================================
|
" ============================================================================
|
||||||
" File: delimitMate.vim
|
" File: delimitMate.vim
|
||||||
" Version: 1.5
|
" 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")
|
||||||
let s:expand_space = b:delimitMate_expand_space
|
if b:delimitMate_expand_space == ""
|
||||||
|
let s:expand_space = "\<Space>"
|
||||||
|
else
|
||||||
|
let s:expand_space = b:delimitMate_expand_space
|
||||||
|
endif
|
||||||
else
|
else
|
||||||
let s:expand_space = g:delimitMate_expand_space
|
if g:delimitMate_expand_space == ""
|
||||||
|
let s:expand_space = "\<Space>"
|
||||||
|
else
|
||||||
|
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,33 +324,39 @@ 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
|
||||||
@@ -346,10 +366,14 @@ function! s:ExtraMappings() "{{{1
|
|||||||
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:
|
||||||
inoremap <buffer> <CR> <C-R>=<SID>ExpandReturn()<CR>
|
if exists("b:delimitMate_expand_cr") || exists("g:delimitMate_expand_cr")
|
||||||
|
inoremap <buffer> <CR> <C-R>=<SID>ExpandReturn()<CR>
|
||||||
|
endif
|
||||||
|
|
||||||
" Expand space if inside an empty pair:
|
" Expand space if inside an empty pair:
|
||||||
inoremap <buffer> <Space> <C-R>=<SID>ExpandSpace()<CR>
|
if exists("b:delimitMate_expand_space") || exists("g:delimitMate_expand_space")
|
||||||
|
inoremap <buffer> <Space> <C-R>=<SID>ExpandSpace()<CR>
|
||||||
|
endif
|
||||||
endfunction "}}}1
|
endfunction "}}}1
|
||||||
|
|
||||||
function! s:TestMappings() "{{{1
|
function! s:TestMappings() "{{{1
|
||||||
@@ -436,6 +460,9 @@ function! s:UnMap() " {{{
|
|||||||
"echomsg 'iunmap <buffer> ' . char
|
"echomsg 'iunmap <buffer> ' . char
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
|
for map in s:apostrophes
|
||||||
|
exec "silent! iunmap <buffer> " . map
|
||||||
|
endfor
|
||||||
|
|
||||||
" Visual Mappings:
|
" Visual Mappings:
|
||||||
for char in s:right_delims + s:left_delims + s:quotes
|
for char in s:right_delims + s:left_delims + s:quotes
|
||||||
@@ -476,6 +503,7 @@ 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
|
||||||
if !exists("s:quotes")
|
if !exists("s:quotes")
|
||||||
@@ -495,10 +523,9 @@ function! s:DelimitMateDo() "{{{1
|
|||||||
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:
|
||||||
|
|||||||
Reference in New Issue
Block a user