57 Commits
2.3 ... 2.4.1

Author SHA1 Message Date
Israel Chauca Fuentes
4b94c38f95 Release 2.4.1. 2010-07-31 13:01:42 -05:00
Israel Chauca Fuentes
217adb3d8e Update change log. 2010-07-31 10:58:55 -05:00
Israel Chauca Fuentes
e63e373ae1 Reorder doc of options. 2010-07-31 00:48:50 -05:00
Israel Chauca Fuentes
9c11c5cc82 Fix 'smart_quotes' doc. 2010-07-31 00:22:26 -05:00
Israel Chauca Fuentes
8b24f0fd9f Add doc on 'smart_quotes' and delimitMateBalance. 2010-07-30 23:56:21 -05:00
Israel Chauca Fuentes
701e14f72f Rename unbalanced_paren to balance_matchpairs. 2010-07-30 23:54:20 -05:00
Israel Chauca Fuentes
c9c1464075 Silence some noise related to 'backspace'. 2010-07-30 23:51:20 -05:00
Israel Chauca Fuentes
e831d89acf Reset buffer with <Home> and <End>. Closes #27. 2010-07-30 02:59:43 -05:00
Israel Chauca Fuentes
133c125f93 Makefile change. 2010-07-30 02:58:12 -05:00
Israel Chauca Fuentes
b9cea6312a Release 2.4 2010-07-29 18:20:13 -05:00
Israel Chauca Fuentes
1b37d60840 Behave nicely with iminsert and imsearch. Thanks to nailxx@github.com. 2010-07-20 13:27:28 -05:00
Israel Chauca Fuentes
a70aa5285e Doc fix. Missing quotes. 2010-07-20 13:23:41 -05:00
Israel Chauca Fuentes
2eba04961d Added note about abbreviations not being expanded. # 26 2010-07-15 19:20:09 -05:00
Israel Chauca Fuentes
3519f82f79 \<Right\> doesn\'t work under terminal. #25 2010-07-15 04:10:38 -05:00
Israel Chauca Fuentes
e9491e473c Reorder some logic. 2010-07-15 04:07:56 -05:00
Israel Chauca Fuentes
9e3075cff5 Changelog update. 2010-07-03 14:43:20 -05:00
Israel Chauca Fuentes
7c9ba95565 Doc update. 2010-06-28 19:08:27 -05:00
Israel Chauca Fuentes
3ae285424c Expand smart quotes to consider [:alnum:] to the right. 2010-06-28 15:20:32 -05:00
Israel Chauca Fuentes
fa1d3b3d6a Add option to allow nesting quotes. #24 2010-06-28 13:18:04 -05:00
Israel Chauca Fuentes
63f8c2af4f Add note to the docs about <S-BS> not working on terminal. 2010-06-26 13:29:16 -05:00
Israel Chauca Fuentes
29eb98d79d Sort results from Tests#Main(). 2010-06-25 15:18:45 -05:00
Israel Chauca Fuentes
5b004ca49d Comment formatting. 2010-06-25 15:17:51 -05:00
Israel Chauca Fuentes
34df78f8ab Fix vars scope. 2010-06-25 15:17:17 -05:00
Israel Chauca Fuentes
e234e45846 #23 and vars with wrong values. 2010-06-25 15:16:25 -05:00
Israel Chauca Fuentes
081ec279ed Rename internal vars to hide them from completion. 2010-06-25 15:10:50 -05:00
Israel Chauca Fuentes
4399fa327f Doc corrections. 2010-06-23 12:53:58 -05:00
Israel Chauca Fuentes
ceaa6e01ed Deleted IsBlockVisual(). 2010-06-23 12:53:16 -05:00
Israel Chauca Fuentes
235f0dcbfb Fixed duplicate <silent>. 2010-06-23 12:52:18 -05:00
Israel Chauca Fuentes
fadd7fefbc Merge http://github.com/Lokaltog/delimitMate
Conflicts:
	autoload/delimitMate.vim
2010-06-22 21:25:05 -05:00
Israel Chauca Fuentes
193b6027c2 Fix #23. 2010-06-22 21:01:03 -05:00
Kim Silkebækken
a76439a641 Make all mappings silent
This change speeds up vim significantly in a terminal, and prevents the
annoying flickering of commands while typing.
2010-06-20 02:06:23 +02:00
Israel Chauca Fuentes
89cc598217 Update README. 2010-06-16 02:18:52 -05:00
Israel Chauca Fuentes
28ce6213fc Cosmetic changes. 2010-06-16 01:54:58 -05:00
Israel Chauca Fuentes
6d1f48c1bf Fix TestMappings(). 2010-06-16 01:54:40 -05:00
Israel Chauca Fuentes
0e20bcaff8 Use "fork" to open new gvim when testing. 2010-06-16 01:51:53 -05:00
Israel Chauca Fuentes
aae61ad8ba Use 'nomore'. 2010-06-16 01:50:33 -05:00
Israel Chauca Fuentes
4dac6ce6ac Fix TestMappings(). 2010-06-16 01:47:42 -05:00
Israel Chauca Fuentes
875a9e450b Silence some noise on UnMap(). 2010-06-16 01:45:40 -05:00
Israel Chauca Fuentes
48d2e3b9d1 Check for 'backspace' when <CR> expansion is enabled. 2010-06-16 01:44:11 -05:00
Israel Chauca Fuentes
5626a633d5 Escape \\ on options. 2010-06-16 01:40:55 -05:00
Israel Chauca Fuentes
3652ba24e3 Split Init() and simplify the set-up process. 2010-06-16 01:37:08 -05:00
Israel Chauca Fuentes
740fc90ae7 Expansion documentation and intialization fixed. 2010-06-12 22:50:14 -05:00
Israel Chauca Fuentes
e0de2dbf39 Use internal b:vars to read from user options. 2010-06-12 22:15:26 -05:00
Israel Chauca Fuentes
efcf9eb341 Formatting. 2010-06-12 12:28:50 -05:00
Israel Chauca Fuentes
2545fa5967 Reset autocmds on re-loading. 2010-06-12 12:26:30 -05:00
Israel Chauca Fuentes
c91674eed2 Doc update. 2010-06-09 19:10:29 -05:00
Israel Chauca Fuentes
542728671e Fix issue #21. 2010-06-09 12:32:57 -05:00
Israel Chauca Fuentes
d1621b6672 Block-wise visual wrapping works with limitations. 2010-06-09 03:20:11 -05:00
Israel Chauca Fuentes
6d1cc1187b Fixed issue #18 for non xterm terminals. 2010-06-08 21:54:22 -05:00
Israel Chauca Fuentes
377c3a37e1 Do not close on unbalanced parens. 2010-06-08 00:48:34 -05:00
Israel Chauca Fuentes
d03324135c Rename and reorder some function, update doc. 2010-06-07 00:54:55 -05:00
Israel Chauca Fuentes
edeaff4730 Missing quote. 2010-06-06 13:51:31 -05:00
Israel Chauca Fuentes
c85fee6eb5 README update. 2010-06-06 13:28:47 -05:00
Israel Chauca Fuentes
0ccb143a12 Doc and version update. 2010-06-06 13:22:14 -05:00
Israel Chauca Fuentes
941beed3b3 Extend detection of version string in Makefile. 2010-06-06 13:16:55 -05:00
Israel Chauca Fuentes
739a3e606c Fix: extra space inserted after <Space> expansion. 2010-06-06 02:51:30 -05:00
Israel Chauca Fuentes
61cc934b68 Give some feedback for commands. 2010-06-06 02:35:15 -05:00
7 changed files with 776 additions and 494 deletions

2
.gitignore vendored
View File

@@ -1,6 +1,8 @@
*.sw?
*.un?
*.vba
*.zip
*.gz
vimball.txt
*.orig
tags

View File

@@ -4,18 +4,13 @@ SCRIPT=$(wildcard plugin/*.vim)
AUTOL=autoload/$(PLUGIN).vim
DOC=$(wildcard doc/*.txt)
TESTS=$(wildcard autoload/*Tests.vim)
VERSION=$(shell perl -ne 'if (/\*\sCurrent\srelease:/) {s/^\s+(\d+\.\d+).*$$/\1/;print}' $(DOC))
VERSION=$(shell perl -ne 'if (/\*\sCurrent\srelease:/) {s/^\s+(\d+\.\S+)\s.*$$/\1/;print}' $(DOC))
VIMFOLDER=~/.vim/
VIM=/usr/bin/vim
.PHONY: $(PLUGIN).vba README
install: vimball
@echo install
$(VIM) -N -c ':so %' -c':q!' $(PLUGIN)-$(VERSION).vba
cp -f $(TESTS) $(VIMFOLDER)$(TESTS)
all: uninstall vimball install README zip gzip
all: vimball README zip gzip
vimball: $(PLUGIN).vba
@@ -25,11 +20,6 @@ clean:
dist-clean: clean
uninstall:
@echo uninstall
$(VIM) -N -c':RmVimball' -c':q!' $(PLUGIN)-$(VERSION).vba
rm -f $(VIMFOLDER)$(TESTS)
undo:
for i in */*.orig; do mv -f "$$i" "$${i%.*}"; done
@@ -47,8 +37,10 @@ zip:
@echo zip
rm -f *.zip
zip -r $(PLUGIN).zip doc plugin autoload
zip $(PLUGIN).zip -d \*.sw\?
zip $(PLUGIN).zip -d \*.orig
zip $(PLUGIN).zip -d \*.sw\? || echo 1
zip $(PLUGIN).zip -d \*.un\? || echo 1
zip $(PLUGIN).zip -d \*.orig || echo 1
zip $(PLUGIN).zip -d \*tags || echo 1
zip $(PLUGIN).zip -d $(TESTS)
ln -f $(PLUGIN).zip $(PLUGIN)-$(VERSION).zip
@@ -60,11 +52,11 @@ release: version all
version:
@echo version: $(VERSION)
perl -i.orig -pne 'if (/^"\sVersion:/) {s/(\d+\.\d+)/$(VERSION)/e}' $(SCRIPT) $(AUTOL)
perl -i.orig -pne 'if (/let\sdelimitMate_version/) {s/(\d+\.\d+)/$(VERSION)/e}' $(SCRIPT)
perl -i.orig -pne 'if (/beasts/) {s/(v\d+\.\d+)/v.$(VERSION)/e}' $(DOC)
perl -i.orig -pne 'if (/^"\sVersion:/) {s/(\d+\.\S+)/$(VERSION)/}' $(SCRIPT) $(AUTOL)
perl -i.orig -pne 'if (/let\sdelimitMate_version/) {s/"(\d+\.\S+)"/"$(VERSION)"/}' $(SCRIPT)
perl -i.orig -pne 'if (/beasts/) {s/(v\d+\.\S+)/v$(VERSION)/}' $(DOC)
perl -i.orig -MPOSIX -pne 'if (/^"\sModified:/) {$$now_string = strftime "%F", localtime; s/(\d+-\d+-\d+)/$$now_string/e}' $(SCRIPT) $(AUTOL)
perl -i.orig -MPOSIX -pne 'if (/^\s+$(VERSION)\s+\d+-\d+-\d+\s+\*/) {$$now_string = strftime "%F", localtime; s/(\d+-\d+-\d+)/$$now_string/e}' $(DOC)
perl -i.orig -MPOSIX -pne 'if (/^\s+$(VERSION)\s+\d+-\d+-\d+\s+\*/) {$$now_string = strftime "%F", localtime; s/(\d+-\d+-\d+)/$$now_string/}' $(DOC)
@echo Version: $(VERSION)
echo:

198
README
View File

@@ -1,4 +1,4 @@
*delimitMate* Trying to keep those beasts at bay! v2.3 *delimitMate.txt*
*delimitMate* Trying to keep those beasts at bay! v2.4.1 *delimitMate.txt*
@@ -26,8 +26,9 @@
2.3 Backspace__________________________|delimitMateBackspace|
2.4 Visual wrapping____________________|delimitMateVisualWrapping|
2.5 Smart Quotes_______________________|delimitMateSmartQuotes|
2.6 FileType based configuration_______|delimitMateFileType|
2.7 Syntax awareness___________________|delimitMateSyntax|
2.6 Balancing matching pairs___________|delimitMateBalance|
2.7 FileType based configuration_______|delimitMateFileType|
2.8 Syntax awareness___________________|delimitMateSyntax|
3. Customization___________________________|delimitMateOptions|
3.1 Options summary____________________|delimitMateOptionSummary|
3.2 Options details____________________|delimitMateOptionDetails|
@@ -90,6 +91,9 @@ Without auto-close: >
-|
()<S-Tab> | ()|
<
NOTE: Abbreviations will not be expanded by delimiters used on delimitMate,
you should use <C-]> (read |i_CTRL-]|) to expand them on the go.
------------------------------------------------------------------------------
2.2 EXPANSION OF SPACE AND CAR RETURN *delimitMateExpansion*
@@ -125,8 +129,9 @@ If you press backspace inside an empty pair, both delimiters are deleted. When
expansions are enabled, <BS> will also delete the expansions. NOTE that
deleting <CR> expansions will brake the redo command.
If you type shift + backspace instead, only the closing delimiter will be
deleted.
If you type <S-BS> (shift + backspace) instead, only the closing delimiter
will be deleted. NOTE that this will not usually work when using Vim from the
terminal, see 'delimitMate#JumpAny()' below to see how to fix it.
e.g. typing at the "|": >
@@ -149,8 +154,9 @@ 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.
NOTE that this feature brakes the redo command and doesn't currently work on
blockwise visual mode, any suggestions to fix this will be very welcome.
NOTE that this feature brakes the redo command and doesn't currently work well
on blockwise visual mode when the selection has lines one character smaller
than the rest, any suggestions to fix this will be very welcome.
e.g. (selection represented between square brackets): >
@@ -162,9 +168,10 @@ e.g. (selection represented between square brackets): >
------------------------------------------------------------------------------
2.5 SMART QUOTES *delimitMateSmartQuotes*
Only one quote will be inserted following a quote, a "\" or an alphanumeric
character. This should cover closing quotes, escaped quotes and apostrophes.
Except for apostrophes, this feature can be disabled setting the option
Only one quote will be inserted following a quote, a "\" or, following or
preceding an alphanumeric character. This should cover closing quotes after a
string, opening quotes before a string, escaped quotes and apostrophes. Except
for apostrophes, this feature can be disabled setting the option
|'delimitMate_smart_quotes'| to 0.
e.g. typing at the "|": >
@@ -176,7 +183,22 @@ e.g. typing at the "|": >
' | I| | I'|
<
------------------------------------------------------------------------------
2.6 FILE TYPE BASED CONFIGURATION *delimitMateFileType*
2.6 BALANCING MATCHING PAIRS *delimitMateBalance*
When inserting an opening paren and |'delimitMate_balance_matchpairs'| is
enabled, delimitMate will try to balance the closing pairs in the current
line.
e.g. typing at the "|": >
What | Before | After
=======================================
( | |) | (|)
( | | | (|)
( | (|) | ((|))
<
------------------------------------------------------------------------------
2.7 FILE TYPE BASED CONFIGURATION *delimitMateFileType*
delimitMate options can be set globally for all buffers using global
("regular") variables in your |vimrc| file. But |:autocmd| can be used to set
@@ -196,7 +218,7 @@ NOTE that you should use buffer variables (|b:var|) only to set options with
|:autocmd|, for global options use regular variables (|g:var|) in your vimrc.
------------------------------------------------------------------------------
2.7 SYNTAX AWARENESS *delimitMateSyntax*
2.8 SYNTAX AWARENESS *delimitMateSyntax*
The features of this plug-in might not be always helpful, comments and strings
usualy don't need auto-completion. delimitMate monitors which region is being
@@ -222,35 +244,41 @@ The behaviour of this script can be customized setting the following options
in your vimrc file. You can use local options to set the configuration for
specific file types, see |delimitMateOptionDetails| for examples.
|'loaded_delimitMate'| Turns off the script.
|'loaded_delimitMate'| Turns off the script.
|'delimitMate_autoclose'| Tells delimitMate whether to automagically
|'delimitMate_autoclose'| Tells delimitMate whether to automagically
insert the closing delimiter.
|'delimitMate_matchpairs'| Tells delimitMate which characters are
|'delimitMate_matchpairs'| Tells delimitMate which characters are
matching pairs.
|'delimitMate_quotes'| Tells delimitMate which quotes should be
|'delimitMate_quotes'| Tells delimitMate which quotes should be
used.
|'delimitMate_visual_leader'| Sets the leader to be used in visual mode.
|'delimitMate_nesting_quotes'| Tells delimitMate which quotes should be
allowed to be nested.
|'delimitMate_expand_cr'| Turns on/off the expansion of <CR>.
|'delimitMate_visual_leader'| Sets the leader to be used in visual mode.
|'delimitMate_expand_space'| Turns on/off the expansion of <Space>.
|'delimitMate_expand_cr'| Turns on/off the expansion of <CR>.
|'delimitMate_excluded_ft'| Turns off the script for the given file types.
|'delimitMate_expand_space'| Turns on/off the expansion of <Space>.
|'delimitMate_excluded_regions'|Turns off the script for the given regions or
|'delimitMate_smart_quotes'| Turns on/off the "smart quotes" feature.
|'delimitMate_balance_matchpairs'|Turns on/off the "balance matching pairs"
feature.
|'delimitMate_excluded_regions'| Turns off the script for the given regions or
syntax group names.
|'delimitMate_apostrophes'| Tells delimitMate how it should "fix"
|'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. NOTE: Not needed any more, kept
for compatibility with older versions.
|'delimitMate_smart_quotes'| Turns on/off the "smart quotes" feature.
------------------------------------------------------------------------------
3.2 OPTIONS DETAILS *delimitMateOptionDetails*
@@ -286,7 +314,7 @@ e.g.: >
------------------------------------------------------------------------------
*'delimitMate_matchpairs'*
*'b:delimitMate_matchpairs'*
Values: A string with |matchpairs| syntax. ~
Values: A string with |'matchpairs'| syntax. ~
Default: &matchpairs ~
Use this option to tell delimitMate which characters should be considered
@@ -304,9 +332,21 @@ Default: "\" ' `" ~
Use this option to tell delimitMate which characters should be considered as
quotes. Read |delimitMateAutoClose| for details.
e.g.: >
let b:delimitMate_quotes = "\" ' ` *"
let delimitMate_quotes = "\" ' ` *"
au FileType html let b:delimitMate_quotes = "\" '"
<
------------------------------------------------------------------------------
*'delimitMate_nesting_quotes'*
*'b:delimitMate_nesting_quotes'*
Values: A list of quotes. ~
Default: [] ~
Quotes listed here will not be able to jump out of the empty pair, thus
allowing the autoclosed quotes to be nested.
e.g.: >
let delimitMate_nesting_quotes = ['"','`']
au FileType python let b:delimitMate_nesting_quotes = ['"']
<
------------------------------------------------------------------------------
*'delimitMate_visual_leader'*
*'b:delimitMate_visual_leader'*
@@ -328,30 +368,44 @@ Default: 0 ~
This option turns on/off the expansion of <CR>. Read |delimitMateExpansion|
for details.
e.g.: >
let b:delimitMate_expand_cr = "\<CR>\<CR>\<Up>"
au FileType mail let b:delimitMate_expand_cr = "\<CR>"
let delimitMate_expand_cr = 1
au FileType mail let b:delimitMate_expand_cr = 1
<
------------------------------------------------------------------------------
*'delimitMate_expand_space'*
*'b:delimitMate_expand_space'*
Values: A key mapping. ~
Default: "\<Space>" ~
Values: 1 or 0 ~
Default: 0 ~
This option turns on/off the expansion of <Space>. Read |delimitMateExpansion|
for details.
e.g.: >
let delimitMate_expand_space = "\<Space>\<Space>\<Left>"
au FileType tcl let b:delimitMate_expand_space = "\<Space>"
let delimitMate_expand_space = 1
au FileType tcl let b:delimitMate_expand_space = 1
<
------------------------------------------------------------------------------
*'delimitMate_excluded_ft'*
Values: A string of file type names separated by single commas. ~
Default: Empty. ~
*'delimitMate_smart_quotes'*
*'b:delimitMate_smart_quotes'*
Values: 1 or 0 ~
Default: 1 ~
This options turns delimitMate off for the listed file types, use this option
only if you don't want any of the features it provides on those file types.
This option turns on/off the smart quotes feature. Read
|delimitMateSmartQuotes| for details.
e.g.: >
let delimitMate_excluded_ft = "mail,txt"
let delimitMate_smart_quotes = 0
au FileType tcl let b:delimitMate_smart_quotes = 0
<
------------------------------------------------------------------------------
*'delimitMate_balance_matchpairs'*
*'b:delimitMate_balance_matchpairs'*
Values: 1 or 0 ~
Default: 0 ~
This option turns on/off the balancing of matching pairs. Read
|delimitMateBalance| for details.
e.g.: >
let delimitMate_balance_matchpairs = 1
au FileType tcl let b:delimitMate_balance_matchpairs = 1
<
------------------------------------------------------------------------------
*'delimitMate_excluded_regions'*
@@ -363,6 +417,16 @@ for more info about what is a region.
e.g.: >
let delimitMate_excluded_regions = "Comments,String"
<
------------------------------------------------------------------------------
*'delimitMate_excluded_ft'*
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 you don't want any of the features it provides on those file types.
e.g.: >
let delimitMate_excluded_ft = "mail,txt"
<
------------------------------------------------------------------------------
*'delimitMate_apostrophes'*
Values: Strings separated by ":". ~
@@ -471,9 +535,15 @@ Functions should be used enclosed between <C-R>= and <CR>, otherwise they
might not work as expected or at all.
------------------------------------------------------------------------------
delimitMate#WithinEmptyPair() *delimitMate_WithinEmptyPair*
delimitMate#WithinEmptyPair() *delimitMate_WithinEmptyPair()*
Returns 1 if the cursor is inside an empty pair, 0 otherwise.
e.g.: >
inoremap <expr> <CR> delimitMate#WithinEmptyPair() ?
\ "\<C-R>=delimitMate#ExpandReturn()\<CR>" :
\ "external_mapping"
<
------------------------------------------------------------------------------
delimitMate#ExpandReturn() *delimitMate#ExpandReturn()*
@@ -484,7 +554,8 @@ Returns the expansion for <CR> if enabled and inside an empty pair, returns
e.g.: This mapping could be used to select an item on a pop-up menu or expand
<CR> inside an empty pair: >
inoremap <expr> <CR> pumvisible() ? "\<c-y>" :
inoremap <expr> <CR> pumvisible() ?
\"\<c-y>" :
\ "\<C-R>=delimitMate#ExpandReturn()\<CR>"
<
------------------------------------------------------------------------------
@@ -509,14 +580,14 @@ This function returns a mapping that will make the cursor jump to the right
when delimitMate#ShouldJump() returns 1, returns the argument "key" otherwise.
e.g.: You can use this to create your own mapping to jump over any delimiter.
>
inoremap <C-Tab> <C-R>=delimitMate#JumpAny("\<S-Tab>")<CR>
inoremap <C-Tab> <C-R>=delimitMate#JumpAny("\<C-Tab>")<CR>
<
==============================================================================
6. TODO LIST *delimitMateTodo*
- Automatic set-up by file type.
- Make visual wrapping work on blockwise visual mode.
- Make block-wise visual wrapping work on un-even regions.
==============================================================================
7. MAINTAINER *delimitMateMaintainer*
@@ -541,34 +612,64 @@ from the following sources:
From the comments on the previous blog post and from:
http://gist.github.com/144619
- Vim Scripts:
http://www.vim.org/scripts
- Karl Guertin
AutoClose:
http://www.vim.org/scripts/script.php?script_id=1849
This script was inspired by the auto-completion of delimiters of TextMate.
- Thiago Alves
AutoClose:
http://www.vim.org/scripts/script.php?script_id=2009
- Edoardo Vacchi
ClosePairs:
http://www.vim.org/scripts/script.php?script_id=2373
This script was inspired by the auto-completion of delimiters on TextMate.
==============================================================================
9. HISTORY *delimitMateHistory*
Version Date Release notes ~
|---------|------------|-----------------------------------------------------|
2.3 2010-06-06 * Current release:
- Syntax aware: Will turn off when editing comments
2.4.1 2010-07-31 * Current release:
- Fix problem with <Home> and <End>.
- Add missing doc on |'delimitMate_smart_quotes'|,
|delimitMateBalance| and
|'delimitMate_balance_matchpairs'|.
|---------|------------|-----------------------------------------------------|
2.4 2010-07-29 * - Unbalanced parens: see :help delimitMateBalance.
- Visual wrapping now works on block-wise visual
with some limitations.
- Arrow keys didn't work on terminal.
- Added option to allow nested quotes.
- Expand Smart Quotes to look for a string on the
right of the cursor.
|---------|------------|-----------------------------------------------------|
2.3.1 2010-06-06 * - Fix: an extra <Space> is inserted after <Space>
expansion.
|---------|------------|-----------------------------------------------------|
2.3 2010-06-06 * - Syntax aware: Will turn off when editing comments
or other regions, customizable.
- Changed format of most mappings.
- Fix: <CR> expansion doesn't brake automatic
indentation adjustments anymore.
- Fix: Arrow keys would insert A, B, C or D instead
of moving the cursor when using Vim on a terminal.
|---------|------------|-----------------------------------------------------|
2.2 2010-05-16 * - Added command to switch the plug-in on and off.
- Fix: some problems with <Left>, <Right> and <CR>.
- Fix: A small problem when inserting a delimiter at
the beginning of the line.
|---------|------------|-----------------------------------------------------|
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.
@@ -584,7 +685,6 @@ This script was inspired by the auto-completion of delimiters of TextMate.
active if you have any of the expansion options
set.
- <S-Backspace> deletes the closing delimiter.
* Fixed bug:
- s:vars were being used to store buffer options.
@@ -643,4 +743,4 @@ _____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|____ ~
__|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_ ~
_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|____ ~
vim:tw=78:ts=8:ft=help:norl:formatoptions+=tcroqn:autoindent:
vim:tw=78:et:ts=2:sw=2:ft=help:norl:formatoptions+=tcroqn:autoindent:

View File

@@ -1,158 +1,172 @@
" ============================================================================
" File: autoload/delimitMate.vim
" Version: 2.3
" Modified: 2010-06-06
" Version: 2.4.1
" Modified: 2010-07-31
" Description: This plugin provides auto-completion for quotes, parens, etc.
" Maintainer: Israel Chauca F. <israelchauca@gmail.com>
" Manual: Read ":help delimitMate".
" Utilities {{{
function! delimitMate#option_init(name, default) "{{{
let b = exists("b:delimitMate_" . a:name)
let g = exists("g:delimitMate_" . a:name)
let prefix = "_l_delimitMate_"
if !b && !g
let sufix = a:default
elseif !b && g
exec "let sufix = g:delimitMate_" . a:name
else
exec "let sufix = b:delimitMate_" . a:name
endif
if exists("b:" . prefix . a:name)
exec "unlockvar! b:" . prefix . a:name
endif
exec "let b:" . prefix . a:name . " = " . string(sufix)
exec "lockvar! b:" . prefix . a:name
endfunction "}}}
function! delimitMate#Init() "{{{
" Initialize variables:
" delimitMate_autoclose {{{
if !exists("b:delimitMate_autoclose") && !exists("g:delimitMate_autoclose")
let b:delimitMate_autoclose = 1
elseif !exists("b:delimitMate_autoclose") && exists("g:delimitMate_autoclose")
let b:delimitMate_autoclose = g:delimitMate_autoclose
else
" Nothing to do.
endif " }}}
" autoclose
call delimitMate#option_init("autoclose", 1)
" delimitMate_matchpairs {{{
if !exists("b:delimitMate_matchpairs") && !exists("g:delimitMate_matchpairs")
let s:matchpairs_temp = &matchpairs
elseif exists("b:delimitMate_matchpairs")
let s:matchpairs_temp = b:delimitMate_matchpairs
else
let s:matchpairs_temp = g:delimitMate_matchpairs
endif " }}}
" matchpairs
call delimitMate#option_init("matchpairs", string(&matchpairs)[1:-2])
call delimitMate#option_init("matchpairs_list", split(b:_l_delimitMate_matchpairs, ','))
call delimitMate#option_init("left_delims", split(b:_l_delimitMate_matchpairs, ':.,\='))
call delimitMate#option_init("right_delims", split(b:_l_delimitMate_matchpairs, ',\=.:'))
" delimitMate_quotes {{{
if exists("b:delimitMate_quotes")
let s:quotes = split(b:delimitMate_quotes)
elseif exists("g:delimitMate_quotes")
let s:quotes = split(g:delimitMate_quotes)
else
let s:quotes = split("\" ' `")
endif
let b:delimitMate_quotes_list = s:quotes " }}}
" quotes
call delimitMate#option_init("quotes", "\" ' `")
call delimitMate#option_init("quotes_list", split(b:_l_delimitMate_quotes))
" delimitMate_excluded_regions {{{
if exists("b:delimitMate_excluded_regions")
let s:excluded_regions = b:delimitMate_excluded_regions
elseif exists("g:delimitMate_excluded_regions")
let s:excluded_regions = g:delimitMate_excluded_regions
else
let s:excluded_regions = "Comment"
endif
let b:delimitMate_excluded_regions_list = split(s:excluded_regions, ',\s*')
let b:delimitMate_excluded_regions_enabled = len(b:delimitMate_excluded_regions_list) " }}}
" nesting_quotes
call delimitMate#option_init("nesting_quotes", [])
" delimitMate_visual_leader {{{
if !exists("b:delimitMate_visual_leader") && !exists("g:delimitMate_visual_leader")
let b:delimitMate_visual_leader = exists('b:maplocalleader') ? b:maplocalleader :
" excluded_regions
call delimitMate#option_init("excluded_regions", "Comment")
call delimitMate#option_init("excluded_regions_list", split(b:_l_delimitMate_excluded_regions, ',\s*'))
let enabled = len(b:_l_delimitMate_excluded_regions_list) > 0
call delimitMate#option_init("excluded_regions_enabled", enabled)
" visual_leader
let leader = exists('b:maplocalleader') ? b:maplocalleader :
\ exists('g:mapleader') ? g:mapleader : "\\"
elseif !exists("b:delimitMate_visual_leader") && exists("g:delimitMate_visual_leader")
let b:delimitMate_visual_leader = g:delimitMate_visual_leader
else
" Nothing to do.
endif " }}}
call delimitMate#option_init("visual_leader", leader)
" delimitMate_expand_space {{{
if !exists("b:delimitMate_expand_space") && !exists("g:delimitMate_expand_space")
let b:delimitMate_expand_space = 0
elseif !exists("b:delimitMate_expand_space") && exists("g:delimitMate_expand_space")
let b:delimitMate_expand_space = g:delimitMate_expand_space
else
" Nothing to do.
endif " }}}
" expand_space
if exists("b:delimitMate_expand_space") && type(b:delimitMate_expand_space) == type("")
echom "b:delimitMate_expand_space is '".b:delimitMate_expand_space."' but it must be either 1 or 0!"
echom "Read :help 'delimitMate_expand_space' for more details."
unlet b:delimitMate_expand_space
let b:delimitMate_expand_space = 1
endif
if exists("g:delimitMate_expand_space") && type(g:delimitMate_expand_space) == type("")
echom "delimitMate_expand_space is '".g:delimitMate_expand_space."' but it must be either 1 or 0!"
echom "Read :help 'delimitMate_expand_space' for more details."
unlet g:delimitMate_expand_space
let g:delimitMate_expand_space = 1
endif
call delimitMate#option_init("expand_space", 0)
" delimitMate_expand_cr {{{
if !exists("b:delimitMate_expand_cr") && !exists("g:delimitMate_expand_cr")
" expand_cr
if exists("b:delimitMate_expand_cr") && type(b:delimitMate_expand_cr) == type("")
echom "b:delimitMate_expand_cr is '".b:delimitMate_expand_cr."' but it must be either 1 or 0!"
echom "Read :help 'delimitMate_expand_cr' for more details."
unlet b:delimitMate_expand_cr
let b:delimitMate_expand_cr = 1
endif
if exists("g:delimitMate_expand_cr") && type(g:delimitMate_expand_cr) == type("")
echom "delimitMate_expand_cr is '".g:delimitMate_expand_cr."' but it must be either 1 or 0!"
echom "Read :help 'delimitMate_expand_cr' for more details."
unlet g:delimitMate_expand_cr
let g:delimitMate_expand_cr = 1
endif
if (&backspace !~ 'eol' || &backspace !~ 'start') &&
\ ((exists('b:delimitMate_expand_cr') && b:delimitMate_expand_cr == 1) ||
\ (exists('g:delimitMate_expand_cr') && g:delimitMate_expand_cr == 1))
echom "delimitMate: In order to use the <CR> expansion, you need to have 'eol' and 'start' in your backspace option. Read :help 'backspace'."
let b:delimitMate_expand_cr = 0
elseif !exists("b:delimitMate_expand_cr") && exists("g:delimitMate_expand_cr")
let b:delimitMate_expand_cr = g:delimitMate_expand_cr
else
" Nothing to do.
endif " }}}
" delimitMate_smart_quotes {{{
if !exists("b:delimitMate_smart_quotes") && !exists("g:delimitMate_smart_quotes")
let b:delimitMate_smart_quotes = 1
elseif !exists("b:delimitMate_smart_quotes") && exists("g:delimitMate_smart_quotes")
let b:delimitMate_smart_quotes = split(g:delimitMate_smart_quotes)
else
" Nothing to do.
endif " }}}
" delimitMate_apostrophes {{{
if !exists("b:delimitMate_apostrophes") && !exists("g:delimitMate_apostrophes")
"let s:apostrophes = split("n't:'s:'re:'m:'d:'ll:'ve:s'",':')
let s:apostrophes = []
elseif !exists("b:delimitMate_apostrophes") && exists("g:delimitMate_apostrophes")
let s:apostrophes = split(g:delimitMate_apostrophes)
else
let s:apostrophes = split(b:delimitMate_apostrophes)
endif
let b:delimitMate_apostrophes_list = s:apostrophes " }}}
call delimitMate#option_init("expand_cr", 0)
" delimitMate_tab2exit {{{
if !exists("b:delimitMate_tab2exit") && !exists("g:delimitMate_tab2exit")
let b:delimitMate_tab2exit = 1
elseif !exists("b:delimitMate_tab2exit") && exists("g:delimitMate_tab2exit")
let b:delimitMate_tab2exit = g:delimitMate_tab2exit
else
" Nothing to do.
endif " }}}
" smart_quotes
call delimitMate#option_init("smart_quotes", 1)
let b:delimitMate_matchpairs_list = split(s:matchpairs_temp, ',')
let b:delimitMate_left_delims = split(s:matchpairs_temp, ':.,\=')
let b:delimitMate_right_delims = split(s:matchpairs_temp, ',\=.:')
" apostrophes
call delimitMate#option_init("apostrophes", "")
call delimitMate#option_init("apostrophes_list", split(b:_l_delimitMate_apostrophes, ":\s*"))
let b:delimitMate_buffer = []
" tab2exit
call delimitMate#option_init("tab2exit", 1)
call delimitMate#UnMap()
if b:delimitMate_autoclose
call delimitMate#AutoClose()
else
call delimitMate#NoAutoClose()
endif
call delimitMate#VisualMaps()
call delimitMate#ExtraMappings()
" balance_matchpairs
call delimitMate#option_init("balance_matchpairs", 0)
let b:_l_delimitMate_buffer = []
let b:loaded_delimitMate = 1
let b:delimitMate_enabled = 1
endfunction "}}} Init()
function! delimitMate#Map() "{{{
" Set mappings:
try
let save_cpo = &cpo
let save_keymap = &keymap
let save_iminsert = &iminsert
let save_imsearch = &imsearch
set keymap=
set cpo&vim
if b:_l_delimitMate_autoclose
call delimitMate#AutoClose()
else
call delimitMate#NoAutoClose()
endif
call delimitMate#VisualMaps()
call delimitMate#ExtraMappings()
finally
let &cpo = save_cpo
let &keymap = save_keymap
let &iminsert = save_iminsert
let &imsearch = save_imsearch
endtry
let b:delimitMate_enabled = 1
endfunction "}}} Map()
function! delimitMate#ShouldJump() "{{{
" Returns 1 if the next character is a closing delimiter.
let col = col('.')
let lcol = col('$')
let char = getline('.')[col - 1]
for cdel in b:delimitMate_right_delims + b:delimitMate_quotes_list
" Closing delimiter on the right.
for cdel in b:_l_delimitMate_right_delims + b:_l_delimitMate_quotes_list
if char == cdel
" Closing delimiter on the right.
return 1
endif
endfor
" Closing delimiter with space expansion.
let nchar = getline('.')[col]
if b:delimitMate_expand_space && char == " "
for cdel in b:delimitMate_right_delims + b:delimitMate_quotes_list
if b:_l_delimitMate_expand_space && char == " "
for cdel in b:_l_delimitMate_right_delims + b:_l_delimitMate_quotes_list
if nchar == cdel
" Closing delimiter with space expansion.
return 1
endif
endfor
endif
" Closing delimiter with CR expansion.
let uchar = getline(line('.') + 1)[0]
if b:delimitMate_expand_cr && char == ""
for cdel in b:delimitMate_right_delims + b:delimitMate_quotes_list
if b:_l_delimitMate_expand_cr && char == ""
for cdel in b:_l_delimitMate_right_delims + b:_l_delimitMate_quotes_list
if uchar == cdel
" Closing delimiter with CR expansion.
return 1
endif
endfor
@@ -161,71 +175,54 @@ function! delimitMate#ShouldJump() "{{{
return 0
endfunction "}}}
function! delimitMate#IsBlockVisual() " {{{
if mode() == "\<C-V>"
return 1
endif
" Store unnamed register values for later use in delimitMate#RestoreRegister().
let b:save_reg = getreg('"')
let b:save_reg_mode = getregtype('"')
function! delimitMate#Visual(del) " {{{
if len(getline('.')) == 0
" This for proper wrap of empty lines.
let @" = "\n"
endif
return 0
endfunction " }}}
function! delimitMate#Visual(del) " {{{
" Let's find which kind of delimiter we got:
let index = index(b:_l_delimitMate_left_delims, a:del)
if index >= 0
let ld = a:del
let rd = b:_l_delimitMate_right_delims[index]
endif
let index = index(b:_l_delimitMate_right_delims, a:del)
if index >= 0
let ld = b:_l_delimitMate_left_delims[index]
let rd = a:del
endif
if index(b:_l_delimitMate_quotes_list, a:del) >= 0
let ld = a:del
let rd = ld
endif
let mode = mode()
if mode == "\<C-V>"
redraw
echom "delimitMate: delimitMate is disabled on blockwise visual mode."
return ""
endif
" Store unnamed register values for later use in delimitMate#RestoreRegister().
let b:save_reg = getreg('"')
let b:save_reg_mode = getregtype('"')
if len(getline('.')) == 0
" This for proper wrap of empty lines.
let @" = "\n"
endif
if mode ==# "V"
" Block-wise visual
return "I" . ld . "\<Esc>gv\<Right>A" . rd . "\<Esc>"
elseif mode ==# "V"
let dchar = "\<BS>"
else
let dchar = ""
endif
let index = index(b:delimitMate_left_delims, a:del)
if index >= 0
let ld = a:del
let rd = b:delimitMate_right_delims[index]
endif
let index = index(b:delimitMate_right_delims, a:del)
if index >= 0
let ld = b:delimitMate_left_delims[index]
let rd = a:del
endif
let index = index(b:delimitMate_quotes_list, a:del)
if index >= 0
let ld = a:del
let rd = ld
endif
" Store unnamed register values for later use in delimitMate#RestoreRegister().
let b:save_reg = getreg('"')
let b:save_reg_mode = getregtype('"')
return "s" . ld . "\<C-R>\"" . dchar . rd . "\<Esc>:call delimitMate#RestoreRegister()\<CR>"
endfunction " }}}
function! delimitMate#IsEmptyPair(str) "{{{
for pair in b:delimitMate_matchpairs_list
for pair in b:_l_delimitMate_matchpairs_list
if a:str == join( split( pair, ':' ),'' )
return 1
endif
endfor
for quote in b:delimitMate_quotes_list
for quote in b:_l_delimitMate_quotes_list
if a:str == quote . quote
return 1
endif
@@ -237,12 +234,12 @@ function! delimitMate#IsCRExpansion() " {{{
let nchar = 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) &&
if index(b:_l_delimitMate_left_delims, nchar) > -1 &&
\ index(b:_l_delimitMate_left_delims, nchar) == index(b:_l_delimitMate_right_delims, schar) &&
\ isEmpty
return 1
elseif index(b:delimitMate_quotes_list, nchar) > -1 &&
\ index(b:delimitMate_quotes_list, nchar) == index(b:delimitMate_quotes_list, schar) &&
elseif index(b:_l_delimitMate_quotes_list, nchar) > -1 &&
\ index(b:_l_delimitMate_quotes_list, nchar) == index(b:_l_delimitMate_quotes_list, schar) &&
\ isEmpty
return 1
else
@@ -258,12 +255,12 @@ function! delimitMate#IsSpaceExpansion() " {{{
let nchar = line[col + 2]
let isSpaces = (line[col] == line[col+1] && line[col] == " ")
if index(b:delimitMate_left_delims, pchar) > -1 &&
\ index(b:delimitMate_left_delims, pchar) == index(b:delimitMate_right_delims, nchar) &&
if index(b:_l_delimitMate_left_delims, pchar) > -1 &&
\ index(b:_l_delimitMate_left_delims, pchar) == index(b:_l_delimitMate_right_delims, nchar) &&
\ isSpaces
return 1
elseif index(b:delimitMate_quotes_list, pchar) > -1 &&
\ index(b:delimitMate_quotes_list, pchar) == index(b:delimitMate_quotes_list, nchar) &&
elseif index(b:_l_delimitMate_quotes_list, pchar) > -1 &&
\ index(b:_l_delimitMate_quotes_list, pchar) == index(b:_l_delimitMate_quotes_list, nchar) &&
\ isSpaces
return 1
endif
@@ -301,7 +298,7 @@ function! delimitMate#WriteAfter(str) "{{{
endfunction " }}}
function! delimitMate#RestoreRegister() " {{{
" Restore unnamed register values store in delimitMate#IsBlockVisual().
" Restore unnamed register values stored in delimitMate#Visual().
call setreg('"', b:save_reg, b:save_reg_mode)
echo ""
endfunction " }}}
@@ -329,45 +326,156 @@ function! delimitMate#GetCurrentSyntaxRegionIf(char) "{{{
endfunction "}}}
function! delimitMate#IsForbidden(char) "{{{
if b:delimitMate_excluded_regions_enabled == 0
if b:_l_delimitMate_excluded_regions_enabled == 0
return 0
endif
"let result = index(b:delimitMate_excluded_regions_list, delimitMate#GetCurrentSyntaxRegion()) >= 0
if index(b:delimitMate_excluded_regions_list, delimitMate#GetCurrentSyntaxRegion()) >= 0
"let result = index(b:_l_delimitMate_excluded_regions_list, delimitMate#GetCurrentSyntaxRegion()) >= 0
if index(b:_l_delimitMate_excluded_regions_list, delimitMate#GetCurrentSyntaxRegion()) >= 0
"echom "Forbidden 1!"
return 1
endif
let region = delimitMate#GetCurrentSyntaxRegionIf(a:char)
"let result = index(b:delimitMate_excluded_regions_list, region) >= 0
"let result = index(b:_l_delimitMate_excluded_regions_list, region) >= 0
"return result || region == 'Comment'
"echom "Forbidden 2!"
return index(b:delimitMate_excluded_regions_list, region) >= 0
return index(b:_l_delimitMate_excluded_regions_list, region) >= 0
endfunction "}}}
function! delimitMate#FlushBuffer() " {{{
let b:delimitMate_buffer = []
let b:_l_delimitMate_buffer = []
return ''
endfunction " }}}
function! delimitMate#BalancedParens(char) "{{{
" Returns:
" = 0 => Parens balanced.
" > 0 => More opening parens.
" < 0 => More closing parens.
let line = getline('.')
let col = col('.') - 2
let col = col >= 0 ? col : 0
let list = split(line, '\zs')
let left = b:_l_delimitMate_left_delims[index(b:_l_delimitMate_right_delims, a:char)]
let right = a:char
let opening = 0
let closing = 0
" If the cursor is not at the beginning, count what's behind it.
if col > 0
" Find the first opening paren:
let start = index(list, left)
" Must be before cursor:
let start = start < col ? start : col - 1
" Now count from the first opening until the cursor, this will prevent
" extra closing parens from being counted.
let opening = count(list[start : col - 1], left)
let closing = count(list[start : col - 1], right)
" I don't care if there are more closing parens than opening parens.
let closing = closing > opening ? opening : closing
endif
" Evaluate parens from the cursor to the end:
let opening += count(list[col :], left)
let closing += count(list[col :], right)
"echom ""
"echom line
"echom col
""echom left.":".a:char
"echom string(list)
"echom string(list[start : col - 1]) . " : " . string(list[col :])
"echom opening . " - " . closing . " = " . (opening - closing)
" Return the found balance:
return opening - closing
endfunction "}}}
" }}}
" Doers {{{
function! delimitMate#JumpIn(char) " {{{
function! delimitMate#SkipDelim(char) "{{{
if delimitMate#IsForbidden(a:char)
return a:char
endif
let col = col('.') - 1
let line = getline('.')
if col > 0
let cur = line[col]
let pre = line[col-1]
else
let cur = line[col]
let pre = ""
endif
if pre == "\\"
" Escaped character
return a:char
elseif cur == a:char
" Exit pair
"return delimitMate#WriteBefore(a:char)
return a:char . delimitMate#Del()
elseif delimitMate#IsEmptyPair( pre . a:char )
" Add closing delimiter and jump back to the middle.
call insert(b:_l_delimitMate_buffer, a:char)
return delimitMate#WriteAfter(a:char)
else
" Nothing special here, return the same character.
return a:char
endif
endfunction "}}}
function! delimitMate#ParenDelim(char) " {{{
if delimitMate#IsForbidden(a:char)
return ''
endif
if b:_l_delimitMate_balance_matchpairs &&
\ delimitMate#BalancedParens(a:char) <= 0
return ''
endif
let line = getline('.')
let col = col('.')-2
if (col) < 0
call setline('.',a:char.line)
call insert(b:delimitMate_buffer, a:char)
call insert(b:_l_delimitMate_buffer, a:char)
else
"echom string(col).':'.line[:(col)].'|'.line[(col+1):]
call setline('.',line[:(col)].a:char.line[(col+1):])
call insert(b:delimitMate_buffer, a:char)
call insert(b:_l_delimitMate_buffer, a:char)
endif
return ''
endfunction " }}}
function! delimitMate#QuoteDelim(char) "{{{
if delimitMate#IsForbidden(a:char)
return a:char
endif
let line = getline('.')
let col = col('.') - 2
if line[col] == "\\"
" Seems like a escaped character, insert one quotation mark.
return a:char
elseif line[col + 1] == a:char &&
\ index(b:_l_delimitMate_nesting_quotes, a:char) < 0
" Get out of the string.
return a:char . delimitMate#Del()
elseif (line[col] =~ '[[:alnum:]]' && a:char == "'") ||
\ (b:_l_delimitMate_smart_quotes &&
\ (line[col] =~ '[[:alnum:]]' ||
\ line[col + 1] =~ '[[:alnum:]]'))
" Seems like an apostrophe or a smart quote case, insert a single quote.
return a:char
elseif (line[col] == a:char && line[col + 1 ] != a:char) && b:_l_delimitMate_smart_quotes
" Seems like we have an unbalanced quote, insert one quotation mark and jump to the middle.
call insert(b:_l_delimitMate_buffer, a:char)
return delimitMate#WriteAfter(a:char)
else
" Insert a pair and jump to the middle.
call insert(b:_l_delimitMate_buffer, a:char)
call delimitMate#WriteAfter(a:char)
return a:char
endif
endfunction "}}}
function! delimitMate#JumpOut(char) "{{{
if delimitMate#IsForbidden(a:char)
return a:char
@@ -398,7 +506,7 @@ function! delimitMate#JumpAny(key) " {{{
elseif char == ""
" CR expansion.
"let char = "\<CR>" . getline(line('.') + 1)[0] . "\<Del>"
let b:delimitMate_buffer = []
let b:_l_delimitMate_buffer = []
return "\<CR>" . getline(line('.') + 1)[0] . "\<Del>"
else
"call delimitMate#RmBuffer(1)
@@ -406,65 +514,6 @@ function! delimitMate#JumpAny(key) " {{{
endif
endfunction " delimitMate#JumpAny() }}}
function! delimitMate#SkipDelim(char) "{{{
if delimitMate#IsForbidden(a:char)
return a:char
endif
let col = col('.') - 1
let line = getline('.')
if col > 0
let cur = line[col]
let pre = line[col-1]
else
let cur = line[col]
let pre = ""
endif
if pre == "\\"
" Escaped character
return a:char
elseif cur == a:char
" Exit pair
"return delimitMate#WriteBefore(a:char)
return a:char . delimitMate#Del()
elseif delimitMate#IsEmptyPair( pre . a:char )
" Add closing delimiter and jump back to the middle.
call insert(b:delimitMate_buffer, a:char)
return delimitMate#WriteAfter(a:char)
else
" Nothing special here, return the same character.
return a:char
endif
endfunction "}}}
function! delimitMate#QuoteDelim(char) "{{{
if delimitMate#IsForbidden(a:char)
return a:char
endif
let line = getline('.')
let col = col('.') - 2
if line[col] == "\\"
" Seems like a escaped character, insert one quotation mark.
return a:char
elseif line[col + 1] == a:char
" Get out of the string.
"return delimitMate#WriteBefore(a:char)
return a:char . delimitMate#Del()
elseif (line[col] =~ '[a-zA-Z0-9]' && a:char == "'") ||
\(line[col] =~ '[a-zA-Z0-9]' && b:delimitMate_smart_quotes)
" Seems like an apostrophe or a closing, insert a single quote.
return a:char
elseif (line[col] == a:char && line[col + 1 ] != a:char) && b:delimitMate_smart_quotes
" Seems like we have an unbalanced quote, insert one quotation mark and jump to the middle.
call insert(b:delimitMate_buffer, a:char)
return delimitMate#WriteAfter(a:char)
else
" Insert a pair and jump to the middle.
call insert(b:delimitMate_buffer, a:char)
call delimitMate#WriteAfter(a:char)
return a:char
endif
endfunction "}}}
function! delimitMate#MapMsg(msg) "{{{
redraw
echomsg a:msg
@@ -491,9 +540,7 @@ function! delimitMate#ExpandSpace() "{{{
endif
if delimitMate#WithinEmptyPair()
" Expand:
call insert(b:delimitMate_buffer, 's')
" Expand:
call insert(b:delimitMate_buffer, 's')
call insert(b:_l_delimitMate_buffer, 's')
return delimitMate#WriteAfter(' ') . "\<Space>"
else
return "\<Space>"
@@ -519,7 +566,7 @@ function! delimitMate#BS() " {{{
endfunction " }}} delimitMate#BS()
function! delimitMate#Del() " {{{
if len(b:delimitMate_buffer) > 0
if len(b:_l_delimitMate_buffer) > 0
let line = getline('.')
let col = col('.') - 2
call delimitMate#RmBuffer(1)
@@ -531,11 +578,11 @@ function! delimitMate#Del() " {{{
endfunction " }}}
function! delimitMate#Finish() " {{{
let len = len(b:delimitMate_buffer)
let len = len(b:_l_delimitMate_buffer)
if len > 0
let buffer = join(b:delimitMate_buffer, '')
let buffer = join(b:_l_delimitMate_buffer, '')
" Reset buffer:
let b:delimitMate_buffer = []
let b:_l_delimitMate_buffer = []
let line = getline('.')
let col = col('.') -2
"echom 'col: ' . col . '-' . line[:col] . "|" . line[col+len+1:] . '%' . buffer
@@ -556,8 +603,8 @@ function! delimitMate#Finish() " {{{
endfunction " }}}
function! delimitMate#RmBuffer(num) " {{{
if len(b:delimitMate_buffer) > 0
call remove(b:delimitMate_buffer, 0, (a:num-1))
if len(b:_l_delimitMate_buffer) > 0
call remove(b:_l_delimitMate_buffer, 0, (a:num-1))
endif
return ""
endfunction " }}}
@@ -567,107 +614,109 @@ endfunction " }}}
" Mappers: {{{
function! delimitMate#NoAutoClose() "{{{
" inoremap <buffer> ) <C-R>=delimitMate#SkipDelim('\)')<CR>
for delim in b:delimitMate_right_delims + b:delimitMate_quotes_list
exec 'inoremap <buffer> ' . delim . ' <C-R>=delimitMate#SkipDelim("' . escape(delim,'"\|') . '")<CR>'
for delim in b:_l_delimitMate_right_delims + b:_l_delimitMate_quotes_list
exec 'inoremap <silent> <buffer> ' . delim . ' <C-R>=delimitMate#SkipDelim("' . escape(delim,'"\|') . '")<CR>'
endfor
endfunction "}}}
function! delimitMate#AutoClose() "{{{
" Add matching pair and jump to the midle:
" inoremap <buffer> ( ()<Left>
" inoremap <silent> <buffer> ( ()<Left>
let i = 0
while i < len(b:delimitMate_matchpairs_list)
let ld = b:delimitMate_left_delims[i]
let rd = b:delimitMate_right_delims[i]
exec 'inoremap <buffer> ' . ld . ' ' . ld . '<C-R>=delimitMate#JumpIn("' . rd . '")<CR>'
while i < len(b:_l_delimitMate_matchpairs_list)
let ld = b:_l_delimitMate_left_delims[i]
let rd = b:_l_delimitMate_right_delims[i]
exec 'inoremap <silent> <buffer> ' . ld . ' ' . ld . '<C-R>=delimitMate#ParenDelim("' . rd . '")<CR>'
let i += 1
endwhile
" Exit from inside the matching pair:
for delim in b:delimitMate_right_delims
exec 'inoremap <buffer> ' . delim . ' <C-R>=delimitMate#JumpOut("\' . delim . '")<CR>'
for delim in b:_l_delimitMate_right_delims
exec 'inoremap <silent> <buffer> ' . delim . ' <C-R>=delimitMate#JumpOut("\' . delim . '")<CR>'
endfor
" Add matching quote and jump to the midle, or exit if inside a pair of matching quotes:
" inoremap <buffer> " <C-R>=delimitMate#QuoteDelim("\"")<CR>
for delim in b:delimitMate_quotes_list
exec 'inoremap <buffer> ' . delim . ' <C-R>=delimitMate#QuoteDelim("\' . delim . '")<CR>'
" inoremap <silent> <buffer> " <C-R>=delimitMate#QuoteDelim("\"")<CR>
for delim in b:_l_delimitMate_quotes_list
exec 'inoremap <silent> <buffer> ' . delim . ' <C-R>=delimitMate#QuoteDelim("\' . delim . '")<CR>'
endfor
" Try to fix the use of apostrophes (de-activated by default):
" inoremap <buffer> n't n't
for map in b:delimitMate_apostrophes_list
exec "inoremap <buffer> " . map . " " . map
" inoremap <silent> <buffer> n't n't
for map in b:_l_delimitMate_apostrophes_list
exec "inoremap <silent> <buffer> " . map . " " . map
endfor
endfunction "}}}
function! delimitMate#VisualMaps() " {{{
let VMapMsg = "delimitMate: delimitMate is disabled on blockwise visual mode."
let vleader = b:delimitMate_visual_leader
let vleader = b:_l_delimitMate_visual_leader
" Wrap the selection with matching pairs, but do nothing if blockwise visual mode is active:
for del in b:delimitMate_right_delims + b:delimitMate_left_delims + b:delimitMate_quotes_list
exec "vnoremap <buffer> <expr> " . vleader . del . ' delimitMate#Visual("' . escape(del, '")') . '")'
for del in b:_l_delimitMate_right_delims + b:_l_delimitMate_left_delims + b:_l_delimitMate_quotes_list
exec "vnoremap <silent> <buffer> <expr> " . vleader . del . ' delimitMate#Visual("' . escape(del, '")') . '")'
endfor
endfunction "}}}
function! delimitMate#ExtraMappings() "{{{
" If pair is empty, delete both delimiters:
inoremap <buffer> <BS> <C-R>=delimitMate#BS()<CR>
inoremap <silent> <buffer> <BS> <C-R>=delimitMate#BS()<CR>
" If pair is empty, delete closing delimiter:
inoremap <buffer> <expr> <S-BS> delimitMate#WithinEmptyPair() && !delimitMate#IsForbidden("") ? "\<Del>" : "\<S-BS>"
inoremap <silent> <buffer> <expr> <S-BS> delimitMate#WithinEmptyPair() ? "\<C-R>=delimitMate#Del()\<CR>" : "\<S-BS>"
" Expand return if inside an empty pair:
if b:delimitMate_expand_cr != 0
inoremap <buffer> <CR> <C-R>=delimitMate#ExpandReturn()<CR>
if b:_l_delimitMate_expand_cr != 0
inoremap <silent> <buffer> <CR> <C-R>=delimitMate#ExpandReturn()<CR>
endif
" Expand space if inside an empty pair:
if b:delimitMate_expand_space != 0
inoremap <buffer> <Space> <C-R>=delimitMate#ExpandSpace()<CR>
if b:_l_delimitMate_expand_space != 0
inoremap <silent> <buffer> <Space> <C-R>=delimitMate#ExpandSpace()<CR>
endif
" Jump out ot any empty pair:
if b:delimitMate_tab2exit
inoremap <buffer> <S-Tab> <C-R>=delimitMate#JumpAny("\<S-Tab>")<CR>
if b:_l_delimitMate_tab2exit
inoremap <silent> <buffer> <S-Tab> <C-R>=delimitMate#JumpAny("\<S-Tab>")<CR>
endif
" Fix the re-do feature:
inoremap <buffer> <Esc> <C-R>=delimitMate#Finish()<CR><Esc>
inoremap <silent> <buffer> <Esc> <C-R>=delimitMate#Finish()<CR><Esc>
" Flush the char buffer on mouse click:
inoremap <buffer> <LeftMouse> <C-R>=delimitMate#Finish()<CR><LeftMouse>
inoremap <buffer> <RightMouse> <C-R>=delimitMate#Finish()<CR><RightMouse>
inoremap <silent> <buffer> <LeftMouse> <C-R>=delimitMate#Finish()<CR><LeftMouse>
inoremap <silent> <buffer> <RightMouse> <C-R>=delimitMate#Finish()<CR><RightMouse>
" Flush the char buffer on key movements:
inoremap <buffer> <Left> <C-R>=delimitMate#Finish()<CR><Left>
inoremap <buffer> <Right> <C-R>=delimitMate#Finish()<CR><Right>
inoremap <buffer> <Up> <C-R>=delimitMate#Finish()<CR><Up>
inoremap <buffer> <Down> <C-R>=delimitMate#Finish()<CR><Down>
inoremap <silent> <buffer> <Left> <C-R>=delimitMate#Finish()<CR><Left>
inoremap <silent> <buffer> <Right> <C-R>=delimitMate#Finish()<CR><Right>
inoremap <silent> <buffer> <Up> <C-R>=delimitMate#Finish()<CR><Up>
inoremap <silent> <buffer> <Down> <C-R>=delimitMate#Finish()<CR><Down>
inoremap <silent> <buffer> <Home> <C-R>=delimitMate#Finish()<CR><Home>
inoremap <silent> <buffer> <End> <C-R>=delimitMate#Finish()<CR><End>
inoremap <buffer> <Del> <C-R>=delimitMate#Del()<CR>
inoremap <silent> <buffer> <Del> <C-R>=delimitMate#Del()<CR>
"the following simply creates an ambiguous mapping so vim fully
"processes the escape sequence for terminal keys, see 'ttimeout' for a
"rough explanation, this just forces it to work
if &term[:4] == "xterm"
inoremap <silent> <C-[>OC <RIGHT>
" The following simply creates an ambiguous mapping so vim fully processes
" the escape sequence for terminal keys, see 'ttimeout' for a rough
" explanation, this just forces it to work
if !has('gui_running')
imap <silent> <C-[>OC <RIGHT>
endif
endfunction "}}}
function! delimitMate#UnMap() " {{{
let imaps =
\ b:delimitMate_right_delims +
\ b:delimitMate_left_delims +
\ b:delimitMate_quotes_list +
\ b:delimitMate_apostrophes_list +
\ b:_l_delimitMate_right_delims +
\ b:_l_delimitMate_left_delims +
\ b:_l_delimitMate_quotes_list +
\ b:_l_delimitMate_apostrophes_list +
\ ['<BS>', '<S-BS>', '<Del>', '<CR>', '<Space>', '<S-Tab>', '<Esc>'] +
\ ['<Up>', '<Down>', '<Left>', '<Right>', '<LeftMouse>', '<RightMouse>']
let vmaps =
\ b:delimitMate_right_delims +
\ b:delimitMate_left_delims +
\ b:delimitMate_quotes_list
\ b:_l_delimitMate_right_delims +
\ b:_l_delimitMate_left_delims +
\ b:_l_delimitMate_quotes_list
for map in imaps
if maparg(map, "i") =~? 'delimitMate'
@@ -675,10 +724,10 @@ function! delimitMate#UnMap() " {{{
endif
endfor
if !exists("b:delimitMate_visual_leader")
if !exists("b:_l_delimitMate_visual_leader")
let vleader = ""
else
let vleader = b:delimitMate_visual_leader
let vleader = b:_l_delimitMate_visual_leader
endif
for map in vmaps
if maparg(vleader . map, "v") =~? "delimitMate"
@@ -686,6 +735,10 @@ function! delimitMate#UnMap() " {{{
endif
endfor
if !has('gui_running')
silent! iunmap <C-[>OC
endif
let b:delimitMate_enabled = 0
endfunction " }}} delimitMate#UnMap()
@@ -693,55 +746,58 @@ endfunction " }}} delimitMate#UnMap()
" Tools: {{{
function! delimitMate#TestMappings() "{{{
exec "normal i*b:delimitMate_autoclose = " . b:delimitMate_autoclose . "\<CR>"
exec "normal i*b:delimitMate_expand_space = " . b:delimitMate_expand_space . "\<CR>"
exec "normal i*b:delimitMate_expand_cr = " . b:delimitMate_expand_cr . "\<CR>\<CR>"
if b:delimitMate_autoclose
for i in range(len(b:delimitMate_left_delims))
exec "normal GGAOpen & close: " . b:delimitMate_left_delims[i]. "|"
exec "normal A\<CR>Delete: " . b:delimitMate_left_delims[i] . "\<BS>|"
exec "normal A\<CR>Exit: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . "|"
exec "normal A\<CR>Space: " . b:delimitMate_left_delims[i] . " |"
exec "normal A\<CR>Delete space: " . b:delimitMate_left_delims[i] . " \<BS>|"
exec "normal GGA\<CR>Visual-L: v\<Esc>v" . b:delimitMate_visual_leader . b:delimitMate_left_delims[i]
exec "normal A\<CR>Visual-R: v\<Esc>v" . b:delimitMate_visual_leader . b:delimitMate_right_delims[i]
exec "normal A\<CR>Car return: " . b:delimitMate_left_delims[i] . "\<CR>|"
exec "normal GGA\<CR>Delete car return: " . b:delimitMate_left_delims[i] . "\<CR>\<BS>|\<Esc>GGA\<CR>\<CR>"
exec "normal i*b:_l_delimitMate_autoclose = " . b:_l_delimitMate_autoclose . "\<Esc>o"
exec "normal i*b:_l_delimitMate_expand_space = " . b:_l_delimitMate_expand_space . "\<Esc>o"
exec "normal i*b:_l_delimitMate_expand_cr = " . b:_l_delimitMate_expand_cr . "\<Esc>o\<Esc>o"
echom b:_l_delimitMate_autoclose.b:_l_delimitMate_expand_space.b:_l_delimitMate_expand_cr
if b:_l_delimitMate_autoclose
" {{{
for i in range(len(b:_l_delimitMate_left_delims))
exec "normal GGoOpen & close: " . b:_l_delimitMate_left_delims[i]. "|"
exec "normal oDelete: " . b:_l_delimitMate_left_delims[i] . "\<BS>|"
exec "normal oExit: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . "|"
exec "normal oSpace: " . b:_l_delimitMate_left_delims[i] . " |"
exec "normal oDelete space: " . b:_l_delimitMate_left_delims[i] . " \<BS>|"
exec "normal GGoVisual-L: v\<Esc>v" . b:_l_delimitMate_visual_leader . b:_l_delimitMate_left_delims[i]
exec "normal oVisual-R: v\<Esc>v" . b:_l_delimitMate_visual_leader . b:_l_delimitMate_right_delims[i]
exec "normal oCar return: " . b:_l_delimitMate_left_delims[i] . "\<CR>|"
exec "normal GGoDelete car return: " . b:_l_delimitMate_left_delims[i] . "\<CR>\<BS>|\<Esc>GGA\<Esc>o\<Esc>o"
endfor
for i in range(len(b:delimitMate_quotes_list))
exec "normal GGAOpen & close: " . b:delimitMate_quotes_list[i] . "|"
exec "normal A\<CR>Delete: "
exec "normal A\<CR>Exit: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . "|"
exec "normal A\<CR>Space: " . b:delimitMate_quotes_list[i] . " |"
exec "normal A\<CR>Delete space: " . b:delimitMate_quotes_list[i] . " \<BS>|"
exec "normal GGA\<CR>Visual: v\<Esc>v" . b:delimitMate_visual_leader . b:delimitMate_quotes_list[i]
exec "normal A\<CR>Car return: " . b:delimitMate_quotes_list[i] . "\<CR>|"
exec "normal GGA\<CR>Delete car return: " . b:delimitMate_quotes_list[i] . "\<CR>\<BS>|\<Esc>GGA\<CR>\<CR>"
for i in range(len(b:_l_delimitMate_quotes_list))
exec "normal GGAOpen & close: " . b:_l_delimitMate_quotes_list[i] . "|"
exec "normal oDelete: "
exec "normal oExit: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . "|"
exec "normal oSpace: " . b:_l_delimitMate_quotes_list[i] . " |"
exec "normal oDelete space: " . b:_l_delimitMate_quotes_list[i] . " \<BS>|"
exec "normal GGoVisual: v\<Esc>v" . b:_l_delimitMate_visual_leader . b:_l_delimitMate_quotes_list[i]
exec "normal oCar return: " . b:_l_delimitMate_quotes_list[i] . "\<CR>|"
exec "normal GGoDelete car return: " . b:_l_delimitMate_quotes_list[i] . "\<CR>\<BS>|\<Esc>GGA\<Esc>o\<Esc>o"
endfor
"}}}
else
for i in range(len(b:delimitMate_left_delims))
exec "normal GGAOpen & close: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . "|"
exec "normal A\<CR>Delete: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . "\<BS>|"
exec "normal A\<CR>Exit: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . b:delimitMate_right_delims[i] . "|"
exec "normal A\<CR>Space: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . " |"
exec "normal A\<CR>Delete space: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . " \<BS>|"
exec "normal GGA\<CR>Visual-L: v\<Esc>v" . b:delimitMate_visual_leader . b:delimitMate_left_delims[i]
exec "normal A\<CR>Visual-R: v\<Esc>v" . b:delimitMate_visual_leader . b:delimitMate_right_delims[i]
exec "normal A\<CR>Car return: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . "\<CR>|"
exec "normal GGA\<CR>Delete car return: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . "\<CR>\<BS>|\<Esc>GGA\<CR>\<CR>"
"{{{
for i in range(len(b:_l_delimitMate_left_delims))
exec "normal GGoOpen & close: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . "|"
exec "normal oDelete: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . "\<BS>|"
exec "normal oExit: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . b:_l_delimitMate_right_delims[i] . "|"
exec "normal oSpace: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . " |"
exec "normal oDelete space: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . " \<BS>|"
exec "normal GGoVisual-L: v\<Esc>v" . b:_l_delimitMate_visual_leader . b:_l_delimitMate_left_delims[i]
exec "normal oVisual-R: v\<Esc>v" . b:_l_delimitMate_visual_leader . b:_l_delimitMate_right_delims[i]
exec "normal oCar return: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . "\<CR>|"
exec "normal GGoDelete car return: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . "\<CR>\<BS>|\<Esc>GGA\<Esc>o\<Esc>o"
endfor
for i in range(len(b:delimitMate_quotes_list))
exec "normal GGAOpen & close: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . "|"
exec "normal A\<CR>Delete: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . "\<BS>|"
exec "normal A\<CR>Exit: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . "|"
exec "normal A\<CR>Space: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . " |"
exec "normal A\<CR>Delete space: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . " \<BS>|"
exec "normal GGA\<CR>Visual: v\<Esc>v" . b:delimitMate_visual_leader . b:delimitMate_quotes_list[i]
exec "normal A\<CR>Car return: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . "\<CR>|"
exec "normal GGA\<CR>Delete car return: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . "\<CR>\<BS>|\<Esc>GGA\<CR>\<CR>"
for i in range(len(b:_l_delimitMate_quotes_list))
exec "normal GGoOpen & close: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . "|"
exec "normal oDelete: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . "\<BS>|"
exec "normal oExit: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . "|"
exec "normal oSpace: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . " |"
exec "normal oDelete space: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . " \<BS>|"
exec "normal GGoVisual: v\<Esc>v" . b:_l_delimitMate_visual_leader . b:_l_delimitMate_quotes_list[i]
exec "normal oCar return: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . "\<CR>|"
exec "normal GGoDelete car return: " . b:_l_delimitMate_quotes_list[i] . b:_l_delimitMate_quotes_list[i] . "\<CR>\<BS>|\<Esc>GGA\<Esc>o\<Esc>o"
endfor
endif
endif "}}}
exec "normal \<Esc>i"
endfunction "}}}

View File

@@ -1,9 +1,14 @@
function! delimitMateTests#Main() " {{{
function! delimitMateTests#Main()
if !exists("g:delimitMate_testing")
echoerr "delimitMateTests#Main(): If you really want to use me, you must set delimitMate_testing to any value."
return
elseif g:delimitMate_testing == "fork"
!gvim -N -u NONE -U NONE -c "set backspace=eol,start" -c "set background=light" -c "syntax on" -c "let delimitMate_testing = 1" -c "so autoload/delimitMate.vim" -c "so autoload/delimitMateTests.vim" -c "so plugin/delimitMate.vim" -c "call delimitMateTests\#Main()"
return ""
endif
nmap <F1> :qall!<CR>
let nomore = &more
set nomore
let b:test_results = {}
let b:errors = 0
let b:corrects = 0
@@ -45,6 +50,7 @@ function! delimitMateTests#Main() " {{{
normal gg.
endif
exec "normal \<Esc>"
call setpos('.', [0, 1, 1, 0])
let result = len(a:output) != line('$')
for line in a:output
@@ -245,9 +251,10 @@ function! delimitMateTests#Main() " {{{
call append(0, "*TESTS REPORT: " . b:errors . " failed, " . b:corrects . " passed and " . b:ignores . " ignored.")
normal "_ddgg
let @/ = ".\\+Failed:.*!="
2,$sort /^.\+':/
normal gg
exec search('Ignored:','nW').",$sort! /^.\\+':/"
set nohlsearch
"syntax match failedLine "^.*Failed.*$" contains=ALL
"syn match passedLine ".*Passed.*"
syn match lineIgnored ".*Ignored.*"
syn match labelPassed "'\@<=.\+\(': 'Passed\)\@="
syn match labelFailed "'\@<=.\+\(': 'Failed\)\@="
@@ -267,6 +274,8 @@ function! delimitMateTests#Main() " {{{
hi def link resultSummary SpecialComment
hi def link resultSummaryNumber Error
" }}}
endfunction " }}}
let &more = nomore
endfunction
" vim:foldmethod=marker:foldcolumn=4

View File

@@ -1,4 +1,4 @@
*delimitMate* Trying to keep those beasts at bay! v2.3 *delimitMate.txt*
*delimitMate* Trying to keep those beasts at bay! v2.4.1 *delimitMate.txt*
@@ -26,8 +26,9 @@
2.3 Backspace__________________________|delimitMateBackspace|
2.4 Visual wrapping____________________|delimitMateVisualWrapping|
2.5 Smart Quotes_______________________|delimitMateSmartQuotes|
2.6 FileType based configuration_______|delimitMateFileType|
2.7 Syntax awareness___________________|delimitMateSyntax|
2.6 Balancing matching pairs___________|delimitMateBalance|
2.7 FileType based configuration_______|delimitMateFileType|
2.8 Syntax awareness___________________|delimitMateSyntax|
3. Customization___________________________|delimitMateOptions|
3.1 Options summary____________________|delimitMateOptionSummary|
3.2 Options details____________________|delimitMateOptionDetails|
@@ -90,6 +91,9 @@ Without auto-close: >
-|
()<S-Tab> | ()|
<
NOTE: Abbreviations will not be expanded by delimiters used on delimitMate,
you should use <C-]> (read |i_CTRL-]|) to expand them on the go.
------------------------------------------------------------------------------
2.2 EXPANSION OF SPACE AND CAR RETURN *delimitMateExpansion*
@@ -125,8 +129,9 @@ If you press backspace inside an empty pair, both delimiters are deleted. When
expansions are enabled, <BS> will also delete the expansions. NOTE that
deleting <CR> expansions will brake the redo command.
If you type shift + backspace instead, only the closing delimiter will be
deleted.
If you type <S-BS> (shift + backspace) instead, only the closing delimiter
will be deleted. NOTE that this will not usually work when using Vim from the
terminal, see 'delimitMate#JumpAny()' below to see how to fix it.
e.g. typing at the "|": >
@@ -149,8 +154,9 @@ 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.
NOTE that this feature brakes the redo command and doesn't currently work on
blockwise visual mode, any suggestions to fix this will be very welcome.
NOTE that this feature brakes the redo command and doesn't currently work well
on blockwise visual mode when the selection has lines one character smaller
than the rest, any suggestions to fix this will be very welcome.
e.g. (selection represented between square brackets): >
@@ -162,9 +168,10 @@ e.g. (selection represented between square brackets): >
------------------------------------------------------------------------------
2.5 SMART QUOTES *delimitMateSmartQuotes*
Only one quote will be inserted following a quote, a "\" or an alphanumeric
character. This should cover closing quotes, escaped quotes and apostrophes.
Except for apostrophes, this feature can be disabled setting the option
Only one quote will be inserted following a quote, a "\" or, following or
preceding an alphanumeric character. This should cover closing quotes after a
string, opening quotes before a string, escaped quotes and apostrophes. Except
for apostrophes, this feature can be disabled setting the option
|'delimitMate_smart_quotes'| to 0.
e.g. typing at the "|": >
@@ -176,7 +183,22 @@ e.g. typing at the "|": >
' | I| | I'|
<
------------------------------------------------------------------------------
2.6 FILE TYPE BASED CONFIGURATION *delimitMateFileType*
2.6 BALANCING MATCHING PAIRS *delimitMateBalance*
When inserting an opening paren and |'delimitMate_balance_matchpairs'| is
enabled, delimitMate will try to balance the closing pairs in the current
line.
e.g. typing at the "|": >
What | Before | After
=======================================
( | |) | (|)
( | | | (|)
( | (|) | ((|))
<
------------------------------------------------------------------------------
2.7 FILE TYPE BASED CONFIGURATION *delimitMateFileType*
delimitMate options can be set globally for all buffers using global
("regular") variables in your |vimrc| file. But |:autocmd| can be used to set
@@ -196,7 +218,7 @@ NOTE that you should use buffer variables (|b:var|) only to set options with
|:autocmd|, for global options use regular variables (|g:var|) in your vimrc.
------------------------------------------------------------------------------
2.7 SYNTAX AWARENESS *delimitMateSyntax*
2.8 SYNTAX AWARENESS *delimitMateSyntax*
The features of this plug-in might not be always helpful, comments and strings
usualy don't need auto-completion. delimitMate monitors which region is being
@@ -222,35 +244,41 @@ The behaviour of this script can be customized setting the following options
in your vimrc file. You can use local options to set the configuration for
specific file types, see |delimitMateOptionDetails| for examples.
|'loaded_delimitMate'| Turns off the script.
|'loaded_delimitMate'| Turns off the script.
|'delimitMate_autoclose'| Tells delimitMate whether to automagically
|'delimitMate_autoclose'| Tells delimitMate whether to automagically
insert the closing delimiter.
|'delimitMate_matchpairs'| Tells delimitMate which characters are
|'delimitMate_matchpairs'| Tells delimitMate which characters are
matching pairs.
|'delimitMate_quotes'| Tells delimitMate which quotes should be
|'delimitMate_quotes'| Tells delimitMate which quotes should be
used.
|'delimitMate_visual_leader'| Sets the leader to be used in visual mode.
|'delimitMate_nesting_quotes'| Tells delimitMate which quotes should be
allowed to be nested.
|'delimitMate_expand_cr'| Turns on/off the expansion of <CR>.
|'delimitMate_visual_leader'| Sets the leader to be used in visual mode.
|'delimitMate_expand_space'| Turns on/off the expansion of <Space>.
|'delimitMate_expand_cr'| Turns on/off the expansion of <CR>.
|'delimitMate_excluded_ft'| Turns off the script for the given file types.
|'delimitMate_expand_space'| Turns on/off the expansion of <Space>.
|'delimitMate_excluded_regions'|Turns off the script for the given regions or
|'delimitMate_smart_quotes'| Turns on/off the "smart quotes" feature.
|'delimitMate_balance_matchpairs'|Turns on/off the "balance matching pairs"
feature.
|'delimitMate_excluded_regions'| Turns off the script for the given regions or
syntax group names.
|'delimitMate_apostrophes'| Tells delimitMate how it should "fix"
|'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. NOTE: Not needed any more, kept
for compatibility with older versions.
|'delimitMate_smart_quotes'| Turns on/off the "smart quotes" feature.
------------------------------------------------------------------------------
3.2 OPTIONS DETAILS *delimitMateOptionDetails*
@@ -286,7 +314,7 @@ e.g.: >
------------------------------------------------------------------------------
*'delimitMate_matchpairs'*
*'b:delimitMate_matchpairs'*
Values: A string with |matchpairs| syntax. ~
Values: A string with |'matchpairs'| syntax. ~
Default: &matchpairs ~
Use this option to tell delimitMate which characters should be considered
@@ -304,9 +332,21 @@ Default: "\" ' `" ~
Use this option to tell delimitMate which characters should be considered as
quotes. Read |delimitMateAutoClose| for details.
e.g.: >
let b:delimitMate_quotes = "\" ' ` *"
let delimitMate_quotes = "\" ' ` *"
au FileType html let b:delimitMate_quotes = "\" '"
<
------------------------------------------------------------------------------
*'delimitMate_nesting_quotes'*
*'b:delimitMate_nesting_quotes'*
Values: A list of quotes. ~
Default: [] ~
Quotes listed here will not be able to jump out of the empty pair, thus
allowing the autoclosed quotes to be nested.
e.g.: >
let delimitMate_nesting_quotes = ['"','`']
au FileType python let b:delimitMate_nesting_quotes = ['"']
<
------------------------------------------------------------------------------
*'delimitMate_visual_leader'*
*'b:delimitMate_visual_leader'*
@@ -328,30 +368,44 @@ Default: 0 ~
This option turns on/off the expansion of <CR>. Read |delimitMateExpansion|
for details.
e.g.: >
let b:delimitMate_expand_cr = "\<CR>\<CR>\<Up>"
au FileType mail let b:delimitMate_expand_cr = "\<CR>"
let delimitMate_expand_cr = 1
au FileType mail let b:delimitMate_expand_cr = 1
<
------------------------------------------------------------------------------
*'delimitMate_expand_space'*
*'b:delimitMate_expand_space'*
Values: A key mapping. ~
Default: "\<Space>" ~
Values: 1 or 0 ~
Default: 0 ~
This option turns on/off the expansion of <Space>. Read |delimitMateExpansion|
for details.
e.g.: >
let delimitMate_expand_space = "\<Space>\<Space>\<Left>"
au FileType tcl let b:delimitMate_expand_space = "\<Space>"
let delimitMate_expand_space = 1
au FileType tcl let b:delimitMate_expand_space = 1
<
------------------------------------------------------------------------------
*'delimitMate_excluded_ft'*
Values: A string of file type names separated by single commas. ~
Default: Empty. ~
*'delimitMate_smart_quotes'*
*'b:delimitMate_smart_quotes'*
Values: 1 or 0 ~
Default: 1 ~
This options turns delimitMate off for the listed file types, use this option
only if you don't want any of the features it provides on those file types.
This option turns on/off the smart quotes feature. Read
|delimitMateSmartQuotes| for details.
e.g.: >
let delimitMate_excluded_ft = "mail,txt"
let delimitMate_smart_quotes = 0
au FileType tcl let b:delimitMate_smart_quotes = 0
<
------------------------------------------------------------------------------
*'delimitMate_balance_matchpairs'*
*'b:delimitMate_balance_matchpairs'*
Values: 1 or 0 ~
Default: 0 ~
This option turns on/off the balancing of matching pairs. Read
|delimitMateBalance| for details.
e.g.: >
let delimitMate_balance_matchpairs = 1
au FileType tcl let b:delimitMate_balance_matchpairs = 1
<
------------------------------------------------------------------------------
*'delimitMate_excluded_regions'*
@@ -363,6 +417,16 @@ for more info about what is a region.
e.g.: >
let delimitMate_excluded_regions = "Comments,String"
<
------------------------------------------------------------------------------
*'delimitMate_excluded_ft'*
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 you don't want any of the features it provides on those file types.
e.g.: >
let delimitMate_excluded_ft = "mail,txt"
<
------------------------------------------------------------------------------
*'delimitMate_apostrophes'*
Values: Strings separated by ":". ~
@@ -471,9 +535,15 @@ Functions should be used enclosed between <C-R>= and <CR>, otherwise they
might not work as expected or at all.
------------------------------------------------------------------------------
delimitMate#WithinEmptyPair() *delimitMate_WithinEmptyPair*
delimitMate#WithinEmptyPair() *delimitMate_WithinEmptyPair()*
Returns 1 if the cursor is inside an empty pair, 0 otherwise.
e.g.: >
inoremap <expr> <CR> delimitMate#WithinEmptyPair() ?
\ "\<C-R>=delimitMate#ExpandReturn()\<CR>" :
\ "external_mapping"
<
------------------------------------------------------------------------------
delimitMate#ExpandReturn() *delimitMate#ExpandReturn()*
@@ -484,7 +554,8 @@ Returns the expansion for <CR> if enabled and inside an empty pair, returns
e.g.: This mapping could be used to select an item on a pop-up menu or expand
<CR> inside an empty pair: >
inoremap <expr> <CR> pumvisible() ? "\<c-y>" :
inoremap <expr> <CR> pumvisible() ?
\"\<c-y>" :
\ "\<C-R>=delimitMate#ExpandReturn()\<CR>"
<
------------------------------------------------------------------------------
@@ -509,14 +580,14 @@ This function returns a mapping that will make the cursor jump to the right
when delimitMate#ShouldJump() returns 1, returns the argument "key" otherwise.
e.g.: You can use this to create your own mapping to jump over any delimiter.
>
inoremap <C-Tab> <C-R>=delimitMate#JumpAny("\<S-Tab>")<CR>
inoremap <C-Tab> <C-R>=delimitMate#JumpAny("\<C-Tab>")<CR>
<
==============================================================================
6. TODO LIST *delimitMateTodo*
- Automatic set-up by file type.
- Make visual wrapping work on blockwise visual mode.
- Make block-wise visual wrapping work on un-even regions.
==============================================================================
7. MAINTAINER *delimitMateMaintainer*
@@ -541,34 +612,64 @@ from the following sources:
From the comments on the previous blog post and from:
http://gist.github.com/144619
- Vim Scripts:
http://www.vim.org/scripts
- Karl Guertin
AutoClose:
http://www.vim.org/scripts/script.php?script_id=1849
This script was inspired by the auto-completion of delimiters of TextMate.
- Thiago Alves
AutoClose:
http://www.vim.org/scripts/script.php?script_id=2009
- Edoardo Vacchi
ClosePairs:
http://www.vim.org/scripts/script.php?script_id=2373
This script was inspired by the auto-completion of delimiters on TextMate.
==============================================================================
9. HISTORY *delimitMateHistory*
Version Date Release notes ~
|---------|------------|-----------------------------------------------------|
2.3 2010-06-06 * Current release:
- Syntax aware: Will turn off when editing comments
2.4.1 2010-07-31 * Current release:
- Fix problem with <Home> and <End>.
- Add missing doc on |'delimitMate_smart_quotes'|,
|delimitMateBalance| and
|'delimitMate_balance_matchpairs'|.
|---------|------------|-----------------------------------------------------|
2.4 2010-07-29 * - Unbalanced parens: see :help delimitMateBalance.
- Visual wrapping now works on block-wise visual
with some limitations.
- Arrow keys didn't work on terminal.
- Added option to allow nested quotes.
- Expand Smart Quotes to look for a string on the
right of the cursor.
|---------|------------|-----------------------------------------------------|
2.3.1 2010-06-06 * - Fix: an extra <Space> is inserted after <Space>
expansion.
|---------|------------|-----------------------------------------------------|
2.3 2010-06-06 * - Syntax aware: Will turn off when editing comments
or other regions, customizable.
- Changed format of most mappings.
- Fix: <CR> expansion doesn't brake automatic
indentation adjustments anymore.
- Fix: Arrow keys would insert A, B, C or D instead
of moving the cursor when using Vim on a terminal.
|---------|------------|-----------------------------------------------------|
2.2 2010-05-16 * - Added command to switch the plug-in on and off.
- Fix: some problems with <Left>, <Right> and <CR>.
- Fix: A small problem when inserting a delimiter at
the beginning of the line.
|---------|------------|-----------------------------------------------------|
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.
@@ -584,7 +685,6 @@ This script was inspired by the auto-completion of delimiters of TextMate.
active if you have any of the expansion options
set.
- <S-Backspace> deletes the closing delimiter.
* Fixed bug:
- s:vars were being used to store buffer options.
@@ -643,4 +743,4 @@ _____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|____ ~
__|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_ ~
_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|____ ~
vim:tw=78:ts=8:ft=help:norl:formatoptions+=tcroqn:autoindent:
vim:tw=78:et:ts=2:sw=2:ft=help:norl:formatoptions+=tcroqn:autoindent:

View File

@@ -1,14 +1,15 @@
" ============================================================================
" File: plugin/delimitMate.vim
" Version: 2.3
" Modified: 2010-06-06
" Version: 2.4.1
" Modified: 2010-07-31
" Description: This plugin provides auto-completion for quotes, parens, etc.
" Maintainer: Israel Chauca F. <israelchauca@gmail.com>
" Manual: Read ":help delimitMate".
" Initialization: {{{
if exists("g:loaded_delimitMate") "{{{
" User doesn't want this plugin, let's get out!
if exists("g:loaded_delimitMate") || &cp
" User doesn't want this plugin or compatible is set, let's get out!
finish
endif
let g:loaded_delimitMate = 1
@@ -25,25 +26,27 @@ if v:version < 700
finish
endif
let s:loaded_delimitMate = 1 " }}}
let delimitMate_version = '2.3'
let s:loaded_delimitMate = 1
let delimitMate_version = "2.4.1"
"}}}
" Tools: {{{
" Functions: {{{
function! s:TestMappingsDo() "{{{
if !exists("g:delimitMate_testing")
silent call delimitMate#TestMappings()
else
let temp_varsDM = [b:delimitMate_expand_space, b:delimitMate_expand_cr, b:delimitMate_autoclose]
let temp_varsDM = [b:_l_delimitMate_expand_space, b:_l_delimitMate_expand_cr, b:_l_delimitMate_autoclose]
for i in [0,1]
let b:delimitMate_expand_space = i
let b:delimitMate_expand_cr = i
for a in [0,1]
let b:delimitMate_autoclose = a
call delimitMate#Init()
call delimitMate#UnMap()
call delimitMate#Map()
call delimitMate#TestMappings()
exec "normal i\<CR>"
normal o
endfor
endfor
let b:delimitMate_expand_space = temp_varsDM[0]
@@ -54,64 +57,84 @@ function! s:TestMappingsDo() "{{{
normal gg
endfunction "}}}
function! s:DelimitMateDo() "{{{
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"
call delimitMate#UnMap()
return 1
endif
endfor
function! s:DelimitMateDo(...) "{{{
" Initialize settings:
call delimitMate#Init()
" Check if this file type is excluded:
if exists("g:delimitMate_excluded_ft") &&
\ index(split(g:delimitMate_excluded_ft, ','), &filetype, 0, 1) >= 0
" Remove any magic:
call delimitMate#UnMap()
" Finish here:
return 1
endif
" First, remove all magic, if needed:
if exists("b:delimitMate_enabled") && b:delimitMate_enabled == 1
call delimitMate#UnMap()
endif
" Now, add magic:
call delimitMate#Map()
if a:0 > 0
echo "delimitMate has been reset."
endif
try
"echomsg "included"
let save_cpo = &cpo
let save_keymap = &keymap
set keymap=
set cpo&vim
call delimitMate#Init()
finally
let &cpo = save_cpo
let &keymap = save_keymap
endtry
endfunction "}}}
function! s:DelimitMateSwitch() "{{{
if b:delimitMate_enabled
call delimitMate#Init()
if exists("b:delimitMate_enabled") && b:delimitMate_enabled
call delimitMate#UnMap()
echo "delimitMate has been disabled."
else
call delimitMate#Init()
call delimitMate#UnMap()
call delimitMate#Map()
echo "delimitMate has been enabled."
endif
endfunction "}}}
"}}}
" Commands: {{{
call s:DelimitMateDo()
" Let me refresh without re-loading the buffer:
command! DelimitMateReload call s:DelimitMateDo()
command! DelimitMateReload call s:DelimitMateDo(1)
" Quick test:
command! DelimitMateTest call s:TestMappingsDo()
" Switch On/Off:
command! DelimitMateSwitch call s:DelimitMateSwitch()
"}}}
" Run on file type events.
"autocmd VimEnter * autocmd FileType * call <SID>DelimitMateDo()
autocmd FileType * call <SID>DelimitMateDo()
" Autocommands: {{{
" Run on new buffers.
autocmd BufNewFile,BufRead,BufEnter * if !exists("b:loaded_delimitMate") | call <SID>DelimitMateDo() | endif
augroup delimitMate
au!
" Run on file type change.
"autocmd VimEnter * autocmd FileType * call <SID>DelimitMateDo()
autocmd FileType * call <SID>DelimitMateDo()
" Flush the char buffer:
autocmd InsertEnter * call delimitMate#FlushBuffer()
autocmd BufEnter * if mode() == 'i' | call delimitMate#FlushBuffer() | endif
" 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
" Flush the char buffer:
autocmd InsertEnter * call delimitMate#FlushBuffer()
autocmd BufEnter *
\ if mode() == 'i' |
\ call delimitMate#FlushBuffer() |
\ endif
augroup END
"}}}