From 2c8b586679c6d57bdc225e2de9854b7cb2ea1c47 Mon Sep 17 00:00:00 2001 From: Israel Chauca Fuentes Date: Sun, 9 May 2010 15:23:30 -0500 Subject: [PATCH] Small fixes and documentation updates. --- Makefile | 1 + autoload/delimitMate.vim | 16 +++++----- autoload/delimitMateTests.vim | 20 ++++++------ doc/delimitMate.txt | 58 +++++++++++++++++++---------------- plugin/delimitMate.vim | 7 +++-- 5 files changed, 56 insertions(+), 46 deletions(-) diff --git a/Makefile b/Makefile index 38e4a82..f319912 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,7 @@ doc_update: install zip: zip -r ${PLUGIN}.zip doc plugin autoload zip ${PLUGIN}.zip -d \*.sw\? + zip ${PLUGIN}.zip -d autoload/${PLUGIN}Tests.vim vimball: install echo doc/${PLUGIN}.txt > vimball.txt diff --git a/autoload/delimitMate.vim b/autoload/delimitMate.vim index ecb36a1..8204e65 100644 --- a/autoload/delimitMate.vim +++ b/autoload/delimitMate.vim @@ -115,7 +115,7 @@ endfunction "}}} function! delimitMate#IsCRExpansion() " {{{ let nchar = getline(line('.')-1)[-1:] - let schar = getline(line('.')+1)[-1:] + let schar = getline(line('.')+1)[:0] let isEmpty = getline('.') == "" if index(b:delimitMate_left_delims, nchar) > -1 && \ index(b:delimitMate_left_delims, nchar) == index(b:delimitMate_right_delims, schar) && @@ -375,7 +375,7 @@ function! delimitMate#Finish() " {{{ let buffer = join(b:delimitMate_buffer, '') let line = getline('.') let col = col('.') -2 - echom 'col: ' . col . '-' . line[:col] . "|" . line[col+len+1:] . '%' . buffer + "echom 'col: ' . col . '-' . line[:col] . "|" . line[col+len+1:] . '%' . buffer call setline('.', line[:col] . line[col+len+1:]) let i = 1 let lefts = '' @@ -469,14 +469,14 @@ function! delimitMate#ExtraMappings() "{{{ inoremap =delimitMate#Finish() " Flush the char buffer on mouse click: - inoremap =delimitMate#FlushBuffer() - inoremap =delimitMate#FlushBuffer() + inoremap =delimitMate#Finish() + inoremap =delimitMate#Finish() " Flush the char buffer on key movements: - inoremap =delimitMate#FlushBuffer() - inoremap =delimitMate#FlushBuffer() - inoremap =delimitMate#FlushBuffer() - inoremap =delimitMate#FlushBuffer() + inoremap =delimitMate#Finish() + inoremap =delimitMate#Finish() + inoremap =delimitMate#Finish() + inoremap =delimitMate#Finish() inoremap =delimitMate#Del() diff --git a/autoload/delimitMateTests.vim b/autoload/delimitMateTests.vim index 8fc7203..669f647 100644 --- a/autoload/delimitMateTests.vim +++ b/autoload/delimitMateTests.vim @@ -1,6 +1,6 @@ function! delimitMateTests#Main() " {{{ if !exists("g:delimitMate_testing") - echoerr "delimitMateTests#Main(): You shouldn't use this function!" + echoerr "delimitMateTests#Main(): If you really want to use me, you must set delimitMate_testing to any value." return endif nmap :qall! @@ -10,7 +10,7 @@ function! delimitMateTests#Main() " {{{ let b:delimitMate_autoclose = 1 let b:delimitMate_matchpairs = &matchpairs let b:delimitMate_quotes = "\" ' `" - let b:delimitMate_excluded_regions = ["Comment"] + let b:delimitMate_excluded_regions = "Comment" silent! unlet b:delimitMate_visual_leader let b:delimitMate_expand_space = 0 let b:delimitMate_expand_cr = 0 @@ -45,7 +45,6 @@ function! delimitMateTests#Main() " {{{ let text = text . "" . getline(i) let i += 1 endwhile - echom "text: " . text if result == 0 exec "let b:test_results['" . substitute(a:name, "[^a-zA-Z0-9_]", "_", "g") . "'] = 'Passed: ' . text . ' == ' . join(a:output, '')" else @@ -58,7 +57,6 @@ function! delimitMateTests#Main() " {{{ call setpos('.', [0, 1, 1, 0]) let result = len(a:output) != line('$') for line in a:output - echom line . " vs " . getline('.') if getline('.') != line || result == 1 let result = 1 break @@ -129,13 +127,21 @@ function! delimitMateTests#Main() " {{{ call RepeatLast("S Tab", ["()|()|"]) " Space expansion - call Type("Space expansion", "(\", ['( | )'], ['expand_space:1']) + call Type("Space expansion", "(\\", ['(|)'], ['expand_space:1']) + call RepeatLast("BS with space expansion", ['(|)(|)']) + + " BS with space expansion + call Type("BS with space expansion", "(\", ['( | )'], ['expand_space:1']) call RepeatLast("Space expansion", ['( | )( | )']) " Car return expansion call Type("CR expansion", "(\", ['(', '|', ')'], ['expand_cr:1']) call RepeatLast("CR expansion", ['(', '|', ')(', '|', ')']) + " BS with car return expansion + call Type("BS with CR expansion", "(\\", ['(|)'], ['expand_cr:1']) + call RepeatLast("BS with CR expansion", ['(|)(|)']) + " Visual wrapping call Type("Visual wrapping left paren", "1234\v,(", ['123(4)'], ['visual_leader:","']) cal RepeatLast("Visual wrapping left paren", ['(1)23(4)']) @@ -216,8 +222,4 @@ function! delimitMateTests#Main() " {{{ hi def link resultInequal Error " }}} endfunction " }}} - -function! delimitMateTests#Go() - call system("gvim -c 'call delimitMateTests\#Main()'") -endfunction " vim:foldmethod=marker:foldcolumn=4 diff --git a/doc/delimitMate.txt b/doc/delimitMate.txt index 6de8b50..c0fc9f2 100644 --- a/doc/delimitMate.txt +++ b/doc/delimitMate.txt @@ -1,4 +1,4 @@ -*delimitMate* Trying to keep those beasts at bay! v.2.0 *delimitMate.txt* +*delimitMate* Trying to keep those beasts at bay! v.2.1 *delimitMate.txt* ========================================================================= ~ ==== ========= ========================== ===== ===================== ~ @@ -37,23 +37,13 @@ ============================================================================== 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 -expansions. +This plug-in provides automatic closing of quotes, parenthesis, brackets, +etc., besides some other related features that should make your time in insert +mode a little bit easier. -When automatic closing is enabled, if an opening delimiter is inserted -delimitMate inserts the closing pair and places the cursor between them. When -automatic closing is disabled, no closing delimiters is inserted by -delimitMate, but if a pair of delimiters is typed, the cursor is placed in the -middle. Also, to get out of a pair of delimiters just type shift+tab or the -right delimiter and the cursor will jump to the right. - -If the cursor is inside an empty pair of delimiters, typing will -insert two spaces and the cursor will be placed in the middle; typing -will insert to car retunrs and place the cursor in the middle line, between -the delimiters. - -All of the operations are undo/redo-wise safe. +Most of the features can be modified or disabled permanently, using global +variables, or on a FileType basis, using autocommands. With a couple of +exceptions and limitations, this features don't brake undo, redo or history. ============================================================================== 2. FUNCTIONALITY *delimitMateFunctionality* @@ -118,6 +108,8 @@ Expand to: > | ) < +NOTE that the expansion of will brake the redo command. + Since and are used everywhere, I have made the functions involved in expansions global, so they can be used to make custom mappings. Read |delimitMateFunctions| for more details. @@ -125,17 +117,26 @@ in expansions global, so they can be used to make custom mappings. Read ------------------------------------------------------------------------------ 2.3 BACKSPACE *delimitMateBackspace* -If you press backspace inside an empty pair, both delimiters are deleted. If -you type shift + backspace instead, only the closing delimiter will be +If you press backspace inside an empty pair, both delimiters are deleted. When +expansions are enabled, will also delete the expansions. NOTE that +deleting expansions will brake the redo command. + +If you type shift + backspace instead, only the closing delimiter will be deleted. e.g. typing at the "|": > - What | Before | After + What | Before | After ============================================== - | call expand(|) | call expand| - ---------|------------------|----------------- - | call expand(|) | call expand(| + | call expand(|) | call expand| + ---------|-------------------|----------------- + | call expand( | ) | call expand(|) + ---------|-------------------|----------------- + | call expand( | call expand(|) + | | | + | ) | + ---------|-------------------|----------------- + | call expand(|) | call expand(| < ------------------------------------------------------------------------------ @@ -144,8 +145,8 @@ e.g. typing at the "|": > When visual mode is active this script allows for the selection to be enclosed with delimiters. But, since brackets have special meaning in visual mode, a leader (the value of 'mapleader' by default) should precede the delimiter. -This feature doesn't currently work on blockwise visual mode, any suggestions -will be welcome. +NOTE that this feature brakes the redo command and doesn't currently work on +blockwise visual mode, any suggestions will be welcome. e.g. (selection represented between square brackets): > @@ -487,7 +488,12 @@ This script was inspired by the auto-completion of delimiters of TextMate. Version Date Release notes ~ |---------|------------|-----------------------------------------------------| - 2.0 2010-04-01 * New features: + 2.1 2010-05-10 - Most of the functions have been moved to an + autoload script to avoid loading unnecessary ones. + - Fixed a problem with the redo command. + - Many small fixes. +|---------|------------|-----------------------------------------------------| + 2.0 2010-04-01 New features: - All features are redo/undo-wise safe. - A single quote typed after an alphanumeric character is considered an apostrophe and one diff --git a/plugin/delimitMate.vim b/plugin/delimitMate.vim index aa7d96a..bf39be9 100644 --- a/plugin/delimitMate.vim +++ b/plugin/delimitMate.vim @@ -25,7 +25,7 @@ if v:version < 700 endif let s:loaded_delimitMate = 1 " }}} -let delimitMate_version = '2.1_DEV' +let delimitMate_version = '2.1' "}}} @@ -70,8 +70,8 @@ function! s:Init() "{{{ else let s:excluded_regions = "Comment" endif - let b:delimitMate_excluded_regions_list = split(s:excluded_regions) " }}} - let b:delimitMate_excluded_regions_enabled = len(b:delimitMate_excluded_regions_list) + let b:delimitMate_excluded_regions_list = split(s:excluded_regions, ',\s*') + let b:delimitMate_excluded_regions_enabled = len(b:delimitMate_excluded_regions_list) " }}} " delimitMate_visual_leader {{{ if !exists("b:delimitMate_visual_leader") && !exists("g:delimitMate_visual_leader") @@ -207,6 +207,7 @@ command! DelimitMateReload call s:DelimitMateDo() " Quick test: command! DelimitMateTest call s:TestMappingsDo() +"command! DelimitMateRegions echo s:excluded_regions " Turn " Run on file type events.