mirror of
https://github.com/Raimondi/delimitMate.git
synced 2025-12-06 20:54:31 +08:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6f0c91468a | ||
|
|
75b4f3b520 | ||
|
|
3ce7f7ffcf |
@@ -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*
|
||||
|
||||
1. Introduction____________________________|delimitMate|
|
||||
1. Introduction____________________________|delimitMateIntro|
|
||||
2. Functionality___________________________|delimitMateFunctionality|
|
||||
2.1 Automatic closing & exiting________|delimitMateAutoClose|
|
||||
2.2 Expansion of space and CR__________|delimitMateExpansion|
|
||||
@@ -16,14 +16,14 @@
|
||||
3. Customization___________________________|delimitMateOptions|
|
||||
3.1 Option summary_____________________|delimitMateOptionSummary|
|
||||
3.2 Options details____________________|delimitMateOptionDetails|
|
||||
4. Public commands_________________________|delimitMatePublicCommands|
|
||||
4. Commands________________________________|delimitMateCommands|
|
||||
5. TODO list_______________________________|delimitMateTodo|
|
||||
6. Maintainer______________________________|delimitMateMaintainer|
|
||||
7. Credits_________________________________|delimitMateCredits|
|
||||
8. History_________________________________|delimitMateHistory|
|
||||
|
||||
==============================================================================
|
||||
1.- INTRODUCTION *delimitMate*
|
||||
1.- INTRODUCTION *delimitMateIntro*
|
||||
|
||||
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
|
||||
@@ -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.
|
||||
|
||||
==============================================================================
|
||||
2. FUNCTIONALITY PROVIDED *delimitMateFunctionality*
|
||||
2. FUNCTIONALITY *delimitMateFunctionality*
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
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): >
|
||||
|
||||
Selected text | After q"
|
||||
Selected text | After \"
|
||||
=============================================
|
||||
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
|
||||
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*
|
||||
|
||||
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
|
||||
autocmd to modify delimitMate's behavior for specific file types.
|
||||
|
||||
@@ -174,8 +178,8 @@ e.g.: >
|
||||
------------------------------------------------------------------------------
|
||||
*'delimitMate_autoclose'*
|
||||
*'b:delimitMate_autoclose'*
|
||||
Values: 0 or 1.
|
||||
Default: 1
|
||||
Values: 0 or 1. ~
|
||||
Default: 1 ~
|
||||
|
||||
If this option is set to 0, delimitMate will not add a closing delimiter
|
||||
automagically. See |delimitMateAutoClose| for details.
|
||||
@@ -186,8 +190,8 @@ e.g.: >
|
||||
------------------------------------------------------------------------------
|
||||
*'delimitMate_matchpairs'*
|
||||
*'b:delimitMate_matchpairs'*
|
||||
Values: A string with |matchpairs| syntax.
|
||||
Default: &matchpairs
|
||||
Values: A string with |matchpairs| syntax. ~
|
||||
Default: &matchpairs ~
|
||||
|
||||
Use this option to tell delimitMate which characters should be considered
|
||||
matching pairs. Read |delimitMateAutoClose| for details.
|
||||
@@ -198,8 +202,8 @@ e.g: >
|
||||
------------------------------------------------------------------------------
|
||||
*'delimitMate_quotes'*
|
||||
*'b:delimitMate_quotes'*
|
||||
Values: A string of characters separated by spaces.
|
||||
Default: "\" ' `"
|
||||
Values: A string of characters separated by spaces. ~
|
||||
Default: "\" ' `" ~
|
||||
|
||||
Use this option to tell delimitMate which characters should be considered as
|
||||
quotes. Read |delimitMateAutoClose| for details.
|
||||
@@ -210,8 +214,8 @@ e.g.: >
|
||||
------------------------------------------------------------------------------
|
||||
*'delimitMate_visual_leader'*
|
||||
*'b:delimitMate_visual_leader'*
|
||||
Values: Any character.
|
||||
Default: q
|
||||
Values: Any character. ~
|
||||
Default: q ~
|
||||
|
||||
The value of this option will be used to wrap the selection in visual mode
|
||||
when followed by a delimiter. Read |delimitMateVisualWrap| for details.
|
||||
@@ -222,8 +226,8 @@ e.g: >
|
||||
------------------------------------------------------------------------------
|
||||
*'delimitMate_expand_cr'*
|
||||
*'b:delimitMate_expand_cr'*
|
||||
Values: A key mapping.
|
||||
Default: "\<CR>"
|
||||
Values: A key mapping. ~
|
||||
Default: "\<CR>" ~
|
||||
|
||||
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.
|
||||
@@ -234,27 +238,41 @@ e.g.: >
|
||||
------------------------------------------------------------------------------
|
||||
*'delimitMate_expand_space'*
|
||||
*'b:delimitMate_expand_space'*
|
||||
Values: A key mapping.
|
||||
Default: "\<Space>"
|
||||
Values: A key mapping. ~
|
||||
Default: "\<Space>" ~
|
||||
|
||||
The value of this option will be used to expand the space character when typed
|
||||
inside an empty delimiter pair. Read |delimitMateExpansion| for details.
|
||||
e.g.: >
|
||||
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'*
|
||||
Values: A string of file type names separated by single commas.
|
||||
Defaul: Empty.
|
||||
Values: A string of file type names separated by single commas. ~
|
||||
Default: Empty. ~
|
||||
|
||||
This options turns delimitMate off for the listed file types, use this option
|
||||
only if don't want any of the features it provides.
|
||||
e.g.: >
|
||||
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*
|
||||
@@ -371,7 +389,24 @@ This script was inspired by the auto-completion of delimiters of TextMate.
|
||||
==============================================================================
|
||||
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
|
||||
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.
|
||||
- New buffer inside the current window wouldn't
|
||||
have the mappings set.
|
||||
|
||||
|---------|------------|-----------------------------------------------------|
|
||||
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.
|
||||
|
||||
|---------|------------|-----------------------------------------------------|
|
||||
|
||||
vim:tw=78:ts=8:ft=help:norl:
|
||||
vim:tw=78:ts=8:ft=help:norl:formatoptions+=tcroqn:autoindent:
|
||||
|
||||
185
delimitMate.vim
185
delimitMate.vim
@@ -1,9 +1,10 @@
|
||||
" ============================================================================
|
||||
" File: delimitMate.vim
|
||||
" Version: 1.3
|
||||
" Version: 1.6
|
||||
" Description: This plugin tries to emulate the auto-completion of delimiters
|
||||
" that TextMate provides.
|
||||
" Maintainer: Israel Chauca F. <israelchauca@gmail.com>
|
||||
" Manual: Read ":help delimitMate".
|
||||
" Credits: Some of the code is modified or just copied from the following:
|
||||
"
|
||||
" - Ian McCracken
|
||||
@@ -108,17 +109,24 @@ function! s:Init() "{{{1
|
||||
elseif exists("b:delimitMate_visual_leader")
|
||||
let s:visual_leader = b:delimitMate_visual_leader
|
||||
else
|
||||
let s:visual_leader = g:delimitMate_visual_leader
|
||||
let s:visual_leader = g:delimitMate_visual_leader
|
||||
endif " }}}
|
||||
|
||||
if !exists("b:delimitMate_expand_space") && !exists("g:delimitMate_expand_space") " {{{
|
||||
let s:expand_space = "\<Space>"
|
||||
elseif b:delimitMate_expand_space == ""
|
||||
let s:expand_space = "\<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
|
||||
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 " }}}
|
||||
|
||||
if !exists("b:delimitMate_expand_cr") && !exists("g:delimitMate_expand_cr") " {{{
|
||||
@@ -138,24 +146,34 @@ function! s:Init() "{{{1
|
||||
|
||||
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:left_delims = split(s:matchpairs_temp, ':.,\=')
|
||||
let s:right_delims = split(s:matchpairs_temp, ',\=.:')
|
||||
let s:VMapMsg = "delimitMate: delimitMate is disabled on blockwise visual mode."
|
||||
|
||||
call s:ResetMappings()
|
||||
call s:UnMap()
|
||||
if s:autoclose
|
||||
call s:AutoClose()
|
||||
else
|
||||
call s:NoAutoClose()
|
||||
endif
|
||||
call s:VisualMaps()
|
||||
call s:ExtraMappings()
|
||||
let b:loaded_delimitMate = 1
|
||||
|
||||
endfunction "}}}1
|
||||
|
||||
function! s:ValidMatchpairs(str) "{{{1
|
||||
if a:str !~ '^\(.:.\)\+\(,.:.\)*$'
|
||||
if a:str !~ '^.:.\(,.:.\)*$'
|
||||
return 0
|
||||
endif
|
||||
for pair in split(a:str,',')
|
||||
@@ -188,15 +206,19 @@ endfunction "}}}1
|
||||
function! s:SkipDelim(char) "{{{1
|
||||
let cur = strpart( getline('.'), col('.')-2, 3 )
|
||||
if cur[0] == "\\"
|
||||
" Escaped character
|
||||
return a:char
|
||||
elseif cur[1] == a:char
|
||||
" Exit pair
|
||||
return "\<Right>"
|
||||
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>"
|
||||
elseif s:IsEmptyPair( cur[0] . a:char )
|
||||
" Add closing delimiter and jump back to the middle.
|
||||
return a:char . "\<Left>"
|
||||
else
|
||||
" Nothing special here, return the same character.
|
||||
return a:char
|
||||
endif
|
||||
endfunction "}}}1
|
||||
@@ -205,21 +227,23 @@ function! s:QuoteDelim(char) "{{{1
|
||||
let line = getline('.')
|
||||
let col = col('.')
|
||||
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
|
||||
elseif line[col - 1] == a:char
|
||||
"Escaping out of the string
|
||||
" Get out of the string.
|
||||
return "\<Right>"
|
||||
else
|
||||
"Starting a string
|
||||
" Insert a pair and jump to the middle.
|
||||
return a:char.a:char."\<Left>"
|
||||
endif
|
||||
endfunction "}}}1
|
||||
|
||||
function! s:ClosePair(char) "{{{1
|
||||
if getline('.')[col('.') - 1] == a:char
|
||||
" Same character on the rigth, jump it.
|
||||
return "\<Right>"
|
||||
else
|
||||
" Insert character.
|
||||
return a:char
|
||||
endif
|
||||
endfunction "}}}1
|
||||
@@ -244,25 +268,6 @@ function! s:NoAutoClose() "{{{1
|
||||
for delim in s:right_delims + s:quotes
|
||||
exec 'inoremap <buffer> ' . delim . ' <C-R>=<SID>SkipDelim("' . escape(delim,'"') . '")<CR>'
|
||||
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
|
||||
|
||||
function! s:AutoClose() "{{{1
|
||||
@@ -286,22 +291,31 @@ function! s:AutoClose() "{{{1
|
||||
exec 'inoremap <buffer> ' . delim . ' <C-R>=<SID>ClosePair("\' . delim . '")<CR>'
|
||||
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:
|
||||
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>"
|
||||
" 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>"'
|
||||
|
||||
" 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>"'
|
||||
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>"
|
||||
" 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>"'
|
||||
endfor
|
||||
endfunction "}}}1
|
||||
@@ -310,46 +324,56 @@ function! s:IsBlockVisual() " {{{1
|
||||
if visualmode() == "<C-V>"
|
||||
return 1
|
||||
endif
|
||||
" Store unnamed register values for later use in s:RestoreRegister().
|
||||
let s:save_reg = getreg('"')
|
||||
echomsg s:save_reg
|
||||
let s:save_reg_mode = getregtype('"')
|
||||
echomsg s:save_reg_mode
|
||||
|
||||
if len(getline('.')) == 0
|
||||
" This for proper wrap of empty lines.
|
||||
let @" = "\n"
|
||||
endif
|
||||
return 0
|
||||
endfunction " }}}1
|
||||
|
||||
function! s:RestoreRegister() " {{{1
|
||||
" Restore unnamed register values store in s:IsBlockVisual().
|
||||
call setreg('"', s:save_reg, s:save_reg_mode)
|
||||
echo ""
|
||||
endfunction " }}}1
|
||||
|
||||
function! s:ExpandReturn() "{{{1
|
||||
if s:WithinEmptyPair()
|
||||
" Expand:
|
||||
return s:expand_return
|
||||
else
|
||||
" Don't
|
||||
return "\<CR>"
|
||||
endif
|
||||
endfunction "}}}1
|
||||
|
||||
function! s:ExpandSpace() "{{{1
|
||||
if s:WithinEmptyPair()
|
||||
" Expand:
|
||||
return s:expand_space
|
||||
else
|
||||
" Don't
|
||||
return "\<Space>"
|
||||
endif
|
||||
endfunction "}}}1
|
||||
|
||||
function! s:ExtraMappings() "{{{1
|
||||
" 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:
|
||||
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:
|
||||
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
|
||||
|
||||
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>"
|
||||
endfor
|
||||
endif
|
||||
exec "normal \<Esc>"
|
||||
exec "normal \<Esc>i"
|
||||
endfunction "}}}1
|
||||
|
||||
function! s:SwitchAutoclose() "{{{1
|
||||
@@ -406,6 +430,64 @@ function! s:SwitchAutoclose() "{{{1
|
||||
DelimitMateReload
|
||||
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
|
||||
if !exists("g:delimitMate_testing")
|
||||
call s:DelimitMateDo()
|
||||
@@ -421,25 +503,30 @@ endfunction "}}}1
|
||||
|
||||
function! s:DelimitMateDo() "{{{1
|
||||
if exists("g:delimitMate_excluded_ft")
|
||||
" Check if this file type is excluded:
|
||||
for ft in split(g:delimitMate_excluded_ft,',')
|
||||
if ft ==? &filetype
|
||||
echomsg "Excluded"
|
||||
if !exists("s:quotes")
|
||||
return 1
|
||||
endif
|
||||
"echomsg "excluded"
|
||||
call s:UnMap()
|
||||
return 1
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
try
|
||||
"echomsg "included"
|
||||
let save_cpo = &cpo
|
||||
set cpo&vim
|
||||
call s:Init()
|
||||
finally
|
||||
let &cpo = save_cpo
|
||||
endtry
|
||||
let &cpo = save_cpo
|
||||
endfunction "}}}1
|
||||
|
||||
" Do the real work: {{{1
|
||||
"call s:DelimitMateDo()
|
||||
" Set some commands: {{{1
|
||||
call s:DelimitMateDo()
|
||||
|
||||
" Let me refresh without re-loading the buffer:
|
||||
command! DelimitMateReload call s:DelimitMateDo()
|
||||
@@ -447,8 +534,14 @@ command! DelimitMateReload call s:DelimitMateDo()
|
||||
" Quick test:
|
||||
command! DelimitMateTest call s:TestMappingsDo()
|
||||
|
||||
"autocmd BufNewFile,BufRead,BufEnter * if !exists("b:loaded_delimitMate") || &filetype !=? "mailapp" | call <SID>DelimitMateDo() | endif
|
||||
autocmd VimEnter * autocmd FileType * if !exists("b:loaded_delimitMate") | call <SID>DelimitMateDo() | endif
|
||||
" Run on file type events.
|
||||
"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
|
||||
" vim:foldmethod=marker:foldcolumn=2
|
||||
|
||||
Reference in New Issue
Block a user