mirror of
https://github.com/Raimondi/delimitMate.git
synced 2025-12-06 12:44:27 +08:00
Compare commits
11 Commits
rewrite
...
1e9e49d6de
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1e9e49d6de | ||
|
|
becbd2d353 | ||
|
|
382c36bf57 | ||
|
|
537a1da0fa | ||
|
|
055978491a | ||
|
|
16687aec24 | ||
|
|
728b57a656 | ||
|
|
98143957cf | ||
|
|
b5719054be | ||
|
|
39d8f522f7 | ||
|
|
3a7919fdb5 |
@@ -12,32 +12,20 @@ if !exists('s:options')
|
||||
let s:options = {}
|
||||
endif
|
||||
|
||||
function! s:set(name, value, ...) "{{{
|
||||
let scope = a:0 ? a:1 : 's'
|
||||
function! s:set(name, value) "{{{
|
||||
let bufnr = bufnr('%')
|
||||
if !exists('s:options[bufnr]')
|
||||
if !has_key(s:options, bufnr)
|
||||
let s:options[bufnr] = {}
|
||||
endif
|
||||
if scope == 's'
|
||||
let name = 's:options.' . bufnr . '.' . a:name
|
||||
else
|
||||
let name = scope . ':delimitMate_' . a:name
|
||||
if exists('name')
|
||||
exec 'unlet! ' . name
|
||||
endif
|
||||
endif
|
||||
exec 'let ' . name . ' = a:value'
|
||||
let s:options[bufnr][a:name] = a:value
|
||||
endfunction "}}}
|
||||
|
||||
function! s:get(name, ...) "{{{
|
||||
if a:0 == 2
|
||||
return deepcopy(get(a:2, 'delimitMate_' . a:name, a:1))
|
||||
elseif a:0 == 1
|
||||
let bufoptions = get(s:options, bufnr('%'), {})
|
||||
return deepcopy(get(bufoptions, a:name, a:1))
|
||||
else
|
||||
return deepcopy(eval('s:options.' . bufnr('%') . '.' . a:name))
|
||||
function! s:get(...) "{{{
|
||||
let options = deepcopy(eval('s:options.' . bufnr('%')))
|
||||
if a:0
|
||||
return options[a:1]
|
||||
endif
|
||||
return options
|
||||
endfunction "}}}
|
||||
|
||||
function! s:exists(name, ...) "{{{
|
||||
@@ -384,6 +372,9 @@ function! delimitMate#QuoteDelim(char) "{{{
|
||||
" If we are in a vim file and it looks like we're starting a comment, do
|
||||
" not add a closing char.
|
||||
return a:char
|
||||
elseif a:char == "'" && index(split(&ft, '\.'), "clojure") != -1
|
||||
" If we are in a clojure file, do not add a closing apostrophe.
|
||||
return a:char
|
||||
elseif s:is_smart_quote(a:char)
|
||||
" Seems like a smart quote, insert a single char.
|
||||
return a:char
|
||||
@@ -495,8 +486,9 @@ function! delimitMate#ExpandReturn() "{{{
|
||||
" indentation is controlled by 'smartindent', and the first character on
|
||||
" the new line is '}'. If this were typed manually it would reindent to
|
||||
" match the current line. Let's reproduce that behavior.
|
||||
let shifts = indent('.') / &sw
|
||||
let spaces = indent('.') - (shifts * &sw)
|
||||
let sw = &sw == 0 ? &ts : &sw
|
||||
let shifts = indent('.') / sw
|
||||
let spaces = indent('.') - (shifts * sw)
|
||||
let val .= "^\<C-D>".repeat("\<C-T>", shifts).repeat(' ', spaces)
|
||||
endif
|
||||
" Expand:
|
||||
|
||||
@@ -191,6 +191,8 @@ e.g.: >
|
||||
let delimitMate_nesting_quotes = ['"','`']
|
||||
au FileType python let b:delimitMate_nesting_quotes = ['"']
|
||||
<
|
||||
For Python this is set by default by the plugin.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*'delimitMate_expand_cr'*
|
||||
*'b:delimitMate_expand_cr'*
|
||||
@@ -384,11 +386,11 @@ With auto-close: >
|
||||
Type | You get
|
||||
=======================
|
||||
( | (|)
|
||||
–––––––––––|–––––––––––
|
||||
-----------|-----------
|
||||
() | ()|
|
||||
–––––––––––|–––––––––––
|
||||
-----------|-----------
|
||||
(<S-Tab> | ()|
|
||||
–––––––––––|–––––––––––
|
||||
-----------|-----------
|
||||
{("<C-G>g | {("")}|
|
||||
<
|
||||
Without auto-close: >
|
||||
@@ -396,11 +398,11 @@ Without auto-close: >
|
||||
Type | You get
|
||||
=========================
|
||||
() | (|)
|
||||
–––––––––-----|––––––––––
|
||||
--------------|----------
|
||||
()) | ()|
|
||||
–––––––––-----|––––––––––
|
||||
--------------|----------
|
||||
()<S-Tab> | ()|
|
||||
––––––––––––––|–––––––––––
|
||||
--------------|----------
|
||||
{}()""<C-G>g | {("")}|
|
||||
<
|
||||
NOTE: Abbreviations will not be expanded by delimiters used on delimitMate,
|
||||
|
||||
@@ -29,15 +29,14 @@ let delimitMate_version = "2.8"
|
||||
" Functions: {{{
|
||||
|
||||
function! s:option_init(name, default) "{{{
|
||||
let b = exists("b:delimitMate_" . a:name)
|
||||
let g = exists("g:delimitMate_" . a:name)
|
||||
let opt_name = "delimitMate_" . a:name
|
||||
" Find value to use.
|
||||
if !b && !g
|
||||
if !has_key(b:, opt_name) && !has_key(g:, opt_name)
|
||||
let value = a:default
|
||||
elseif b
|
||||
exec "let value = b:delimitMate_" . a:name
|
||||
elseif has_key(b:, opt_name)
|
||||
let value = b:[opt_name]
|
||||
else
|
||||
exec "let value = g:delimitMate_" . a:name
|
||||
let value = g:[opt_name]
|
||||
endif
|
||||
call s:set(a:name, value)
|
||||
endfunction "}}}
|
||||
@@ -48,8 +47,8 @@ function! s:init() "{{{
|
||||
call s:option_init("autoclose", 1)
|
||||
" matchpairs
|
||||
call s:option_init("matchpairs", string(&matchpairs)[1:-2])
|
||||
call s:option_init("matchpairs_list", map(split(s:get('matchpairs'), '.:.\zs,\ze.:.'), 'split(v:val, ''^.\zs:\ze.$'')'))
|
||||
let pairs = s:get('matchpairs_list')
|
||||
call s:option_init("matchpairs_list", map(split(s:get('matchpairs', ''), '.:.\zs,\ze.:.'), 'split(v:val, ''^.\zs:\ze.$'')'))
|
||||
let pairs = s:get('matchpairs_list', [])
|
||||
if len(filter(pairs, 'v:val[0] ==# v:val[1]'))
|
||||
echohl ErrorMsg
|
||||
echom 'delimitMate: each member of a pair in delimitMate_matchpairs must be different from each other.'
|
||||
@@ -57,17 +56,17 @@ function! s:init() "{{{
|
||||
echohl Normal
|
||||
return 0
|
||||
endif
|
||||
call s:option_init("left_delims", map(copy(s:get('matchpairs_list')), 'v:val[0]'))
|
||||
call s:option_init("right_delims", map(copy(s:get('matchpairs_list')), 'v:val[1]'))
|
||||
call s:option_init("left_delims", map(copy(s:get('matchpairs_list', [])), 'v:val[0]'))
|
||||
call s:option_init("right_delims", map(copy(s:get('matchpairs_list', [])), 'v:val[1]'))
|
||||
" quotes
|
||||
call s:option_init("quotes", "\" ' `")
|
||||
call s:option_init("quotes_list",split(s:get('quotes'), '\s\+'))
|
||||
call s:option_init("quotes_list",split(s:get('quotes', ''), '\s\+'))
|
||||
" nesting_quotes
|
||||
call s:option_init("nesting_quotes", [])
|
||||
" excluded_regions
|
||||
call s:option_init("excluded_regions", "Comment")
|
||||
call s:option_init("excluded_regions_list", split(s:get('excluded_regions'), ',\s*'))
|
||||
let enabled = len(s:get('excluded_regions_list')) > 0
|
||||
call s:option_init("excluded_regions_list", split(s:get('excluded_regions', ''), ',\s*'))
|
||||
let enabled = len(s:get('excluded_regions_list', [])) > 0
|
||||
call s:option_init("excluded_regions_enabled", enabled)
|
||||
" expand_space
|
||||
if exists("b:delimitMate_expand_space") && type(b:delimitMate_expand_space) == type("")
|
||||
@@ -110,7 +109,7 @@ function! s:init() "{{{
|
||||
call s:option_init("smart_matchpairs", '^\%(\w\|\!\|[£$]\|[^[:punct:][:space:]]\)')
|
||||
" smart_quotes
|
||||
" XXX: backward compatibility. Ugly, should go the way of the dodo soon.
|
||||
let quotes = escape(join(s:get('quotes_list'), ''), '\-^[]')
|
||||
let quotes = escape(join(s:get('quotes_list', []), ''), '\-^[]')
|
||||
let default_smart_quotes = '\%(\w\|[^[:punct:][:space:]' . quotes . ']\|\%(\\\\\)*\\\)\%#\|\%#\%(\w\|[^[:space:][:punct:]' . quotes . ']\)'
|
||||
if exists('g:delimitMate_smart_quotes') && type(g:delimitMate_smart_quotes) == type(0)
|
||||
if g:delimitMate_smart_quotes
|
||||
@@ -134,7 +133,7 @@ function! s:init() "{{{
|
||||
call s:option_init("smart_quotes", default_smart_quotes)
|
||||
" apostrophes
|
||||
call s:option_init("apostrophes", "")
|
||||
call s:option_init("apostrophes_list", split(s:get('apostrophes'), ":\s*"))
|
||||
call s:option_init("apostrophes_list", split(s:get('apostrophes', ''), ":\s*"))
|
||||
" tab2exit
|
||||
call s:option_init("tab2exit", 1)
|
||||
" balance_matchpairs
|
||||
@@ -146,9 +145,10 @@ function! s:init() "{{{
|
||||
return 1
|
||||
endfunction "}}} Init()
|
||||
|
||||
function! s:get(...) " {{{
|
||||
return call('delimitMate#Get', a:000)
|
||||
endfunction " }}}
|
||||
function! s:get(name, default) "{{{
|
||||
let bufoptions = delimitMate#Get()
|
||||
return get(bufoptions, a:name, a:default)
|
||||
endfunction "}}}
|
||||
|
||||
function! s:set(...) " {{{
|
||||
return call('delimitMate#Set', a:000)
|
||||
@@ -164,7 +164,7 @@ function! s:Map() "{{{
|
||||
set keymap=
|
||||
set cpo&vim
|
||||
silent! doautocmd <nomodeline> User delimitMate_map
|
||||
if s:get('autoclose')
|
||||
if s:get('autoclose', 1)
|
||||
call s:AutoClose()
|
||||
else
|
||||
call s:NoAutoClose()
|
||||
@@ -270,7 +270,7 @@ endfunction "}}}
|
||||
|
||||
function! s:NoAutoClose() "{{{
|
||||
" inoremap <buffer> ) <C-R>=delimitMate#SkipDelim('\)')<CR>
|
||||
for delim in s:get('right_delims') + s:get('quotes_list')
|
||||
for delim in s:get('right_delims', []) + s:get('quotes_list', [])
|
||||
if delim == '|'
|
||||
let delim = '<Bar>'
|
||||
endif
|
||||
@@ -283,9 +283,9 @@ function! s:AutoClose() "{{{
|
||||
" Add matching pair and jump to the midle:
|
||||
" inoremap <silent> <buffer> ( ()<Left>
|
||||
let i = 0
|
||||
while i < len(s:get('matchpairs_list'))
|
||||
let ld = s:get('left_delims')[i] == '|' ? '<bar>' : s:get('left_delims')[i]
|
||||
let rd = s:get('right_delims')[i] == '|' ? '<bar>' : s:get('right_delims')[i]
|
||||
while i < len(s:get('matchpairs_list', []))
|
||||
let ld = s:get('left_delims', [])[i] == '|' ? '<bar>' : s:get('left_delims', [])[i]
|
||||
let rd = s:get('right_delims', [])[i] == '|' ? '<bar>' : s:get('right_delims', [])[i]
|
||||
exec 'inoremap <expr><silent> <Plug>delimitMate' . ld
|
||||
\. ' <SID>TriggerAbb().delimitMate#ParenDelim("' . escape(rd, '|') . '")'
|
||||
exec 'silent! imap <unique> <buffer> '.ld
|
||||
@@ -294,7 +294,7 @@ function! s:AutoClose() "{{{
|
||||
endwhile
|
||||
|
||||
" Exit from inside the matching pair:
|
||||
for delim in s:get('right_delims')
|
||||
for delim in s:get('right_delims', [])
|
||||
let delim = delim == '|' ? '<bar>' : delim
|
||||
exec 'inoremap <expr><silent> <Plug>delimitMate' . delim
|
||||
\. ' <SID>TriggerAbb().delimitMate#JumpOut("\' . delim . '")'
|
||||
@@ -304,7 +304,7 @@ function! s:AutoClose() "{{{
|
||||
|
||||
" Add matching quote and jump to the midle, or exit if inside a pair of matching quotes:
|
||||
" inoremap <silent> <buffer> " <C-R>=delimitMate#QuoteDelim("\"")<CR>
|
||||
for delim in s:get('quotes_list')
|
||||
for delim in s:get('quotes_list', [])
|
||||
if delim == '|'
|
||||
let delim = '<Bar>'
|
||||
endif
|
||||
@@ -316,7 +316,7 @@ function! s:AutoClose() "{{{
|
||||
|
||||
" Try to fix the use of apostrophes (kept for backward compatibility):
|
||||
" inoremap <silent> <buffer> n't n't
|
||||
for map in s:get('apostrophes_list')
|
||||
for map in s:get('apostrophes_list', [])
|
||||
exec "inoremap <silent> " . map . " " . map
|
||||
exec 'silent! imap <unique> <buffer> ' . map . ' <Plug>delimitMate' . map
|
||||
endfor
|
||||
@@ -340,17 +340,17 @@ function! s:ExtraMappings() "{{{
|
||||
endif
|
||||
" Expand return if inside an empty pair:
|
||||
inoremap <expr><silent> <Plug>delimitMateCR <SID>TriggerAbb()."\<C-R>=delimitMate#ExpandReturn()\<CR>"
|
||||
if s:get('expand_cr') && !hasmapto('<Plug>delimitMateCR', 'i') && maparg('<CR>', 'i') == ''
|
||||
if s:get('expand_cr', 0) && !hasmapto('<Plug>delimitMateCR', 'i') && maparg('<CR>', 'i') == ''
|
||||
silent! imap <unique> <buffer> <CR> <Plug>delimitMateCR
|
||||
endif
|
||||
" Expand space if inside an empty pair:
|
||||
inoremap <expr><silent> <Plug>delimitMateSpace <SID>TriggerAbb()."\<C-R>=delimitMate#ExpandSpace()\<CR>"
|
||||
if s:get('expand_space') && !hasmapto('<Plug>delimitMateSpace', 'i') && maparg('<Space>', 'i') == ''
|
||||
if s:get('expand_space', 0) && !hasmapto('<Plug>delimitMateSpace', 'i') && maparg('<Space>', 'i') == ''
|
||||
silent! imap <unique> <buffer> <Space> <Plug>delimitMateSpace
|
||||
endif
|
||||
" Jump over any delimiter:
|
||||
inoremap <expr><silent> <Plug>delimitMateS-Tab <SID>TriggerAbb()."\<C-R>=delimitMate#JumpAny()\<CR>"
|
||||
if s:get('tab2exit') && !hasmapto('<Plug>delimitMateS-Tab', 'i') && maparg('<S-Tab>', 'i') == ''
|
||||
if s:get('tab2exit', 0) && !hasmapto('<Plug>delimitMateS-Tab', 'i') && maparg('<S-Tab>', 'i') == ''
|
||||
silent! imap <unique> <buffer> <S-Tab> <Plug>delimitMateS-Tab
|
||||
endif
|
||||
" Jump over next delimiters
|
||||
@@ -383,9 +383,10 @@ augroup delimitMate
|
||||
au!
|
||||
" Run on file type change.
|
||||
au FileType * call <SID>setup()
|
||||
au FileType python let b:delimitMate_nesting_quotes = ['"', "'"]
|
||||
|
||||
" Run on new buffers.
|
||||
au BufNewFile,BufRead,BufEnter *
|
||||
au BufNewFile,BufRead,BufEnter,CmdwinEnter *
|
||||
\ if !exists('b:delimitMate_was_here') |
|
||||
\ call <SID>setup() |
|
||||
\ let b:delimitMate_was_here = 1 |
|
||||
|
||||
Reference in New Issue
Block a user