217 Commits

Author SHA1 Message Date
Vasily Toropov
1e9e49d6de Merge 3a7919fdb5 into becbd2d353 2024-08-19 16:09:57 -07:00
Israel Chauca Fuentes
becbd2d353 Merge pull request #308 from kevinhwang91/master
fix: &sw may be a zero
2024-08-06 01:02:38 -05:00
kevinhwang91
382c36bf57 fix: &sw may be a zero
E41: Out of memory!
2024-08-06 12:56:21 +08:00
Israel Chauca Fuentes
537a1da0fa Merge pull request #295 from ypid/fix/python-defaults
Set delimitMate_nesting_quotes for Python by default
2020-12-13 22:12:48 -06:00
Robin Schneider
055978491a Set delimitMate_nesting_quotes for Python by default
Closes: #173
2020-12-13 17:49:44 +01:00
Israel Chauca F
16687aec24 Clean s:get() and s:set() up. Force s:set() to take a default value. Closes #287 2020-07-29 11:50:21 -05:00
Israel Chauca Fuentes
728b57a656 Merge pull request #260 from aschrab/command-window
Do setup for command windows
2017-06-19 00:53:36 -04:00
Aaron Schrab
98143957cf Do setup for command windows 2017-06-18 18:35:29 -04:00
Israel Chauca Fuentes
b5719054be Merge pull request #246 from Atcold/patch-1
Fix doc
2016-07-19 16:19:28 -04:00
Alfredo Canziani
39d8f522f7 Fix doc
Fix unusual formatting in section 3.1
2016-07-19 14:11:06 -04:00
Israel Chauca Fuentes
8bc47fd1c4 Merge pull request #227 from wellle/fix-repeat-and-undo
Fix repeat and undo
2015-09-07 14:58:42 -04:00
Christian Wellenbrock
bc97837c71 Don't break undo sequence when moving in insert mode
Since Vim version 7.4.849 [1] we can move in insert mode without
breaking the undo sequence by inserting <C-G>U before the movement key.

Add s:joinUndo which returns "\<C-G>U" if available.
Use s:joinUndo before doing any <Left> or <Right> movements in insert
mode to keep a single undo point which can be repeated and undone
with a single command.

[1] https://github.com/vim/vim/releases/tag/v7.4.849
2015-09-06 15:42:30 +02:00
Vasily Toropov
3a7919fdb5 Fixed closing apostrophe in clojure files 2015-07-26 17:39:30 +10:00
Israel Chauca Fuentes
d24ad6b301 Merge pull request #210 from codebeige/fix_expand_cr_for_excluded_ft
Prevent errors inside excluded filetype
2015-05-18 13:24:02 -04:00
Israel Chauca Fuentes
81de76fe52 Update help. 2015-05-17 19:42:50 -04:00
Israel Chauca Fuentes
5945fdfd14 Consider more characters in smart_matchpairs default value. 2015-05-17 19:34:11 -04:00
Israel Chauca Fuentes
9a77c3aee6 Merge branch 'RGBD-fix-maparg-typo' 2015-05-01 22:35:56 -04:00
Oleg Zubchenko
342a04b427 fix maparg typo 2015-04-27 21:11:57 +03:00
Tibor Claassen
03e94587ae Add a guard clause to disable expansion for excluded filetypes 2015-03-28 15:48:40 +02:00
Israel Chauca Fuentes
c78a6e6d93 Allow using commas and colons in matchpairs. Fix #208. 2015-02-12 09:09:48 -05:00
Israel Chauca Fuentes
470c053a3b Better handling of insert_eol_marker. Should fix #195. 2015-01-17 14:03:48 -05:00
Israel Chauca Fuentes
254a89d67c Call s:setup() directly in the plugin. Should fix #202.
- Move 'call s:setup()' out of the autocmd.
- Add a test for the first buffer without filetype set.
2015-01-15 11:21:09 -05:00
Israel Chauca Fuentes
e7b4dedb84 Add option delimitMate_insert_eol_marker. Closes #195. 2015-01-08 17:14:27 -05:00
Israel Chauca Fuentes
21a3ade90c Use s:get() and s:set() instead of the abbreviated forms. 2015-01-06 08:50:17 -05:00
Israel Chauca Fuentes
8e30e70bcd Refactor reporting code. 2015-01-05 02:16:09 -05:00
Israel Chauca Fuentes
ac792c01b6 Indent with spaces. 2015-01-04 20:25:50 -05:00
Israel Chauca Fuentes
c23ef684e3 Add :DelimitMateOn, :DelimitMateOff & remove s:DelimitMateSwitch(). 2015-01-04 20:13:11 -05:00
Israel Chauca Fuentes
b63924f2b2 Update doc. 2015-01-04 20:09:00 -05:00
Israel Chauca Fuentes
07b7cc969f Merge pull request #201 from kballard/mappings-user-event
Add 2 User events when mapping and unmapping
2015-01-02 20:32:18 -05:00
Israel Chauca Fuentes
13e52d42ae Do not consider quotes for smart_matchpairs. Closes #200. 2015-01-02 12:08:16 -05:00
Israel Chauca Fuentes
aa9d737763 Rename functions. 2015-01-02 12:07:31 -05:00
Daniel Hahler
bf2b68edab Remove call to s:option_init("excluded_ft"): it is a global setting only 2015-01-01 14:58:41 -05:00
Israel Chauca Fuentes
fe9022433d Use :unlet only when necessary. 2015-01-01 09:41:32 -05:00
Israel Chauca Fuentes
6f7e6413ce Fix doco. 2014-12-30 21:02:44 -05:00
Kevin Ballard
a9a37854da Minor documentation tweaks
Fix a typo in a hyperlink, and change the sample code for
delimitMate#JumpAny() to use an <expr> mapping instead of <C-R>=.
2014-12-29 19:33:24 -08:00
Kevin Ballard
0739792d01 Add 2 User events when mapping and unmapping
delimitMate has some nice logic for doing per-filetype mappings, but
this logic can't be used when users provide mappings directly. To remedy
this, add two User events `delimitMate_map` and `delimitMate_unmap` that
are fired at the appropriate times. Users can use these events to define
per-filetype mappings just as delimitMate does.
2014-12-29 19:33:15 -08:00
Kevin Ballard
6f4f1b06d3 Be more conservative about unmapping
Restrict unmapping to check for '^<Plug>delimitMate' (case sensitive)
instead of 'delimitMate' (case insensitive). This should make it less
likely to accidentally trigger on custom user keybinds that reference
delimitMate.
2014-12-29 18:37:51 -08:00
Israel Chauca Fuentes
0049b07a1c Fix Makefile and gitignore. 2014-12-03 17:06:37 -05:00
Israel Chauca Fuentes
fe1983cfa1 Consider ´quotes in smart_quotes`. Close #182.
[:punct:] does not always match the same set of characters.
2014-12-02 11:07:22 -05:00
Israel Chauca Fuentes
a4ac44a84f Add test plugins to the &rtp if they are present. 2014-12-01 00:23:37 -05:00
Israel Chauca Fuentes
4c13ed6aee Make s:g() return default optional values. Close #186. 2014-11-30 11:40:19 -05:00
Israel Chauca Fuentes
eafd832c04 Fix indentation in test. 2014-11-29 16:08:43 -05:00
Israel Chauca Fuentes
e13872fdb2 Fix indentation in test. 2014-11-29 16:08:00 -05:00
Israel Chauca Fuentes
9a9b9edb9a Merge pull request #183 from blueyed/makefile-for-tests
Makefile for tests
2014-11-29 15:32:43 -05:00
Israel Chauca Fuentes
0f353bd2b3 Add test for smartindent and expand_cr. 2014-11-28 12:11:28 -05:00
Israel Chauca Fuentes
c1b832bbf8 Merge pull request #180 from kballard/fix_expand_cr_smartindent
Fix expand_cr behavior with 'smartindent'
2014-11-27 02:45:59 -05:00
Israel Chauca Fuentes
073957f0a1 Add expand_inside_quotes to report and fix doc. Closes #179. 2014-11-27 02:11:12 -05:00
Israel Chauca Fuentes
c678061b79 Fix '<CR><BS>. Closes #178. 2014-11-27 01:48:34 -05:00
Israel Chauca Fuentes
12c7d85ff6 Add a basic vimrc to help with tests. 2014-11-26 19:24:38 -05:00
Israel Chauca Fuentes
66834e7209 Allow custom regex for smart_quotes. Close #164.
- Use search() to match on the current line and remove most of the old
  code in IsSmartQuote().
- Allow using ! to negate the pattern.
- Add tests.
- s:s() :unlet variables before setting them.
2014-11-26 15:03:00 -05:00
Daniel Hahler
21072cf13e gitignore: test/build and test output/generated files 2014-06-15 15:14:40 +02:00
Daniel Hahler
d952f6c721 test: call new Makefile from test subdir 2014-06-15 15:14:40 +02:00
Daniel Hahler
0efe44bc70 Rename README to README.md 2014-06-15 15:14:40 +02:00
Daniel Hahler
631d72465a Add a Makefile to provide make test 2014-06-15 15:14:40 +02:00
Kevin Ballard
4024181af2 Fix expand_cr behavior with 'smartindent'
When indentation is controlled by 'smartindent', the expand_cr behavior
doesn't end up producing the same results that you would get without
delimitMate. The following behavior results instead:

Before: {|}
After: {
		|
	}

The expected behavior is to produce the following:

Before: {|}
After: {
	|
}

To that end, detect when indentation is controlled by 'smartindent' and
adjust the indentation of the close line to match.
2014-06-03 18:26:42 -07:00
Israel Chauca Fuentes
38487bbec8 Merge pull request #169 from blueyed/hack-jumpout-del-and-reinsert
JumpOut: delete and insert char instead of jumping over.
2014-02-19 20:40:27 -05:00
Israel Chauca Fuentes
c74a48ccd8 Merge pull request #167 from blueyed/makefile-detect-sed
Detect $SED dynamically, but do not force `gsed`
2014-02-14 02:41:58 -05:00
Daniel Hahler
df1f32f772 JumpOut: delete and insert char instead of jumping over
Ref: https://github.com/Raimondi/delimitMate/issues/168
2014-02-11 23:55:25 +01:00
Daniel Hahler
f2b9b3a0c2 Detect $SED dynamically, but do not force gsed 2014-02-06 02:24:43 +01:00
Daniel Hahler
1c45f7bbde ParenDelim: improve smart_matchpairs handling
* move the check up
* only handle it when smart_matchpairs is configured (default)
2014-02-06 02:20:29 +01:00
Israel Chauca Fuentes
a1f21e8ef5 Merge pull request #162 from blueyed/handle-dotted-filetype
Fix &ft check in QuoteDelim: handle dotted filetypes
2014-02-02 21:05:39 -08:00
Israel Chauca Fuentes
eba94168ce Merge pull request #161 from blueyed/doc-typo
minor: fix doc typo
2014-02-02 21:03:22 -08:00
Daniel Hahler
06c1f31632 Fix &ft check in QuoteDelim: handle dotted filetypes
From `:h 'filetype'`:

		When a dot appears in the value then this separates two filetype
		names.  Example:
			/* vim: set filetype=c.doxygen : */ ~

I am using `ft=pentadactyl.vim` for my Pentadactyl/Vimperator
configuration files.
2014-01-29 11:23:20 +01:00
Daniel Hahler
9826c667e0 minor: fix doc typo 2014-01-29 11:19:50 +01:00
Israel Chauca Fuentes
35280c1444 Merge pull request #158 from peter50216/patch-1
Run DelimitMateDo() when loading plugin.
2014-01-07 13:07:19 -08:00
peter50216
82160a5de6 run DelimitMateDo() when loading plugin.
Current setting would make this plugin's mapping added last, and cause conflict with https://github.com/tpope/vim-endwise. See https://github.com/tpope/vim-endwise/pull/13.
2014-01-07 12:00:54 +08:00
Israel Chauca Fuentes
07d9fa9ddc Check delimitMate_matchpairs’ syntax. Also some formatting. 2014-01-04 18:14:03 -05:00
Israel Chauca Fuentes
54853a954c Consider | for matchpairs. Also some minor formatting. Fix #155. 2014-01-04 16:43:45 -05:00
Israel Chauca Fuentes
f00f6b6cf2 Simplify TriggerAbb(). 2013-12-25 02:28:46 -05:00
Israel Chauca Fuentes
d280d23a83 Do not try to expand iabbreviations when popup menu on. Should fix #154. 2013-12-25 02:09:41 -05:00
Israel Chauca Fuentes
821e0019fb Consider popup menu when expanding. Close #154. 2013-12-24 13:20:39 -05:00
Israel Chauca Fuentes
5ef40e0234 Do not expand cr and space inside quotes by default. Close #153.
- Add delimitMate_expand_inside_quotes.
- Add tests.
2013-12-24 02:48:35 -05:00
Israel Chauca Fuentes
399e18d669 Merge pull request #152 from Gray-Wind/master
Fix logical issue
2013-12-21 06:45:22 -08:00
Ilya Kolo
92fba35d27 Fix logical issue 2013-12-21 14:31:40 +04:00
Israel Chauca Fuentes
0528bdac15 Only try to expand abbreviations when supported. Close #151. 2013-12-20 18:21:34 -05:00
Israel Chauca Fuentes
5db098e953 Better testing for quotes. 2013-12-19 00:26:58 -05:00
Israel Chauca Fuentes
b45536fe8d Fix expanding abbreviations. Close #145. 2013-12-18 23:55:02 -05:00
Israel Chauca Fuentes
3dde5cc8cb Do not use <C-R>= for matchpairs. Close #150, close #143. 2013-12-18 23:05:30 -05:00
Israel Chauca Fuentes
5787ec4f59 Add explanation about delimitMate_jump_expansion. Close #137. 2013-12-18 12:52:57 -05:00
Israel Chauca Fuentes
2dc880bf1c Merge pull request #147 from mganjoo/master
Add C-h synonym for delimitMateBS
2013-12-18 09:14:10 -08:00
Israel Chauca Fuentes
440f38858f Merge pull request #149 from thiderman/comments
Modify QuoteDelim() to be smart about vim comments
2013-12-15 15:47:18 -08:00
Lowe Thiderman
f7f895c211 Modify QuoteDelim() to be smart about vim comments
Add simple check into QuoteDelim() that checks if the user is about to start
a comment in vim files. If that's the case, don't balance it.
2013-12-15 22:24:20 +01:00
Milind Ganjoo
654dc14e6e Add C-h synonym for delimitMateBS (can't add one for S-BS though) 2013-10-26 17:13:26 -07:00
Israel Chauca Fuentes
543be33b13 Better handling of nested quotes. Closes #134. 2013-07-22 20:52:05 -04:00
Israel Chauca Fuentes
7345bfddef Update readme. 2013-07-22 13:35:59 -04:00
Israel Chauca Fuentes
16a35eefab Update version and doc. 2013-07-22 13:29:36 -04:00
Israel Chauca Fuentes
74ab16ea5b Rewrite makefile. 2013-07-22 13:28:52 -04:00
Israel Chauca Fuentes
2adbf5a8d7 Remove old test script. 2013-07-14 03:34:20 -04:00
Israel Chauca Fuentes
e4a02eb998 Do not modify the line when checking for syntax groups. 2013-07-14 01:31:30 -04:00
Israel Chauca Fuentes
ad11ab2210 Fix tests. 2013-07-14 01:30:05 -04:00
Israel Chauca Fuentes
6b0d448f6a Don't use a char buffer anymore. 2013-07-14 01:29:53 -04:00
Israel Chauca Fuentes
32c9db8f37 Simplify command. 2013-07-13 23:01:02 -04:00
Israel Chauca Fuentes
a77423a46f Remove superfluous unmapping. 2013-07-13 22:59:58 -04:00
Israel Chauca Fuentes
57fd02b2e0 Fix tests. 2013-07-13 22:58:42 -04:00
Israel Chauca Fuentes
14faba1c62 Don't use setline() for left-side matchpair. 2013-07-13 21:57:21 -04:00
Israel Chauca Fuentes
8ab087c95c Don't use setline() with quotes. 2013-07-13 21:27:38 -04:00
Israel Chauca Fuentes
61d62e8920 small fix. 2013-07-13 19:54:23 -04:00
Israel Chauca Fuentes
7ce61655a7 Do not remove caracters when inserting a closing paren. Close #133. 2013-07-09 14:10:28 -04:00
Israel Chauca Fuentes
8d133d4726 Set bs to 2 on tests. 2013-06-27 21:51:28 -04:00
Israel Chauca Fuentes
7caa6092b7 Fix <S-Tab> mapping. Close #132. 2013-06-27 21:35:37 -04:00
Israel Chauca Fuentes
d98d8c0a0d Fix :DelimitMateTest. 2013-06-27 20:59:04 -04:00
Israel Chauca Fuentes
e2d63e38f6 Store internal values in s:options. Close #79. 2013-06-22 00:20:45 -04:00
Israel Chauca Fuentes
579e3520a4 Use setter/getter everywhere (well, almost everywhere). 2013-06-21 23:49:48 -04:00
Israel Chauca Fuentes
90d07a68be Update options list. 2013-06-21 22:42:41 -04:00
Israel Chauca Fuentes
2cb3f4d5e6 Use getter func. 2013-06-21 22:42:15 -04:00
Israel Chauca Fuentes
3a23e89cb5 Jump out of space expansion. Never meant to disable it. Closes #129. 2013-06-21 21:49:07 -04:00
Israel Chauca Fuentes
70e1ac1462 Smart quotes consider balanced quotes on current line. Closes #94. 2013-06-19 00:43:42 -04:00
Israel Chauca Fuentes
d4ba528935 Add eol marker finished. Closes #102. Add s:g(). 2013-06-19 00:06:10 -04:00
Israel Chauca Fuentes
8a8aad183f Fix tests, BS in expansions and close #105. 2013-06-18 18:52:26 -04:00
Israel Chauca Fuentes
cfc6654855 Make jumping over space and CR expansions optional and off by default.
- Closes #130.
- Closes #110.
- As suggested in #95.
2013-06-18 16:02:48 -04:00
Israel Chauca Fuentes
f2efe4331b Merge pull request #128 from matthias-guenther/master
Markdown file ending for README
2013-05-12 13:53:31 -07:00
Matthias Günther
dfa7e9b730 Markdown ending for README 2013-05-11 22:21:28 +02:00
Israel Chauca Fuentes
765bdd80dc Fix typo. 2013-04-10 11:04:15 -04:00
Israel Chauca Fuentes
739d2f9bd4 Call #Finish() only when necessary for <BS>. As mentioned in #124. 2013-03-27 18:33:58 -04:00
Israel Chauca Fuentes
eb7738e4aa Call #Finish() only when necessary. Closes #124. 2013-03-27 16:50:53 -04:00
Israel Chauca Fuentes
32f5d8df07 Do not map over <Esc>. Closes #118. 2013-02-12 10:37:42 -05:00
Israel Chauca Fuentes
7b5887c324 Do not create bogus imap. closes #113 , closes #87. 2013-02-08 20:43:32 -05:00
Israel Chauca Fuentes
0326b7c14a Flush buffer on scrolling. 2012-07-20 15:51:19 -04:00
Israel Chauca Fuentes
1dfe26a538 Fix CR expansion & syn fold enabled by InsertLeave
Benamin Fritz reported the following:

Without the "zv", if the user has syntax folding on, when the mapping
invokes <Esc> the pair of braces which were just separated by a <CR>
could become folded, so that the trailing "o" opens a new line AFTER
the pair.
2012-06-08 16:56:34 -04:00
Israel Chauca Fuentes
9c1564a22f Merge pull request #99 from jamessan/master
Fix spelling mistake in README
2012-05-30 18:51:46 -07:00
James McCoy
028964cf7d README: Fix spelling mistake 2012-05-30 21:43:35 -04:00
Israel Chauca Fuentes
5a84c1a746 Update :DelimitMateTest for eol_marker. 2012-04-15 20:16:44 -04:00
Israel Chauca Fuentes
0f9563969d Update doc about #77. 2012-04-15 01:47:19 -04:00
Israel Chauca Fuentes
d3ffebab74 Replace for loop with map(). Should finish with #77. 2012-04-15 01:34:56 -04:00
Israel Chauca Fuentes
ece6c39a65 Add eol marker only if inserted on the same 'insert session'. 2012-04-15 01:02:28 -04:00
Israel Chauca Fuentes
ad151d3e55 Fix readme. 2012-04-14 19:36:51 -04:00
Israel Chauca Fuentes
b65d719353 Add string next to the closing matchpair when at the eol. Closes #77. 2012-04-14 19:36:51 -04:00
Israel Chauca Fuentes
a42dff4ad8 Merge pull request #97 from grota/master
fix for #96
2012-04-08 08:57:51 -07:00
Giuseppe Rota
4a7d5a6e54 screwup in map checks 2012-04-08 13:37:11 +02:00
Israel Chauca Fuentes
50a0df0be4 Merge pull request #96 from grota/master
Avoid mapping in ExtraMappings when there's already a map.
2012-04-07 20:19:24 -07:00
Giuseppe Rota
cecebf6e86 Avoid mapping in ExtraMappings when there's already a map. 2012-04-07 13:17:34 +02:00
Israel Chauca Fuentes
ad4430706e Fix conflict with cindent. Comment on #95. 2012-04-01 17:59:40 -04:00
Israel Chauca Fuentes
93d4a373fb Correct test for CR expansions. 2012-03-31 17:00:51 -04:00
Israel Chauca Fuentes
a9f51531d9 Consider indentation with BS on empty expanded CR. 2012-03-31 16:56:31 -04:00
Israel Chauca Fuentes
6bb98110b4 Consider space and CR expansions when jumping over. Closes #95. 2012-03-31 13:33:24 -04:00
Israel Chauca Fuentes
0b34aea202 Always jump over the quote on the right. Closes #89. 2012-03-04 00:11:40 -05:00
Israel Chauca Fuentes
f1e92d05d5 Make smart quote work beyond the first column. Closes #89. 2012-03-03 16:09:08 -05:00
Israel Chauca Fuentes
8ec2bcb89a Merge pull request #88 from Glench/patch-2
Fix grammar in README
2012-02-29 16:32:52 -08:00
Glen Chiacchieri
beb87ef41f Fix grammar in README 2012-02-29 19:26:07 -05:00
Israel Chauca Fuentes
26a6def62f Add an option to prevent mapping to ^[OC.
Might be useful in #87.
2012-02-28 18:27:13 -05:00
Israel Chauca Fuentes
0fb597ef36 Make :DelimitMateTest more verbose.
- Add the output of :version.
- Print all mapping regardless of value.
- Ask before overwriting a modified buffer.
2012-02-25 17:45:28 -05:00
Israel Chauca Fuentes
fe5dd9a61a Fix typo in doc. Closes #85. 2012-02-24 20:48:05 -05:00
Israel Chauca Fuentes
bb9b0edcc5 Simplify CR expansion mapping. Add Test for it. 2012-02-24 20:32:42 -05:00
Israel Chauca Fuentes
f3176a664c Merge branch 'master' of https://github.com/gyim/delimitMate 2012-02-23 20:46:02 -05:00
Akos Gyimesi
1cbbe90a09 Allow CR expansion for arbitrary line suffix. 2012-02-23 21:35:40 +01:00
Israel Chauca Fuentes
a9174f65ba Merge pull request #83 from gyim/master
Add mapping for default MacVim movements
2012-02-23 12:01:28 -08:00
Akos Gyimesi
2af2dd2350 Add mapping for default MacVim movements 2012-02-23 20:58:42 +01:00
Israel Chauca Fuentes
9c77b8434a Use default cpo values while creating mappings. Closes #72. 2012-02-22 23:14:01 -05:00
Israel Chauca Fuentes
646794cbda Remove "apostrophe" feature. Closes #81. 2012-02-16 14:53:01 -05:00
Israel Chauca Fuentes
93fdcf92e1 Update README. 2012-02-16 02:30:35 -05:00
Israel Chauca Fuentes
fbbd9514c5 Add real README. 2012-02-16 02:28:10 -05:00
Israel Chauca Fuentes
be5c41b3c1 Add test files. 2012-02-16 01:59:28 -05:00
Israel Chauca Fuentes
b853ee9f35 Handle backspace option gracefully. Quick test for #64. 2012-02-15 22:05:48 -05:00
Israel Chauca Fuentes
eb2625c4a7 Consider non ascii chars for smart quote. 2012-02-15 15:38:11 -05:00
Israel Chauca Fuentes
e17f6cd23c Consider non ascii chars for smart quote. Close #73. 2012-02-15 14:52:53 -05:00
Israel Chauca Fuentes
54acd56b48 Fix space expansion. Closes #68. 2012-02-15 14:25:36 -05:00
Israel Chauca Fuentes
9bdd4b078a Merge pull request #80 from Glench/patch-1
Fix typo in readme.
2012-02-14 17:16:22 -08:00
Israel Chauca Fuentes
f5748da36c Fix issues with quotes. 2012-02-14 18:39:48 -05:00
Israel Chauca Fuentes
eade67b409 Remove noise. 2012-02-12 13:33:04 -05:00
Glen Chiacchieri
b3f62f79c2 Fix typo in readme.
This was bothering me way too much.
2012-02-12 13:25:37 -05:00
Israel Chauca Fuentes
9d133d5b69 Fix flushing of char buffer. 2012-02-09 21:28:53 -05:00
Israel Chauca Fuentes
9f003b5bf5 Add CursorIdx() multibyte aware col(). 2012-02-08 22:44:39 -05:00
Israel Chauca Fuentes
e688e20151 Optimize IsSpaceExpansion. 2012-02-08 03:50:43 -05:00
Israel Chauca Fuentes
8749708115 Optimize IsEmptyPair. 2012-02-08 03:41:11 -05:00
Israel Chauca Fuentes
5cc5d8d9b3 Replace GeetChar*Cursor with GetCharFromCursor. 2012-02-08 03:07:49 -05:00
Israel Chauca Fuentes
98b4119746 Attempt to fix CR expansion. 2012-02-08 01:08:10 -05:00
Israel Chauca Fuentes
c889905e47 Fix duplicated closing paren with <S-Tab>.
Code from @albertosantini. Closes #69.
2012-02-08 00:22:18 -05:00
Israel Chauca Fuentes
db54dadb46 Remove unused var. 2012-02-08 00:22:04 -05:00
Israel Chauca Fuentes
604260f56e Use GetChar*Cursor() instead of byte indexes. 2012-02-08 00:02:58 -05:00
Israel Chauca Fuentes
581a3ebc17 Modify b:_l_delimitMate_matchpairs_list. 2012-02-07 22:32:17 -05:00
Israel Chauca Fuentes
cc1acaba96 Allow multibyte chars with <BS>. Closes #78.
- Add delimitMate#GetCharUnderCursor()
- Add delimitMate#GetCharBeforeCursor()
- Simplify delimitMate#Del()
2012-02-07 22:11:53 -05:00
Israel Chauca Fuentes
7b781ab6b6 Merge branch 'master' of https://github.com/MSch/delimitMate 2012-02-07 18:46:04 -05:00
Israel Chauca Fuentes
233eb52a97 Merge pull request #67 from tmhedberg/master
Option to disable delimitMate in all buffers by default
2012-02-05 21:19:50 -08:00
Martin Schürrer
aff9743269 Also work with <C-Left> and <C-Right> 2011-12-18 12:22:16 +01:00
Taylor Hedberg
ce1d05fac5 [fix] Broken undo after <CR> expanded 2011-11-03 12:47:21 -04:00
Taylor Hedberg
6dad313734 Documentation for delimitMate_offByDefault 2011-08-25 12:42:32 -04:00
Taylor Hedberg
5263e25548 delimitMate_offByDefault option to disable delimitMate by default 2011-08-25 12:36:15 -04:00
Israel Chauca Fuentes
39b8298390 Typo on doc. "brake->break" now all of them. 2011-07-04 16:51:48 -05:00
Israel Chauca Fuentes
57b80ea78a Typo on doc. "brake->break" 2011-07-04 16:50:02 -05:00
Israel Chauca Fuentes
a5b7141fc4 Set and restore &cpo in the right place. 2011-04-17 15:49:27 -05:00
Israel Chauca Fuentes
9efb01da68 UPdate README. 2011-01-14 23:31:20 -06:00
Israel Chauca Fuentes
860c45ab2a Limit autocmd effects. 2011-01-14 22:13:00 -06:00
Israel Chauca Fuentes
8686edfc63 Update version. 2011-01-14 20:59:53 -06:00
Israel Chauca Fuentes
5e7a7c4738 Update change log. 2011-01-14 20:57:56 -06:00
Israel Chauca Fuentes
928cc1146a Fix behaviour of b:loaded_delimitMate. 2011-01-14 20:49:28 -06:00
Israel Chauca Fuentes
d420afdacd Trivial formatting. 2011-01-14 20:37:40 -06:00
Israel Chauca Fuentes
f6015300a0 Modify smart_matchpairs regex. 2011-01-14 20:37:04 -06:00
Israel Chauca Fuentes
e183064744 Update change log. 2011-01-14 20:36:29 -06:00
Israel Chauca Fuentes
40849c94ef Update documentation. 2011-01-14 20:29:22 -06:00
Israel Chauca Fuentes
4c1424f9bd Reorder stuff. 2010-12-11 05:23:59 -06:00
Israel Chauca Fuentes
0783f97fc0 Modify :DelimitMateTest output. 2010-12-11 05:23:27 -06:00
Israel Chauca Fuentes
e551885c24 Prevent indenting from propagating on the report. 2010-12-11 00:16:31 -06:00
Israel Chauca Fuentes
4891a04258 Fix double space. 2010-12-11 00:10:21 -06:00
Israel Chauca Fuentes
ad77a9a75e Append output of :set to report. 2010-12-11 00:08:35 -06:00
Israel Chauca Fuentes
5bf35a6b31 Delete empty <CR> expansion with indentation. 2010-12-11 00:07:59 -06:00
Israel Chauca Fuentes
49044099dd Change format of report. 2010-12-11 00:07:19 -06:00
Israel Chauca Fuentes
7c423067a8 UPdate to delimitMateTests#Main(). 2010-12-10 23:26:21 -06:00
Israel Chauca Fuentes
d08fa765b9 Update doc. 2010-12-10 23:25:10 -06:00
Israel Chauca Fuentes
f47bcd8e3f Reorder mappings. 2010-12-08 21:56:47 -06:00
Israel Chauca Fuentes
873e79ec37 Allow jumping over contiguous delimiters. Closes #44. 2010-12-08 03:34:45 -06:00
Israel Chauca Fuentes
589b2ae85a Merge branch 'master' into jump_over 2010-12-07 17:05:00 -06:00
Israel Chauca Fuentes
f9f2b5f177 Don't leave mappings around.
Some mappings weren't being unmapped on filetype change because options
were initialized before the call to Unmap().
2010-12-07 16:59:09 -06:00
Israel Chauca Fuentes
4157dc8a88 Make jumping back optional. 2010-12-06 22:08:59 -06:00
Israel Chauca Fuentes
d0fc1456b7 Use \# to insert closing pair in smart_matchpairs. 2010-11-17 23:17:25 -06:00
Israel Chauca Fuentes
86f70a7d9c Use regex for smart_matchpairs.
If the text in the line to the right of the cursor matches
smart_matchpairs, do not auto close.

To match the opening paren, insert a escaped bang (\!) in the pattern.
2010-11-17 17:53:33 -06:00
Israel Chauca Fuentes
f7b53f045d Fix typo. 2010-11-09 03:19:44 -06:00
Israel Chauca Fuentes
f3d140e363 Update credits section. 2010-11-09 01:12:26 -06:00
Israel Chauca Fuentes
93a1770f37 Doc update. 2010-11-08 09:47:51 -06:00
Israel Chauca Fuentes
859a732509 Merge git://github.com/ervandew/delimitMate into temporal
Conflicts:
	autoload/delimitMate.vim
2010-11-08 09:22:20 -06:00
Israel Chauca Fuentes
eb778be64b Update OptionsList(). 2010-11-06 22:47:05 -05:00
Israel Chauca Fuentes
2b2ae65182 Eliminate some noise from DelimitMateTest. 2010-11-06 22:43:03 -05:00
Israel Chauca Fuentes
e1b52d3676 Some formating. 2010-11-06 22:41:31 -05:00
Israel Chauca Fuentes
ff4745b191 More flexible test for 'backspace' values. 2010-11-06 22:38:13 -05:00
Israel Chauca Fuentes
2ba694830d Use '\w' instead of '[[:alnum:]]' in smart_quotes. 2010-11-06 22:35:40 -05:00
Israel Chauca Fuentes
12c5c96ca2 Add smart_matchpairs
This option will prevent delimitMate from inserting the closing
delimiter when there is a keyword character on the right of the cursor.
2010-11-06 20:05:40 -05:00
ervandew
a97af1fb97 add option to disable closing delims if open delim added before an alphanumeric 2010-11-06 17:15:23 -07:00
Israel Chauca Fuentes
5bf6a1e30c Fix DelimitMateTest. 2010-10-09 17:23:32 -05:00
22 changed files with 1825 additions and 2022 deletions

4
.gitignore vendored
View File

@@ -1,8 +1,12 @@
*.sw?
*.un?
*.vba
*.vmb
*.zip
*.gz
vimball.txt
*.orig
tags
test/build
test/*.tap
test/*.msgout

119
Makefile
View File

@@ -1,62 +1,81 @@
PLUGIN=$(shell basename "$$PWD")
SCRIPT=$(wildcard plugin/*.vim)
#AUTOL=$(wildcard autoload/*.vim)
AUTOL=autoload/$(PLUGIN).vim
PLUGIN = $(wildcard plugin/*.vim)
SOURCES = $(PLUGIN)
LIB = $(wildcard autoload/*.vim)
SOURCES += $(LIB)
DOC = $(wildcard doc/*.txt)
TESTS=$(wildcard autoload/*Tests.vim)
VERSION=$(shell perl -ne 'if (/\*\sCurrent\srelease:/) {s/^\s+(\d+\.\S+)\s.*$$/\1/;print}' $(DOC))
VIMFOLDER=~/.vim/
VIM=/usr/bin/vim
SOURCES += $(DOC)
NAME = delimitMate
VERSION = $(shell $(SED) -n -e '/Current \+release/{s/^ \+\([0-9.]\+\).*/\1/;p;}' $(firstword $(DOC)))
FILENAME = $(NAME)-$(VERSION)
DESTDIR = $(HOME)/.vim
VIM = vim
SED = $(shell command -v gsed || command -v sed)
PERL = perl
comma := ,
empty :=
space := $(empty) $(empty)
.PHONY: $(PLUGIN).vba README
.PHONY: version clean distclean undo release test install uninstall
all: vimball README zip gzip
vimball: $(PLUGIN).vba
all: zip gzip
dist: version all
vimball: $(FILENAME).vmb
zip: $(FILENAME).zip $(FILENAME).vmb.zip
gzip: $(FILENAME).tar.gz $(FILENAME).vmb.gz
clean:
@echo clean
rm -f *.vba */*.orig *.~* .VimballRecord *.zip *.gz
rm -f */*.orig *.~* .VimballRecord *.zip *.gz *.vmb
dist-clean: clean
distclean: clean
-zsh -c 'setopt extendedglob; rm -f ^(README.md|Makefile|basic_vimrc)(.)'
-zsh -c 'setopt extendedglob; rm -f .^(git|README.md|Makefile|basic_vimrc)*'
undo:
for i in */*.orig; do mv -f "$$i" "$${i%.*}"; done
README:
@echo README
cp -f $(DOC) README
$(PLUGIN).vba:
@echo $(PLUGIN).vba
rm -f $(PLUGIN)-$(VERSION).vba
$(VIM) -N -c 'ru! vimballPlugin.vim' -c ':call append("0", [ "$(SCRIPT)", "$(AUTOL)", "$(DOC)"])' -c '$$d' -c ":%MkVimball $(PLUGIN)-$(VERSION) ." -c':q!'
ln -f $(PLUGIN)-$(VERSION).vba $(PLUGIN).vba
zip:
@echo zip
rm -f *.zip
zip -r $(PLUGIN).zip doc plugin autoload
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
gzip: vimball
@echo vimball
gzip -f $(PLUGIN).vba
release: version all
version:
@echo version: $(VERSION)
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/}' $(DOC)
@echo Version: $(VERSION)
$(PERL) -i.orig -pne 'if (/^"\sVersion:/) {s/(\d+\.\S+)/$(VERSION)/}' $(PLUGIN) $(LIB)
$(PERL) -i.orig -pne \
'if (/let\sdelimitMate_version/) {s/"(\d+\.\S+)"/"$(VERSION)"/}' $(PLUGIN)
$(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}' \
$(PLUGIN) $(LIB)
$(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:
test:
$(MAKE) -C test
install: $(SOURCES)
for dir in $(^D);\
do install -d -m 0755 $(DESTDIR)$(PREFIX)/$$dir;\
done;\
for file in $^;\
do install -m 0644 $$file $(DESTDIR)$(PREFIX)/$$file;\
done;
uninstall:
for file in $(SOURCES);\
do rm -f $(DESTDIR)$(PREFIX)/$$file;\
done;
%.vmb: $(SOURCES)
$(VIM) -N -es -u NORC \
-c 'call setline(1,["$(subst $(space),"$(comma)",$^)"])'\
-c "%MkVimball! $(basename $@) ." -c 'q!'
%.vmb.zip: vimball
zip $@ $(basename $@)
%.zip: $(SOURCES)
zip $@ $^
%.vmb.gz: vimball
gzip -f < $(basename $@) > $@
%.tar.gz: $(SOURCES)
tar -cvzf $@ $^
# vim:ts=2:sw=2

761
README
View File

@@ -1,761 +0,0 @@
*delimitMate.txt* Trying to keep those beasts at bay! v2.5.1 *delimitMate*
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
MMMM MMMMMMMMM MMMMMMMMMMMMMMMMMMMMMMMMMM MMMMM MMMMMMMMMMMMMMMMMMMMM ~
MMMM MMMMMMMMM MMMMMMMMMMMMMMMMMMMMMMMMMM MMM MMMMMMMMMMMMMMMMMMMMM
MMMM MMMMMMMMM MMMMMMMMMMMMMMMMMMMMM MMM M M MMMMMMMMMM MMMMMMMMM ~
MMMM MMM MMM MM MM M M MMM MM MM MM MM MMM MMM MMM MM
MM MM M MM MMMMMM MMMMMMM MMM MMMMM MM M MMM MMM M M ~
M M MM MM MM MM M M MM MMM MMM MMMMM MMMMM MMM MMM M
M M MM MMMMM MM MM M M MM MMM MMM MMMMM MMM MMM MMM MMMM ~
M M MM M MM MM MM M M MM MMM MMM MMMMM MM M MMM MMM M M
MM MMM MMM MM MM M M MM MMM MM MMMMM MMM MMM MMM MM ~
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
==============================================================================
0.- CONTENTS *delimitMate-contents*
1. Introduction____________________________|delimitMateIntro|
2. Customization___________________________|delimitMateOptions|
2.1 Options summary____________________|delimitMateOptionSummary|
2.2 Options details____________________|delimitMateOptionDetails|
3. Functionality___________________________|delimitMateFunctionality|
3.1 Automatic closing & exiting________|delimitMateAutoClose|
3.2 Expansion of space and CR__________|delimitMateExpansion|
3.3 Backspace__________________________|delimitMateBackspace|
3.4 Smart Quotes_______________________|delimitMateSmartQuotes|
3.5 Balancing matching pairs___________|delimitMateBalance|
3.6 FileType based configuration_______|delimitMateFileType|
3.7 Syntax awareness___________________|delimitMateSyntax|
4. Commands________________________________|delimitMateCommands|
5. Mappings________________________________|delimitMateMappings|
6. Functions_______________________________|delimitMateFunctions|
7. TODO list_______________________________|delimitMateTodo|
8. Maintainer______________________________|delimitMateMaintainer|
9. Credits_________________________________|delimitMateCredits|
10. History_________________________________|delimitMateHistory|
==============================================================================
1.- INTRODUCTION *delimitMateIntro*
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.
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.
NOTE 1: If you have any trouble with this plugin, please run |:DelimitMateTest|
in a new buffer to see what is not working.
NOTE 2: |'timeout'| needs to be set when working in the terminal, otherwise you
might find weird behaviour with mappings including <Esc> or arrow keys.
NOTE 3: Abbreiations set with |:iabbrev| will not be expanded by delimiters
used on delimitMate, you should use <C-]> (read |i_CTRL-]|) to expand them on
the go.
==============================================================================
2. CUSTOMIZATION *delimitMateOptions*
You can create your own mappings for some features using the global functions.
Read |DelimitMateFunctions| for more info.
------------------------------------------------------------------------------
2.1 OPTIONS SUMMARY *delimitMateOptionSummary*
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.
|'delimitMate_autoclose'| Tells delimitMate whether to automagically
insert the closing delimiter.
|'delimitMate_matchpairs'| Tells delimitMate which characters are
matching pairs.
|'delimitMate_quotes'| Tells delimitMate which quotes should be
used.
|'delimitMate_nesting_quotes'| Tells delimitMate which quotes should be
allowed to be nested.
|'delimitMate_expand_cr'| Turns on/off the expansion of <CR>.
|'delimitMate_expand_space'| Turns on/off the expansion of <Space>.
|'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_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.
------------------------------------------------------------------------------
2.2 OPTIONS DETAILS *delimitMateOptionDetails*
Add the shown lines to your vimrc file in order to set the below options.
Buffer variables take precedence over global ones and can be used along with
autocmd to modify delimitMate's behavior for specific file types, read more in
|delimitMateFileType|.
Note: Use buffer variables only to set options for specific file types using
:autocmd, use global variables to set options for every buffer. Read more in
|g:var| and |b:var|.
------------------------------------------------------------------------------
*'loaded_delimitMate'*
*'b:loaded_delimitMate'*
This option prevents delimitMate from loading.
e.g.: >
let loaded_delimitMate = 1
au FileType mail let b:loaded_delimitMate = 1
<
------------------------------------------------------------------------------
*'delimitMate_autoclose'*
*'b:delimitMate_autoclose'*
Values: 0 or 1. ~
Default: 1 ~
If this option is set to 0, delimitMate will not add a closing delimiter
automagically. See |delimitMateAutoClose| for details.
e.g.: >
let delimitMate_autoclose = 0
au FileType mail let b:delimitMate_autoclose = 0
<
------------------------------------------------------------------------------
*'delimitMate_matchpairs'*
*'b:delimitMate_matchpairs'*
Values: A string with |'matchpairs'| syntax, plus support for multi-byte~
characters.~
Default: &matchpairs ~
Use this option to tell delimitMate which characters should be considered
matching pairs. Read |delimitMateAutoClose| for details.
e.g: >
let delimitMate_matchpairs = "(:),[:],{:},<:>"
au FileType vim,html let b:delimitMate_matchpairs = "(:),[:],{:},<:>"
<
------------------------------------------------------------------------------
*'delimitMate_quotes'*
*'b:delimitMate_quotes'*
Values: A string of characters separated by spaces. ~
Default: "\" ' `" ~
Use this option to tell delimitMate which characters should be considered as
quotes. Read |delimitMateAutoClose| for details.
e.g.: >
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_expand_cr'*
*'b:delimitMate_expand_cr'*
Values: 1 or 0 ~
Default: 0 ~
This option turns on/off the expansion of <CR>. Read |delimitMateExpansion|
for details.
e.g.: >
let delimitMate_expand_cr = 1
au FileType mail let b:delimitMate_expand_cr = 1
<
------------------------------------------------------------------------------
*'delimitMate_expand_space'*
*'b:delimitMate_expand_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 = 1
au FileType tcl let b:delimitMate_expand_space = 1
<
------------------------------------------------------------------------------
*'delimitMate_smart_quotes'*
*'b:delimitMate_smart_quotes'*
Values: 1 or 0 ~
Default: 1 ~
This option turns on/off the smart quotes feature. Read
|delimitMateSmartQuotes| for details.
e.g.: >
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'*
Values: A string of syntax group names names separated by single commas. ~
Default: Comment ~
This options turns delimitMate off for the listed regions, read |group-name|
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 ":". ~
Default: No longer used. ~
NOTE: This feature is turned off by default, it's been kept for compatibility
with older version, read |delimitMateSmartQuotes| for details.
If auto-close is enabled, this option tells delimitMate how to try to fix the
balancing of single quotes when used as apostrophes. The values of this option
are strings of text where a single quote would be used as an apostrophe (e.g.:
the "n't" of wouldn't or can't) separated by ":". Set it to an empty string to
disable this feature.
e.g.: >
let delimitMate_apostrophes = ""
au FileType tcl let delimitMate_apostrophes = ""
<
==============================================================================
3. FUNCTIONALITY *delimitMateFunctionality*
------------------------------------------------------------------------------
3.1 AUTOMATIC CLOSING AND EXITING *delimitMateAutoClose*
With automatic closing enabled, if an opening delimiter is inserted the plugin
inserts the closing delimiter and places the cursor between the pair. With
automatic closing disabled, no closing delimiters is inserted by delimitMate,
but when a pair of delimiters is typed, the cursor is placed in the middle.
When the cursor is inside an empty pair or located next to the left of a
closing delimiter, the cursor is placed outside the pair to the right of the
closing delimiter.
Unless |'delimitMate_matchpairs'| or |'delimitMate_quotes'|are set, this
script uses the values in '&matchpairs' to identify the pairs, and ", ' and `
for quotes respectively.
The following table shows the behaviour, this applies to quotes too (the final
position of the cursor is represented by a "|"):
With auto-close: >
Type | You get
====================
( | (|)
|
() | ()|
|
(<S-Tab> | ()|
<
Without auto-close: >
Type | You get
=====================
() | (|)
-|
()) | ()|
-|
()<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.
------------------------------------------------------------------------------
3.2 EXPANSION OF SPACE AND CAR RETURN *delimitMateExpansion*
When the cursor is inside an empty pair of delimiters, <Space> and <CR> can be
expanded, see |'delimitMate_expand_space'| and
|'delimitMate_expand_cr'|:
Expand <Space> to: >
<Space><Space><Left> | You get
====================================
(|) | ( | )
<
Expand <CR> to: >
<CR><CR><Up> | You get
============================
(|) | (
| |
| )
<
NOTE that the expansion of <CR> will brake the redo command.
Since <Space> and <CR> 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.
------------------------------------------------------------------------------
3.3 BACKSPACE *delimitMateBackspace*
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 <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 "|": >
What | Before | After
==============================================
<BS> | call expand(|) | call expand|
---------|-------------------|-----------------
<BS> | call expand( | ) | call expand(|)
---------|-------------------|-----------------
<BS> | call expand( | call expand(|)
| | |
| ) |
---------|-------------------|-----------------
<S-BS> | call expand(|) | call expand(|
<
------------------------------------------------------------------------------
3.4 SMART QUOTES *delimitMateSmartQuotes*
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 "|": >
What | Before | After
=======================================
" | Text | | Text "|"
" | "String| | "String"|
" | let i = "| | let i = "|"
'm | I| | I'm|
<
------------------------------------------------------------------------------
3.5 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
=======================================
( | |) | (|)
( | | | (|)
( | (|) | ((|))
<
------------------------------------------------------------------------------
3.6 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
options for specific file types (see |'filetype'|) using buffer variables in
the following way: >
au FileType mail,text let b:delimitMate_autoclose = 0
^ ^ ^ ^ ^
| | | | |
| | | | - Option value.
| | | - Option name.
| | - Buffer variable.
| - File types for which the option will be set.
- Don't forget to put this event.
<
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.
------------------------------------------------------------------------------
3.7 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
edited and if it detects that the cursor is in a comment it'll turn itself off
until the cursor leaves the comment. The excluded regions can be set using the
option |'delimitMate_excluded_regions'|. Read |group-name| for a list of
regions or syntax group names.
NOTE that this feature relies on a proper syntax file for the current file
type, if the appropiate syntax file doesn't define a region, delimitMate won't
know about it.
==============================================================================
4. COMMANDS *delimitMateCommands*
------------------------------------------------------------------------------
:DelimitMateReload *:DelimitMateReload*
Re-sets all the mappings used for this script, use it if any option has been
changed or if the filetype option hasn't been set yet.
------------------------------------------------------------------------------
:DelimitMateSwitch *:DelimitMateSwitch*
Switches the plug-in on and off.
------------------------------------------------------------------------------
:DelimitMateTest *:DelimitMateTest*
This command tests every mapping set-up for this script, useful for testing
custom configurations.
The following output corresponds to the default values, it will be different
depending on your configuration. "Open & close:" represents the final result
when the closing delimiter has been inserted, either manually or
automatically, see |delimitMateExpansion|. "Delete:" typing backspace in an
empty pair, see |delimitMateBackspace|. "Exit:" typing a closing delimiter
inside a pair of delimiters, see |delimitMateAutoclose|. "Space:" the
expansion, if any, of space, see |delimitMateExpansion|. "Visual-L",
"Visual-R" and "Visual" shows visual wrapping, see
|delimitMateVisualWrapping|. "Car return:" the expansion of car return, see
|delimitMateExpansion|. The cursor's position at the end of every test is
represented by an "|": >
* AUTOCLOSE:
Open & close: (|)
Delete: |
Exit: ()|
Space: ( |)
Visual-L: (v)
Visual-R: (v)
Car return: (
|)
Open & close: {|}
Delete: |
Exit: {}|
Space: { |}
Visual-L: {v}
Visual-R: {v}
Car return: {
|}
Open & close: [|]
Delete: |
Exit: []|
Space: [ |]
Visual-L: [v]
Visual-R: [v]
Car return: [
|]
Open & close: "|"
Delete: |
Exit: ""|
Space: " |"
Visual: "v"
Car return: "
|"
Open & close: '|'
Delete: |
Exit: ''|
Space: ' |'
Visual: 'v'
Car return: '
|'
Open & close: `|`
Delete: |
Exit: ``|
Space: ` |`
Visual: `v`
Car return: `
|`
<
==============================================================================
5. MAPPINGS *delimitMateMappings*
delimitMate doesn't override any existing map, so you may encounter that it
doesn't work as expected because a mapping is missing. In that case, the
conflicting mappings should be resolved by either disabling the conflicting
mapping or creating a custom mappings.
In order to make custom mappings easier and prevent overwritting existing
ones, delimitMate uses the |<Plug>| + |hasmapto()| (|usr_41.txt|) construct
for its mappings.
The following are the mappings alway set by delimitMate:
<BS> is mapped to <Plug>delimitMateBS
<S-BS> is mapped to <Plug>delimitMateS-BS
<S-Tab> is mapped to <Plug>delimitMateS-Tab
<Del> is mapped to <Plug>delimitMateDel
<Esc> is mapped to <Plug>delimitMateEsc
<Left> is mapped to <Plug>delimitMateLeft
<Right> is mapped to <Plug>delimitMateRight
<Home> is mapped to <Plug>delimitMateHome
<End> is mapped to <Plug>delimitMateEnd
<Up> is mapped to <Plug>delimitMateUp
<Down> is mapped to <Plug>delimitMateDown
<PageUp> is mapped to <Plug>delimitMatePageUp
<PageDown> is mapped to <Plug>delimitMatePageDown
<S-Down> is mapped to <Plug>delimitMateS-Down
<S-Up> is mapped to <Plug>delimitMateS-Up
<LeftMouse> is mapped to <Plug>delimitMateMLeftMouse
<RightMouse> is mapped to <Plug>delimitMateMRightMouse
The rest of the mappings correspond to parens, quotes, CR, Space, etc. and they
depend on the values of the delimitMate options, they have the following form:
<Plug>delimitMate + char
e.g.: for "(":
( is mapped to <Plug>delimitMate(
e.g.: If you have <CR> expansion enabled, you might want to skip it on pop-up
menus:
imap <expr> <CR> pumvisible() ?
\"\<c-y>" :
\ "<Plug>delimitMateCR"
==============================================================================
6. FUNCTIONS *delimitMateFunctions*
------------------------------------------------------------------------------
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#ShouldJump() *delimitMate#ShouldJump()*
Returns 1 if there is a closing delimiter or a quote to the right of the
cursor, 0 otherwise.
------------------------------------------------------------------------------
delimitMate#JumpAny(key) *delimitMate#JumpAny()*
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("\<C-Tab>")<CR>
<
==============================================================================
7. TODO LIST *delimitMateTodo*
- Automatic set-up by file type.
- Make block-wise visual wrapping work on un-even regions.
==============================================================================
8. MAINTAINER *delimitMateMaintainer*
Hi there! My name is Israel Chauca F. and I can be reached at:
mailto:israelchauca@gmail.com
Feel free to send me any suggestions and/or comments about this plugin, I'll
be very pleased to read them.
==============================================================================
9. CREDITS *delimitMateCredits*
Some of the code that make this script is modified or just shamelessly copied
from the following sources:
- Ian McCracken
Post titled: Vim, Part II: Matching Pairs:
http://concisionandconcinnity.blogspot.com/
- Aristotle Pagaltzis
From the comments on the previous blog post and from:
http://gist.github.com/144619
- Karl Guertin
AutoClose:
http://www.vim.org/scripts/script.php?script_id=1849
- 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.
==============================================================================
10. HISTORY *delimitMateHistory*
Version Date Release notes ~
|---------|------------|-----------------------------------------------------|
2.5.1 2010-09-30 * Current release:
- Remove visual wrapping. Surround.vim offers a much
better implementation.
- Minor mods to DelimitMateTest.
|---------|------------|-----------------------------------------------------|
2.5 2010-09-22 * - Better handling of mappings.
- Add report for mappings in |:DelimitMateTest|.
- Allow the use of "|" and multi-byte characters in
|'delimitMate_quotes'| and |'delimitMate_matchpairs'|.
- Allow commands to be concatenated using |.
|---------|------------|-----------------------------------------------------|
2.4.1 2010-07-31 * - 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.
- A single quote typed after an alphanumeric
character is considered an apostrophe and one
single quote is inserted.
- A quote typed after another quote inserts a single
quote and the cursor jumps to the middle.
- <S-Tab> jumps out of any empty pair.
- <CR> and <Space> expansions are fixed, but the
functions used for it are global and can be used in
custom mappings. The previous system is still
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.
|---------|------------|-----------------------------------------------------|
1.6 2009-10-10 * Now delimitMate tries to fix the balancing of single
quotes when used as apostrophes. You can read
|delimitMate_apostrophes| for details.
Fixed an error when |b:delimitMate_expand_space|
wasn't set but |delimitMate_expand_space| wasn't.
|---------|------------|-----------------------------------------------------|
1.5 2009-10-05 * Fix: delimitMate should work correctly for files
passed as arguments to Vim. Thanks to Ben Beuchler
for helping to nail this bug.
|---------|------------|-----------------------------------------------------|
1.4 2009-09-27 * Fix: delimitMate is now enabled on new buffers even
if they don't have set the file type option or were
opened directly from the terminal.
|---------|------------|-----------------------------------------------------|
1.3 2009-09-24 * Now local options can be used along with autocmd
for specific file type configurations.
Fixes:
- Unnamed register content is not lost on visual
mode.
- Use noremap where appropiate.
- Wrapping a single empty line works as expected.
|---------|------------|-----------------------------------------------------|
1.2 2009-09-07 * Fixes:
- When inside nested empty pairs, deleting the
innermost left delimiter would delete all right
contiguous delimiters.
- When inside an empty pair, inserting a left
delimiter wouldn't insert the right one, instead
the cursor would jump to the right.
- New buffer inside the current window wouldn't
have the mappings set.
|---------|------------|-----------------------------------------------------|
1.1 2009-08-25 * Fixed an error that ocurred when mapleader wasn't
set and added support for GetLatestScripts
auto-detection.
|---------|------------|-----------------------------------------------------|
1.0 2009-08-23 * Initial upload.
|---------|------------|-----------------------------------------------------|
`\|||/´ MMM \|/ www __^__ ~
(o o) (o o) @ @ (O-O) /(o o)\\ ~
ooO_(_)_Ooo__ ooO_(_)_Ooo___oOO_(_)_OOo___oOO__(_)__OOo___oOO__(_)__OOo_____ ~
_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|____ ~
__|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_ ~
_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|____ ~
vim:tw=78:et:ts=2:sw=2:ft=help:norl:formatoptions+=tcroqn:autoindent:

6
README.md Normal file
View File

@@ -0,0 +1,6 @@
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, like syntax awareness (will not insert the closing delimiter
in comments and other configurable regions), <CR> and <Space> expansions (off by default), and some more.
Most of the features can be modified or disabled permanently, using global variables, or on a FileType basis, using
:autocmd.

View File

@@ -1,96 +1,148 @@
" ============================================================================
" File: autoload/delimitMate.vim
" Version: 2.5.1
" Modified: 2010-09-30
" Version: 2.7
" Modified: 2013-07-15
" Description: This plugin provides auto-completion for quotes, parens, etc.
" Maintainer: Israel Chauca F. <israelchauca@gmail.com>
" Manual: Read ":help delimitMate".
" ============================================================================
" Utilities {{{
"let delimitMate_loaded = 1
let delimitMate_loaded = 1
if !exists('s:options')
let s:options = {}
endif
function! delimitMate#ShouldJump() "{{{
function! s:set(name, value) "{{{
let bufnr = bufnr('%')
if !has_key(s:options, bufnr)
let s:options[bufnr] = {}
endif
let s:options[bufnr][a:name] = a:value
endfunction "}}}
function! s:get(...) "{{{
let options = deepcopy(eval('s:options.' . bufnr('%')))
if a:0
return options[a:1]
endif
return options
endfunction "}}}
function! s:exists(name, ...) "{{{
let scope = a:0 ? a:1 : 's'
if scope == 's'
let bufnr = bufnr('%')
let name = 'options.' . bufnr . '.' . a:name
else
let name = 'delimitMate_' . a:name
endif
return exists(scope . ':' . name)
endfunction "}}}
function! s:is_jump(...) "{{{
" Returns 1 if the next character is a closing delimiter.
let col = col('.')
let lcol = col('$')
let char = getline('.')[col - 1]
let char = s:get_char(0)
let list = s:get('right_delims') + s:get('quotes_list')
" Closing delimiter on the right.
for cdel in b:_l_delimitMate_right_delims + b:_l_delimitMate_quotes_list
if char == cdel
if (!a:0 && index(list, char) > -1)
\ || (a:0 && char == a:1)
return 1
endif
endfor
" Closing delimiter with space expansion.
let nchar = getline('.')[col]
if b:_l_delimitMate_expand_space && char == " "
for cdel in b:_l_delimitMate_right_delims + b:_l_delimitMate_quotes_list
if nchar == cdel
return 1
let nchar = s:get_char(1)
if !a:0 && s:get('expand_space') && char == " "
if index(list, nchar) > -1
return 2
endif
endfor
elseif a:0 && s:get('expand_space') && nchar == a:1 && char == ' '
return 3
endif
if !s:get('jump_expansion')
return 0
endif
" Closing delimiter with CR expansion.
let uchar = getline(line('.') + 1)[0]
if b:_l_delimitMate_expand_cr && char == ""
for cdel in b:_l_delimitMate_right_delims + b:_l_delimitMate_quotes_list
if uchar == cdel
return 1
let uchar = matchstr(getline(line('.') + 1), '^\s*\zs\S')
if !a:0 && s:get('expand_cr') && char == ""
if index(list, uchar) > -1
return 4
endif
endfor
elseif a:0 && s:get('expand_cr') && uchar == a:1
return 5
endif
return 0
endfunction "}}}
function! delimitMate#IsEmptyPair(str) "{{{
for pair in b:_l_delimitMate_matchpairs_list
if a:str == join( split( pair, ':' ),'' )
return 1
endif
endfor
for quote in b:_l_delimitMate_quotes_list
if a:str == quote . quote
return 1
endif
endfor
return 0
function! s:rquote(char) "{{{
let pos = matchstr(getline('.')[col('.') : ], escape(a:char, '[]*.^$\'), 1)
let i = 0
while s:get_char(i) ==# a:char
let i += 1
endwhile
return i
endfunction "}}}
function! delimitMate#IsCRExpansion() " {{{
function! s:lquote(char) "{{{
let i = 0
while s:get_char(i - 1) ==# a:char
let i -= 1
endwhile
return i * -1
endfunction "}}}
function! s:get_char(...) "{{{
let idx = col('.') - 1
if !a:0 || (a:0 && a:1 >= 0)
" Get char from cursor.
let line = getline('.')[idx :]
let pos = a:0 ? a:1 : 0
return matchstr(line, '^'.repeat('.', pos).'\zs.')
endif
" Get char behind cursor.
let line = getline('.')[: idx - 1]
let pos = 0 - (1 + a:1)
return matchstr(line, '.\ze'.repeat('.', pos).'$')
endfunction "s:get_char }}}
function! s:is_cr_expansion(...) " {{{
let nchar = getline(line('.')-1)[-1:]
let schar = getline(line('.')+1)[:0]
let isEmpty = getline('.') == ""
if index(b:_l_delimitMate_left_delims, nchar) > -1 &&
\ index(b:_l_delimitMate_left_delims, nchar) == index(b:_l_delimitMate_right_delims, schar) &&
\ isEmpty
let schar = matchstr(getline(line('.')+1), '^\s*\zs\S')
let isEmpty = a:0 ? getline('.') =~ '^\s*$' : empty(getline('.'))
if index(s:get('left_delims'), nchar) > -1
\ && index(s:get('left_delims'), nchar)
\ == index(s:get('right_delims'), schar)
\ && isEmpty
return 1
elseif index(b:_l_delimitMate_quotes_list, nchar) > -1 &&
\ index(b:_l_delimitMate_quotes_list, nchar) == index(b:_l_delimitMate_quotes_list, schar) &&
\ isEmpty
elseif index(s:get('quotes_list'), nchar) > -1
\ && index(s:get('quotes_list'), nchar)
\ == index(s:get('quotes_list'), schar)
\ && isEmpty
return 1
else
return 0
endif
endfunction " }}} delimitMate#IsCRExpansion()
endfunction " }}} s:is_cr_expansion()
function! delimitMate#IsSpaceExpansion() " {{{
let line = getline('.')
let col = col('.')-2
if col > 0
let pchar = line[col - 1]
let nchar = line[col + 2]
let isSpaces = (line[col] == line[col+1] && line[col] == " ")
function! s:is_space_expansion() " {{{
if col('.') > 2
let pchar = s:get_char(-2)
let nchar = s:get_char(1)
let isSpaces =
\ (s:get_char(-1)
\ == s:get_char(0)
\ && s:get_char(-1) == " ")
if index(b:_l_delimitMate_left_delims, pchar) > -1 &&
\ index(b:_l_delimitMate_left_delims, pchar) == index(b:_l_delimitMate_right_delims, nchar) &&
if index(s:get('left_delims'), pchar) > -1 &&
\ index(s:get('left_delims'), pchar)
\ == index(s:get('right_delims'), nchar) &&
\ isSpaces
return 1
elseif index(b:_l_delimitMate_quotes_list, pchar) > -1 &&
\ index(b:_l_delimitMate_quotes_list, pchar) == index(b:_l_delimitMate_quotes_list, nchar) &&
elseif index(s:get('quotes_list'), pchar) > -1 &&
\ index(s:get('quotes_list'), pchar)
\ == index(s:get('quotes_list'), nchar) &&
\ isSpaces
return 1
endif
@@ -98,89 +150,69 @@ function! delimitMate#IsSpaceExpansion() " {{{
return 0
endfunction " }}} IsSpaceExpansion()
function! delimitMate#WithinEmptyPair() "{{{
let cur = strpart( getline('.'), col('.')-2, 2 )
return delimitMate#IsEmptyPair( cur )
endfunction "}}}
function! delimitMate#WriteBefore(str) "{{{
let len = len(a:str)
let line = getline('.')
let col = col('.')-2
if col < 0
call setline('.',line[(col+len+1):])
else
call setline('.',line[:(col)].line[(col+len+1):])
function! s:is_empty_matchpair() "{{{
" get char before the cursor.
let open = s:get_char(-1)
let idx = index(s:get('left_delims'), open)
if idx == -1
return 0
endif
return a:str
let close = get(s:get('right_delims'), idx, '')
return close ==# s:get_char(0)
endfunction "}}}
function! delimitMate#WriteAfter(str) "{{{
let len = len(a:str)
let line = getline('.')
let col = col('.')-2
if (col) < 0
call setline('.',a:str.line)
else
call setline('.',line[:(col)].a:str.line[(col+len):])
function! s:is_empty_quotes() "{{{
" get char before the cursor.
let quote = s:get_char(-1)
let idx = index(s:get('quotes_list'), quote)
if idx == -1
return 0
endif
return ''
return quote ==# s:get_char(0)
endfunction "}}}
function! delimitMate#GetSyntaxRegion(line, col) "{{{
return synIDattr(synIDtrans(synID(a:line, a:col, 1)), 'name')
endfunction " }}}
function! s:cursor_idx() "{{{
let idx = len(split(getline('.')[: col('.') - 1], '\zs')) - 1
return idx
endfunction "delimitMate#CursorCol }}}
function! delimitMate#GetCurrentSyntaxRegion() "{{{
function! s:get_syn_name() "{{{
let col = col('.')
if col == col('$')
let col = col - 1
endif
return delimitMate#GetSyntaxRegion(line('.'), col)
return synIDattr(synIDtrans(synID(line('.'), col, 1)), 'name')
endfunction " }}}
function! delimitMate#GetCurrentSyntaxRegionIf(char) "{{{
let col = col('.')
let origin_line = getline('.')
let changed_line = strpart(origin_line, 0, col - 1) . a:char . strpart(origin_line, col - 1)
call setline('.', changed_line)
let region = delimitMate#GetSyntaxRegion(line('.'), col)
call setline('.', origin_line)
return region
endfunction "}}}
function! delimitMate#IsForbidden(char) "{{{
if b:_l_delimitMate_excluded_regions_enabled == 0
function! s:is_excluded_ft(ft) "{{{
if !exists("g:delimitMate_excluded_ft")
return 0
endif
"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 index(split(g:delimitMate_excluded_ft, ','), a:ft, 0, 1) >= 0
endfunction "}}}
function! s:is_forbidden(char) "{{{
if s:is_excluded_ft(&filetype)
return 1
endif
let region = delimitMate#GetCurrentSyntaxRegionIf(a:char)
"let result = index(b:_l_delimitMate_excluded_regions_list, region) >= 0
"return result || region == 'Comment'
"echom "Forbidden 2!"
return index(b:_l_delimitMate_excluded_regions_list, region) >= 0
if !s:get('excluded_regions_enabled')
return 0
endif
let region = s:get_syn_name()
return index(s:get('excluded_regions_list'), region) >= 0
endfunction "}}}
function! delimitMate#FlushBuffer() " {{{
let b:_l_delimitMate_buffer = []
return ''
endfunction " }}}
function! delimitMate#BalancedParens(char) "{{{
function! s:balance_matchpairs(char) "{{{
" Returns:
" = 0 => Parens balanced.
" > 0 => More opening parens.
" < 0 => More closing parens.
let line = getline('.')
let col = col('.') - 2
let col = s:cursor_idx() - 1
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 left = s:get('left_delims')[index(s:get('right_delims'), a:char)]
let right = a:char
let opening = 0
let closing = 0
@@ -203,32 +235,78 @@ function! delimitMate#BalancedParens(char) "{{{
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 "}}}
" }}}
function! s:is_smart_quote(char) "{{{
" TODO: Allow using a:char in the pattern.
let tmp = s:get('smart_quotes')
if empty(tmp)
return 0
endif
let regex = matchstr(tmp, '^!\?\zs.*')
" Flip matched value if regex starts with !
let mod = tmp =~ '^!' ? [1, 0] : [0, 1]
let matched = search(regex, 'ncb', line('.')) > 0
let noescaped = substitute(getline('.'), '\\.', '', 'g')
let odd = (count(split(noescaped, '\zs'), a:char) % 2)
let result = mod[matched] || odd
return result
endfunction "delimitMate#SmartQuote }}}
function! delimitMate#Set(...) "{{{
return call('s:set', a:000)
endfunction "}}}
function! delimitMate#Get(...) "{{{
return call('s:get', a:000)
endfunction "}}}
function! delimitMate#ShouldJump(...) "{{{
return call('s:is_jump', a:000)
endfunction "}}}
function! delimitMate#IsEmptyPair(str) "{{{
if strlen(substitute(a:str, ".", "x", "g")) != 2
return 0
endif
let idx = index(s:get('left_delims'), matchstr(a:str, '^.'))
if idx > -1 &&
\ s:get('right_delims')[idx] == matchstr(a:str, '.$')
return 1
endif
let idx = index(s:get('quotes_list'), matchstr(a:str, '^.'))
if idx > -1 &&
\ s:get('quotes_list')[idx] == matchstr(a:str, '.$')
return 1
endif
return 0
endfunction "}}}
function! delimitMate#WithinEmptyPair() "{{{
" if cursor is at column 1 return 0
if col('.') == 1
return 0
endif
" get char before the cursor.
let char1 = s:get_char(-1)
" get char under the cursor.
let char2 = s:get_char(0)
return delimitMate#IsEmptyPair( char1.char2 )
endfunction "}}}
" Doers {{{
function! delimitMate#SkipDelim(char) "{{{
if delimitMate#IsForbidden(a:char)
if s:is_forbidden(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]
let cur = s:get_char(0)
let pre = s:get_char(-1)
else
let cur = line[col]
let cur = s:get_char(0)
let pre = ""
endif
if pre == "\\"
@@ -236,300 +314,346 @@ function! delimitMate#SkipDelim(char) "{{{
return a:char
elseif cur == a:char
" Exit pair
"return delimitMate#WriteBefore(a:char)
return a:char . delimitMate#Del()
return a:char . "\<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)
return a:char . s:joinUndo() . "\<Left>"
else
" Nothing special here, return the same character.
return a:char
endif
endfunction "}}}
function! delimitMate#ParenDelim(char) " {{{
if delimitMate#IsForbidden(a:char)
return ''
function! delimitMate#ParenDelim(right) " {{{
let left = s:get('left_delims')[index(s:get('right_delims'),a:right)]
if s:is_forbidden(a:right)
return left
endif
if b:_l_delimitMate_balance_matchpairs &&
\ delimitMate#BalancedParens(a:char) <= 0
return ''
" Try to balance matchpairs
if s:get('balance_matchpairs') &&
\ s:balance_matchpairs(a:right) < 0
return left
endif
let line = getline('.')
let col = col('.')-2
if (col) < 0
call setline('.',a:char.line)
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:_l_delimitMate_buffer, a:char)
if s:get('smart_matchpairs') != ''
let smart_matchpairs = substitute(s:get('smart_matchpairs'), '\\!', left, 'g')
let smart_matchpairs = substitute(smart_matchpairs, '\\#', a:right, 'g')
if line[col+1:] =~ smart_matchpairs
return left
endif
return ''
endif
if len(line) == (col + 1) && s:get('insert_eol_marker') == 1
let tail = s:get('eol_marker')
else
let tail = ''
endif
return left . a:right . tail . repeat(s:joinUndo() . "\<Left>", len(split(tail, '\zs')) + 1)
endfunction " }}}
function! delimitMate#QuoteDelim(char) "{{{
if delimitMate#IsForbidden(a:char)
if s:is_forbidden(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.
let char_at = s:get_char(0)
let char_before = s:get_char(-1)
let nesting_on = index(s:get('nesting_quotes'), a:char) > -1
let left_q = nesting_on ? s:lquote(a:char) : 0
if nesting_on && left_q > 1
" Nesting quotes.
let right_q = s:rquote(a:char)
let quotes = right_q > left_q + 1 ? 0 : left_q - right_q + 2
let lefts = quotes - 1
return repeat(a:char, quotes) . repeat(s:joinUndo() . "\<Left>", lefts)
elseif char_at == a:char
" Inside an empty pair, jump out
return a:char . "\<Del>"
elseif a:char == '"' && index(split(&ft, '\.'), "vim") != -1 && getline('.') =~ '^\s*$'
" If we are in a vim file and it looks like we're starting a comment, do
" not add a closing char.
return a:char
elseif 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.
elseif a:char == "'" && index(split(&ft, '\.'), "clojure") != -1
" If we are in a clojure file, do not add a closing apostrophe.
return a:char
elseif (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)
elseif s:is_smart_quote(a:char)
" Seems like a smart quote, insert a single char.
return a:char
elseif (char_before == a:char && char_at != a:char)
\ && !empty(s:get('smart_quotes'))
" Seems like we have an unbalanced quote, insert one quotation
" mark and jump to the middle.
return a:char . s:joinUndo() . "\<Left>"
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
let sufix = ''
if !empty(s:get('eol_marker')) && col('.') - 1 == len(getline('.'))
let idx = len(s:get('eol_marker')) * -1
let marker = getline('.')[idx : ]
let has_marker = marker == s:get('eol_marker')
let sufix = !has_marker ? s:get('eol_marker') : ''
endif
return a:char . a:char . s:joinUndo() . "\<Left>"
endif
endfunction "}}}
function! delimitMate#JumpOut(char) "{{{
if delimitMate#IsForbidden(a:char)
if s:is_forbidden(a:char)
return a:char
endif
let line = getline('.')
let col = col('.')-2
if line[col+1] == a:char
return a:char . delimitMate#Del()
let jump = s:is_jump(a:char)
if jump == 1
" HACK: Instead of <Right>, we remove the char to be jumped over and
" insert it again. This will trigger re-indenting via 'indentkeys'.
" Ref: https://github.com/Raimondi/delimitMate/issues/168
return "\<Del>".a:char
elseif jump == 3
return s:joinUndo() . "\<Right>" . s:joinUndo() . "\<Right>"
elseif jump == 5
return "\<Down>\<C-O>I" . s:joinUndo() . "\<Right>"
else
return a:char
endif
endfunction " }}}
function! delimitMate#JumpAny(key) " {{{
if delimitMate#IsForbidden('')
return a:key
function! delimitMate#JumpAny(...) " {{{
if s:is_forbidden('')
return ''
endif
if !delimitMate#ShouldJump()
return a:key
if !s:is_jump()
return ''
endif
" Let's get the character on the right.
let char = getline('.')[col('.')-1]
let char = s:get_char(0)
if char == " "
" Space expansion.
"let char = char . getline('.')[col('.')] . delimitMate#Del()
return char . getline('.')[col('.')] . delimitMate#Del() . delimitMate#Del()
"call delimitMate#RmBuffer(1)
return s:joinUndo() . "\<Right>" . s:joinUndo() . "\<Right>"
elseif char == ""
" CR expansion.
"let char = "\<CR>" . getline(line('.') + 1)[0] . "\<Del>"
let b:_l_delimitMate_buffer = []
return "\<CR>" . getline(line('.') + 1)[0] . "\<Del>"
return "\<CR>" . getline(line('.') + 1)[0] . "\<Del>\<Del>"
else
"call delimitMate#RmBuffer(1)
return char . delimitMate#Del()
return s:joinUndo() . "\<Right>"
endif
endfunction " delimitMate#JumpAny() }}}
function! delimitMate#MapMsg(msg) "{{{
redraw
echomsg a:msg
return ""
endfunction "}}}
function! delimitMate#JumpMany() " {{{
let line = split(getline('.')[col('.') - 1 : ], '\zs')
let rights = ""
let found = 0
for char in line
if index(s:get('quotes_list'), char) >= 0 ||
\ index(s:get('right_delims'), char) >= 0
let rights .= s:joinUndo() . "\<Right>"
let found = 1
elseif found == 0
let rights .= s:joinUndo() . "\<Right>"
else
break
endif
endfor
if found == 1
return rights
else
return ''
endif
endfunction " delimitMate#JumpMany() }}}
function! delimitMate#ExpandReturn() "{{{
if delimitMate#IsForbidden("")
if s:is_forbidden("")
return "\<CR>"
endif
if delimitMate#WithinEmptyPair()
let escaped = s:cursor_idx() >= 2
\ && s:get_char(-2) == '\'
let expand_right_matchpair = s:get('expand_cr') == 2
\ && index(s:get('right_delims'), s:get_char(0)) > -1
let expand_inside_quotes = s:get('expand_inside_quotes')
\ && s:is_empty_quotes()
\ && !escaped
let is_empty_matchpair = s:is_empty_matchpair()
if !pumvisible( )
\ && ( is_empty_matchpair
\ || expand_right_matchpair
\ || expand_inside_quotes)
let val = "\<Esc>a"
if is_empty_matchpair && s:get('insert_eol_marker') == 2
\ && !search(escape(s:get('eol_marker'), '[]\.*^$').'$', 'cnW', '.')
let tail = getline('.')[col('.') - 1 : ]
let times = len(split(tail, '\zs'))
let val .= repeat(s:joinUndo() . "\<Right>", times) . s:get('eol_marker') . repeat(s:joinUndo() . "\<Left>", times + 1)
endif
let val .= "\<CR>"
if &smartindent && !&cindent && !&indentexpr
\ && s:get_char(0) == '}'
" indentation is controlled by 'smartindent', and the first character on
" the new line is '}'. If this were typed manually it would reindent to
" match the current line. Let's reproduce that behavior.
let sw = &sw == 0 ? &ts : &sw
let shifts = indent('.') / sw
let spaces = indent('.') - (shifts * sw)
let val .= "^\<C-D>".repeat("\<C-T>", shifts).repeat(' ', spaces)
endif
" Expand:
call delimitMate#FlushBuffer()
"return "\<Esc>a\<CR>x\<CR>\<Esc>k$\"_xa"
return "\<CR>\<UP>\<Esc>o"
" XXX zv prevents breaking expansion with syntax folding enabled by
" InsertLeave.
let val .= "\<Esc>zvO"
return val
else
return "\<CR>"
endif
endfunction "}}}
function! delimitMate#ExpandSpace() "{{{
if delimitMate#IsForbidden("\<Space>")
if s:is_forbidden("\<Space>")
return "\<Space>"
endif
if delimitMate#WithinEmptyPair()
let escaped = s:cursor_idx() >= 2
\ && s:get_char(-2) == '\'
let expand_inside_quotes = s:get('expand_inside_quotes')
\ && s:is_empty_quotes()
\ && !escaped
if s:is_empty_matchpair() || expand_inside_quotes
" Expand:
call insert(b:_l_delimitMate_buffer, 's')
return delimitMate#WriteAfter(' ') . "\<Space>"
return "\<Space>\<Space>" . s:joinUndo() . "\<Left>"
else
return "\<Space>"
endif
endfunction "}}}
function! delimitMate#BS() " {{{
if delimitMate#IsForbidden("")
return "\<BS>"
endif
if delimitMate#WithinEmptyPair()
"call delimitMate#RmBuffer(1)
return "\<BS>" . delimitMate#Del()
" return "\<Right>\<BS>\<BS>"
elseif delimitMate#IsSpaceExpansion()
"call delimitMate#RmBuffer(1)
return "\<BS>" . delimitMate#Del()
elseif delimitMate#IsCRExpansion()
return "\<BS>\<Del>"
if s:is_forbidden("")
let extra = ''
elseif &bs !~ 'start\|2'
let extra = ''
elseif delimitMate#WithinEmptyPair()
let extra = "\<Del>"
elseif s:is_space_expansion()
let extra = "\<Del>"
elseif s:is_cr_expansion()
let extra = repeat("\<Del>",
\ len(matchstr(getline(line('.') + 1), '^\s*\S')))
else
return "\<BS>"
let extra = ''
endif
return "\<BS>" . extra
endfunction " }}} delimitMate#BS()
function! delimitMate#Del() " {{{
if len(b:_l_delimitMate_buffer) > 0
let line = getline('.')
let col = col('.') - 2
call delimitMate#RmBuffer(1)
call setline('.', line[:col] . line[col+2:])
return ''
function! delimitMate#Test() "{{{
%d _
" Check for script options:
let result = [
\ 'delimitMate Report',
\ '==================',
\ '',
\ '* Options: ( ) default, (g) global, (b) buffer',
\ '']
for option in sort(keys(s:options[bufnr('%')]))
if s:exists(option, 'b')
let scope = '(b)'
elseif s:exists(option, 'g')
let scope = '(g)'
else
return "\<Del>"
let scope = '( )'
endif
endfunction " }}}
function! delimitMate#Finish() " {{{
let len = len(b:_l_delimitMate_buffer)
if len > 0
let buffer = join(b:_l_delimitMate_buffer, '')
let len2 = len(buffer)
" Reset buffer:
let b:_l_delimitMate_buffer = []
let line = getline('.')
let col = col('.') -2
"echom 'col: ' . col . '-' . line[:col] . "|" . line[col+len+1:] . '%' . buffer
if col < 0
call setline('.', line[col+len2+1:])
else
call setline('.', line[:col] . line[col+len2+1:])
endif
let i = 1
let lefts = "\<Left>"
while i < len
let lefts = lefts . "\<Left>"
let i += 1
endwhile
return substitute(buffer, "s", "\<Space>", 'g') . lefts
endif
return ''
endfunction " }}}
function! delimitMate#RmBuffer(num) " {{{
if len(b:_l_delimitMate_buffer) > 0
call remove(b:_l_delimitMate_buffer, 0, (a:num-1))
endif
return ""
endfunction " }}}
" }}}
" Tools: {{{
function! delimitMate#TestMappings() "{{{
let options = sort(keys(delimitMate#OptionsList()))
let optoutput = ['delimitMate Report', '==================', '', '* Options: (-) unset, (g) global, (b) buffer','']
for option in options
exec 'call add(optoutput, ''('.(exists('b:delimitMate_'.option) ? 'b' : exists('g:delimitMate_'.option) ? 'g' : '-').') delimitMate_''.option.'' = ''.string(b:_l_delimitMate_'.option.'))'
call add(result,
\ scope . ' delimitMate_' . option
\ . ' = '
\ . string(s:get(option)))
endfor
call append(line('$'), optoutput + ['--------------------',''])
call add(result, '')
" Check if mappings were set. {{{
let imaps = b:_l_delimitMate_right_delims
let imaps = imaps + ( b:_l_delimitMate_autoclose ? b:_l_delimitMate_left_delims : [] )
let imaps = imaps +
\ b:_l_delimitMate_quotes_list +
\ b:_l_delimitMate_apostrophes_list +
\ ['<BS>', '<S-BS>', '<Del>', '<S-Tab>', '<Esc>'] +
\ ['<Up>', '<Down>', '<Left>', '<Right>', '<LeftMouse>', '<RightMouse>'] +
\ ['<Home>', '<End>', '<PageUp>', '<PageDown>', '<S-Down>', '<S-Up>']
let imaps = imaps + ( b:_l_delimitMate_expand_cr ? ['<CR>'] : [] )
let imaps = imaps + ( b:_l_delimitMate_expand_space ? ['<Space>'] : [] )
let option = 'delimitMate_excluded_ft'
call add(result,
\(exists('g:'.option) ? '(g) ' : '( ) g:') . option . ' = '
\. string(get(g:, option, '')))
let vmaps =
\ b:_l_delimitMate_right_delims +
\ b:_l_delimitMate_left_delims +
\ b:_l_delimitMate_quotes_list
call add(result, '--------------------')
call add(result, '')
let ibroken = []
for map in imaps
if maparg(map, "i") !~? 'delimitMate'
" Check if mappings were set.
let left_delims = s:get('autoclose') ? s:get('left_delims') : []
let special_keys = ['<BS>', '<S-BS>', '<S-Tab>', '<C-G>g']
if s:get('expand_cr')
call add(special_keys, '<CR>')
endif
if s:get('expand_space')
call add(special_keys, '<Space>')
endif
let maps =
\ s:get('right_delims')
\ + left_delims
\ + s:get('quotes_list')
\ + s:get('apostrophes_list')
\ + special_keys
call add(result, '* Mappings:')
call add(result, '')
for map in maps
let output = ''
if map == '|'
let map = '<Bar>'
endif
redir => output | execute "verbose imap ".map | redir END
let ibroken = ibroken + [map.": is not set:"] + split(output, '\n')
endif
call extend(result, split(output, '\n'))
endfor
let ibroken = len(ibroken) > 0 ? ['IMAP'] + ibroken : []
unlet! output
if ibroken == []
let output = ['* Mappings:', '', 'All mappings were set-up.', '--------------------', '', '']
else
let output = ['* Mappings:', ''] + ibroken + ['--------------------', '']
endif
call append('$', output+['* Showcase:', ''])
" }}}
if b:_l_delimitMate_autoclose
" {{{
for i in range(len(b:_l_delimitMate_left_delims))
exec "normal GGoOpen: " . 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 oCar return: " . b:_l_delimitMate_left_delims[i] . "\<CR>|"
exec "normal GGoDelete car return: " . b:_l_delimitMate_left_delims[i] . "\<CR>\<BS>|\<Esc>GG\<Esc>o"
endfor
for i in range(len(b:_l_delimitMate_quotes_list))
exec "normal GGAOpen: " . b:_l_delimitMate_quotes_list[i] . "|"
exec "normal oDelete: " . b:_l_delimitMate_left_delims[i] . b:_l_delimitMate_right_delims[i] . "\<BS>|"
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 oCar return: " . b:_l_delimitMate_quotes_list[i] . "\<CR>|"
exec "normal GGoDelete car return: " . b:_l_delimitMate_quotes_list[i] . "\<CR>\<BS>|\<Esc>GG\<Esc>o"
endfor
"}}}
else
"{{{
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 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>GG\<Esc>o"
endfor
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 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>GG\<Esc>o"
endfor
endif "}}}
call add(result, '--------------------')
call add(result, '')
call add(result, '* Showcase:')
call add(result, '')
call setline(1, result)
call s:test_mappings(s:get('left_delims'), 1)
call s:test_mappings(s:get('quotes_list'), 0)
let result = []
redir => setoptions
echo " * Vim configuration:\<NL>"
filetype
echo ""
set
version
redir END
call extend(result, split(setoptions,"\n"))
call add(result, '--------------------')
setlocal nowrap
call append('$', result)
call feedkeys("\<Esc>\<Esc>", 'n')
endfunction "}}}
function! delimitMate#OptionsList() "{{{
return {'autoclose' : 1,'matchpairs': &matchpairs, 'quotes' : '" '' `', 'nesting_quotes' : [], 'expand_cr' : 0, 'expand_space' : 0, 'smart_quotes' : 1, 'balance_matchpairs' : 0, 'excluded_regions' : 'Comment', 'excluded_ft' : '', 'apostrophes' : ''}
endfunction " delimitMate#OptionsList }}}
"}}}
function! s:test_mappings(list, is_matchpair) "{{{
let prefix = "normal Go0\<C-D>"
let last = "|"
let open = s:get('autoclose') ? 'Open: ' : 'Open & close: '
for s in a:list
if a:is_matchpair
let pair = s:get('right_delims')[index(s:get('left_delims'), s)]
else
let pair = s
endif
if !s:get('autoclose')
let s .= pair
endif
exec prefix . open . s . last
exec prefix . "Delete: " . s . "\<BS>" . last
exec prefix . "Exit: " . s . pair . last
if s:get('expand_space')
\ && (a:is_matchpair || s:get('expand_inside_quotes'))
exec prefix . "Space: " . s . " " . last
exec prefix . "Delete space: " . s . " \<BS>" . last
endif
if s:get('expand_cr')
\ && (a:is_matchpair || s:get('expand_inside_quotes'))
exec prefix . "Car return: " . s . "\<CR>" . last
exec prefix . "Delete car return: " . s . "\<CR>0\<C-D>\<BS>" . last
endif
call append('$', '')
endfor
endfunction "}}}
" vim:foldmethod=marker:foldcolumn=4
function! s:joinUndo() "{{{
if v:version < 704
\ || ( v:version == 704 && !has('patch849') )
return ''
endif
return "\<C-G>U"
endfunction "}}}
" vim:foldmethod=marker:foldcolumn=4:ts=2:sw=2

View File

@@ -1,260 +0,0 @@
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
let b:ignores = 0
function! SetOptions(list) " {{{
let b:delimitMate_autoclose = 1
let b:delimitMate_matchpairs = &matchpairs
let b:delimitMate_quotes = "\" ' `"
let b:delimitMate_excluded_regions = "Comment"
let b:delimitMate_expand_space = 0
let b:delimitMate_expand_cr = 0
let b:delimitMate_smart_quotes = 1
let b:delimitMate_apostrophes = ""
let b:delimitMate_tab2exit = 1
" Set current test options:
for str in a:list
"echom '1:'.str
let op = strpart(str, 0, stridx(str,':'))
"echom op
let val = strpart(str, stridx(str, ':' ) + 1)
"echom val
exec "let b:delimitMate_" . op . " = " . val
endfor
DelimitMateReload
endfunction " }}}
function! Type(name, input, output, options, ...) " {{{
if a:0 > 0
let ignore = a:1
else
let ignore = 0
endif
if a:input != "\<Esc>."
" Set default options:
call SetOptions(a:options)
let CapR = ""
normal ggVG"_d
exec "normal i" . a:input . "|\<Esc>"
else
let CapR = "_R"
normal gg.
endif
exec "normal \<Esc>"
call setpos('.', [0, 1, 1, 0])
let result = len(a:output) != line('$')
for line in a:output
if getline('.') != line || result == 1
let result = 1
break
endif
call setpos('.', [0, line('.') + 1, 1, 0])
endfor
let text = getline('.')
let i = 2
while i <= line('$')
let text = text . "<cr>" . getline(i)
let i += 1
endwhile
if ignore == 1
let label = "Ignored"
let result = "?="
let b:ignores += 1
elseif result == 0
let label = "Passed"
let result = "=="
let b:corrects += 1
else
let label = "Failed"
let result = "!="
let b:errors += 1
endif
exec "let b:test_results['" .
\ substitute(a:name, "[^a-zA-Z0-9_]", "_", "g") . CapR . "'] = '" .
\ label . ": ' . a:input . ' => ' . text . ' " .
\ result . " ' . join(a:output, '<cr>')"
endfunction " }}}
function! RepeatLast(name, output, ...) " {{{
if a:0 > 0
let arg1 = a:1
else
let arg1 = ''
endif
call Type(a:name, "\<Esc>.", a:output, [], arg1)
endfunction " }}}
" Test's test {{{
call Type("Test 1", "123", ["123|"], [])
call RepeatLast("Test 1", ["123|123|"])
" Auto-closing parens
call Type("Autoclose parens", "(", ["(|)"], [])
call RepeatLast("Autoclose_parens", ["(|)(|)"])
" Auto-closing quotes
call Type("Autoclose quotes", '"', ['"|"'], [])
call RepeatLast("Autoclose_quotes", ['"|""|"'])
" Deleting parens
call Type("Delete empty parens", "(\<BS>", ["|"], [])
call RepeatLast("Delete empty parens", ["||"])
" Deleting quotes
call Type("Delete emtpy quotes", "\"\<BS>", ['|'], [])
call RepeatLast("Delete empty quotes", ["||"])
" Manual closing parens
call Type("Manual closing parens", "()", ["(|)"], ["autoclose:0"])
call RepeatLast("Manual closing parens", ["(|)(|)"])
" Manual closing quotes
call Type("Manual closing quotes", "\"\"", ['"|"'], ["autoclose:0"])
call RepeatLast("Manual closing quotes", ['"|""|"'])
" Jump over paren
call Type("Jump over paren", "()", ['()|'], [])
call RepeatLast("Jump over paren", ['()|()|'])
" Jump over quote
call Type("Jump over quote", "\"\"", ['""|'], [])
call RepeatLast("Jump over quote", ['""|""|'])
" Apostrophe
call Type("Apostrophe", "test'", ["test'|"], [])
call RepeatLast("Apostrophe", ["test'|test'|"])
" Close quote
call Type("Close quote", "'\<Del>\<Esc>a'", ["'|'"], [])
" Closing paren
call Type("Closing paren", "abcd)", ["abcd)|"], [])
" <S-Tab>
call Type("S Tab", "(\<S-Tab>", ["()|"], [])
call RepeatLast("S Tab", ["()|()|"])
" Space expansion
call Type("Space expansion", "(\<Space>\<BS>", ['(|)'], ['expand_space:1'])
call RepeatLast("BS with space expansion", ['(|)(|)'])
" BS with space expansion
call Type("BS with space expansion", "(\<Space>", ['( | )'], ['expand_space:1'])
call RepeatLast("Space expansion", ['( | )( | )'])
" Car return expansion
call Type("CR expansion", "(\<CR>", ['(', '|', ')'], ['expand_cr:1'])
call RepeatLast("CR expansion", ['(', '|', ')(', '|', ')'], 1)
" BS with car return expansion
call Type("BS with CR expansion", "(\<CR>\<BS>", ['(|)'], ['expand_cr:1'])
call RepeatLast("BS with CR expansion", ['(|)(|)'], 1)
" Smart quotes
call Type("Smart quote alphanumeric", "a\"4", ['a"4|'], [])
call RepeatLast("Smart quote alphanumeric", ['a"4|a"4|'])
" Smart quotes
call Type("Smart quote escaped", "esc\\\"", ['esc\"|'], [])
call RepeatLast("Smart quote escaped", ['esc\"|esc\"|'])
" Smart quotes
call Type("Smart quote apostrophe", "I'm", ["I'm|"], ['smart_quotes:0'])
call RepeatLast("Smart quote escaped", ["I'm|I'm|"])
" Backspace inside space expansion
call Type("Backspace inside space expansion", "(\<Space>\<BS>", ['(|)'], ['expand_space:1'])
call RepeatLast("Backspace inside space expansion", ['(|)(|)'])
" <Right-arrow> inserts text
call Type("<Right-arrow> inserts text", "(he\<Right>\<Space>th\<Right>\<Right>", ['(he) th|'], [])
" Backspace inside CR expansion
call Type("Backspace inside CR expansion", "(\<CR>\<BS>", ['(|)'], ['expand_cr:1'])
call RepeatLast("Backspace inside CR expansion", ['(|)(|)'], 1)
" FileType event
let g:delimitMate_excluded_ft = "vim"
set ft=vim
call Type("FileType Autoclose parens", "(", ["(|"], [])
unlet g:delimitMate_excluded_ft
set ft=
" Duplicated delimiter after CR
call Type("Duplicated delimiter after CR", "(\<CR>", ['(', '|)'], [])
" Deactivate on comments: The first call to a closing delimiter
" will not work here as expected, but it does in real life tests.
set ft=vim
call Type("Deactivate on comments", "\"()``[]''\"\"", ["\"()``[]''\"\"|"], ["autoclose:0"], 1)
set ft=
" Deactivate parens on comments: The first call to a closing delimiter
" will not work here as expected, but it does in real life tests.
set ft=vim
call Type("Deactivate parens on comments", "\"()[]", ["\"()[]|"], ["autoclose:0"], 1)
set ft=
" Deactivate quotes on comments: See previous note.
set ft=vim
call Type("Deactivate parens on comments", "\"(`", ["\"(``|"], [], 1)
set ft=
" Manual close at start of line
call Type("Manual close at start of line", "m)\<Left>\<Left>)", [')|m)'], ["autoclose:0"])
" Use | in quotes
call Type("Use <Bar> in quotes", "\<Bar>bars", ['|bars|'], ["quotes:'|'"])
" Use | in matchpairs
call Type("Use <Bar> in matchpairs", "\<Bar>bars", ['|bars|$$'], ["matchpairs:'|:$'"])
"}}}
" Show results: {{{
normal ggVG"_d
call append(0, split(string(b:test_results)[1:-2], ', '))
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
syn match lineIgnored ".*Ignored.*"
syn match labelPassed "'\@<=.\+\(': 'Passed\)\@="
syn match labelFailed "'\@<=.\+\(': 'Failed\)\@="
syn match resultPassed "\('Passed: \)\@<=.\+\('$\)\@="
syn match resultFailed "\('Failed: \)\@<=.\+\('$\)\@=" contains=resultInequal
syn match resultIgnored "\('Ignored: \)\@<=.\+\('$\)\@="
syn match resultInequal "!="
syn match resultSummary "^\*.\+" contains=resultSummaryNumber
syn match resultSummaryNumber "[1-9][0-9]* failed*" contained
hi def link lineIgnored Ignore
hi def link labelPassed Comment
hi def link labelFailed Special
hi def link resultPassed Ignore
hi def link resultFailed Boolean
hi def link resultInequal Error
hi def link resultSummary SpecialComment
hi def link resultSummaryNumber Error
" }}}
let &more = nomore
endfunction
" vim:foldmethod=marker:foldcolumn=4

4
basic_vimrc Normal file
View File

@@ -0,0 +1,4 @@
so ./test/_setup.vim
let delimitMate_expand_cr = 1
filetype indent plugin on

View File

@@ -1,4 +1,4 @@
*delimitMate.txt* Trying to keep those beasts at bay! v2.5.1 *delimitMate*
*delimitMate.txt* Trying to keep those beasts at bay! v2.7 *delimitMate*
@@ -34,10 +34,11 @@
4. Commands________________________________|delimitMateCommands|
5. Mappings________________________________|delimitMateMappings|
6. Functions_______________________________|delimitMateFunctions|
7. TODO list_______________________________|delimitMateTodo|
8. Maintainer______________________________|delimitMateMaintainer|
9. Credits_________________________________|delimitMateCredits|
10. History_________________________________|delimitMateHistory|
7. Autocommands____________________________|delimitMateAutocmds|
8. TODO list_______________________________|delimitMateTodo|
9. Maintainer______________________________|delimitMateMaintainer|
10. Credits_________________________________|delimitMateCredits|
11. History_________________________________|delimitMateHistory|
==============================================================================
1.- INTRODUCTION *delimitMateIntro*
@@ -47,16 +48,12 @@ etc.; besides some other related features that should make your time in insert
mode a little bit easier.
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.
variables, or on a FileType basis, using autocommands.
NOTE 1: If you have any trouble with this plugin, please run |:DelimitMateTest|
in a new buffer to see what is not working.
NOTE 2: |'timeout'| needs to be set when working in the terminal, otherwise you
might find weird behaviour with mappings including <Esc> or arrow keys.
NOTE 3: Abbreiations set with |:iabbrev| will not be expanded by delimiters
NOTE 2: Abbreviations set with |:iabbrev| will not be expanded by delimiters
used on delimitMate, you should use <C-]> (read |i_CTRL-]|) to expand them on
the go.
@@ -64,7 +61,7 @@ the go.
2. CUSTOMIZATION *delimitMateOptions*
You can create your own mappings for some features using the global functions.
Read |DelimitMateFunctions| for more info.
Read |delimitMateFunctions| for more info.
------------------------------------------------------------------------------
2.1 OPTIONS SUMMARY *delimitMateOptionSummary*
@@ -91,8 +88,12 @@ specific file types, see |delimitMateOptionDetails| for examples.
|'delimitMate_expand_space'| Turns on/off the expansion of <Space>.
|'delimitMate_jump_expansion'| Turns on/off jumping over expansions.
|'delimitMate_smart_quotes'| Turns on/off the "smart quotes" feature.
|'delimitMate_smart_matchpairs'| Turns on/off the "smart matchpairs" feature.
|'delimitMate_balance_matchpairs'|Turns on/off the "balance matching pairs"
feature.
@@ -101,6 +102,10 @@ specific file types, see |delimitMateOptionDetails| for examples.
|'delimitMate_excluded_ft'| Turns off the script for the given file types.
|'delimitMate_eol_marker'| Determines what to insert after the closing
matchpair when typing an opening matchpair on
the end of the line.
|'delimitMate_apostrophes'| Tells delimitMate how it should "fix"
balancing of single quotes when used as
apostrophes. NOTE: Not needed any more, kept
@@ -115,7 +120,7 @@ autocmd to modify delimitMate's behavior for specific file types, read more in
|delimitMateFileType|.
Note: Use buffer variables only to set options for specific file types using
:autocmd, use global variables to set options for every buffer. Read more in
:autocmd, use global variables to set options for all buffers. Read more in
|g:var| and |b:var|.
------------------------------------------------------------------------------
@@ -126,6 +131,15 @@ e.g.: >
let loaded_delimitMate = 1
au FileType mail let b:loaded_delimitMate = 1
<
------------------------------------------------------------------------------
*'delimitMate_offByDefault'*
Values: 0 or 1.~
Default: 0~
If this option is set to 1, delimitMate will load, but will not take
effect in any buffer unless |:DelimitMateSwitch| is called in that
buffer.
------------------------------------------------------------------------------
*'delimitMate_autoclose'*
*'b:delimitMate_autoclose'*
@@ -169,20 +183,25 @@ e.g.: >
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.
When adding a third quote listed in this option is inserted, three quotes will
be inserted to the right of the cursor and the cursor will stay in the middle.
If more quotes are inserted the number of quotes on both sides of the cursor
will stay balanced.
e.g.: >
let delimitMate_nesting_quotes = ['"','`']
au FileType python let b:delimitMate_nesting_quotes = ['"']
<
For Python this is set by default by the plugin.
------------------------------------------------------------------------------
*'delimitMate_expand_cr'*
*'b:delimitMate_expand_cr'*
Values: 1 or 0 ~
Values: 0, 1 or 2 ~
Default: 0 ~
This option turns on/off the expansion of <CR>. Read |delimitMateExpansion|
for details.
for details. NOTE This feature requires that 'backspace' is either set to 2 or
has "eol" and "start" as part of its value.
e.g.: >
let delimitMate_expand_cr = 1
au FileType mail let b:delimitMate_expand_cr = 1
@@ -192,24 +211,73 @@ e.g.: >
*'b:delimitMate_expand_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 = 1
au FileType tcl let b:delimitMate_expand_space = 1
<
------------------------------------------------------------------------------
*'delimitMate_expand_inside_quotes'*
*'b:delimitMate_expand_inside_quotes'*
Values: 1 or 0 ~
Default: 0 ~
When this option is set to 1 the expansion of space and cr will also be
applied to quotes. Read |delimitMateExpansion| for details.
e.g.: >
let delimitMate_expand_inside_quotes = 1
au FileType mail let b:delimitMate_expand_inside_quotes = 1
<
------------------------------------------------------------------------------
*'delimitMate_jump_expansion'*
*'b:delimitMate_jump_expansion'*
Values: 1 or 0 ~
Default: 0 ~
This option turns on/off the jumping over <CR> and <Space> expansions when
inserting closing matchpairs. Read |delimitMateExpansion| for details.
e.g.: >
let delimitMate_jump_expansion = 1
au FileType tcl let b:delimitMate_jump_expansion = 1
<
------------------------------------------------------------------------------
*'delimitMate_smart_quotes'*
*'b:delimitMate_smart_quotes'*
Values: 1 or 0 ~
Default: 1 ~
Values: String with an optional ! at the beginning followed by a regexp ~
Default:~
'\%(\w\|[^[:punct:][:space:]]\|\%(\\\\\)*\\\)\%#\|\%#\%(\w\|[^[:space:][:punct:]]\)' ~
A bang (!) at the beginning is removed and used to "negate" the pattern. The
remaining text is used as a regexp to be matched on the current line. A single
quote is inserted when the pattern matches and a bang is not present. The bang
changes that, so a single quote is inserted only if the regexp does not match.
This feature is disabled when the variable is set to an empty string, with the
exception of apostrophes.
Note that you need to use '\%#' to match the position of the cursor. Keep in
mind that '\%#' matches with zero width, so if you need to match the char
under the cursor (which would be the one to the right on insert mode) use
something like '\%#.'.
This option turns on/off the smart quotes feature. Read
|delimitMateSmartQuotes| for details.
e.g.: >
let delimitMate_smart_quotes = 0
au FileType tcl let b:delimitMate_smart_quotes = 0
let delimitMate_smart_quotes = '\w\%#'
au FileType tcl let b:delimitMate_smart_quotes = '!\s\%#\w'
<
------------------------------------------------------------------------------
*'delimitMate_smart_matchpairs'*
*'b:delimitMate_smart_matchpairs'*
Values: Regexp ~
Default: '^\%(\w\|\!\|[£$]\|[^[:space:][:punct:]]\)' ~
This regex is matched against the text to the right of cursor, if it's not
empty and there is a match delimitMate will not autoclose the pair. At the
moment to match the text, an escaped bang (\!) in the regex will be replaced
by the character being inserted, while an escaped number symbol (\#) will be
replaced by the closing pair.
e.g.: >
let delimitMate_smart_matchpairs = ''
au FileType tcl let b:delimitMate_smart_matchpairs = '^\%(\w\|\$\)'
<
------------------------------------------------------------------------------
*'delimitMate_balance_matchpairs'*
@@ -231,7 +299,7 @@ Default: Comment ~
This options turns delimitMate off for the listed regions, read |group-name|
for more info about what is a region.
e.g.: >
let delimitMate_excluded_regions = "Comments,String"
let delimitMate_excluded_regions = "Comment,String"
<
------------------------------------------------------------------------------
*'delimitMate_excluded_ft'*
@@ -243,6 +311,32 @@ 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_insert_eol_marker'*
Values: Integer ~
Default: 1 ~
Whether to insert the eol marker (EM) or not. The EM is inserted following
rules:
0 -> never
1 -> when inserting any matchpair
2 -> when expanding car return in matchpair
e.g.: >
au FileType c,perl let b:delimitMate_insert_eol_marker = 2
<
------------------------------------------------------------------------------
*'delimitMate_eol_marker'*
Values: String. ~
Default: Empty. ~
The contents of this string will be inserted after the closing matchpair or
quote when the respective opening matchpair or quote is inserted at the end
of the line.
e.g.: >
au FileType c,perl let b:delimitMate_eol_marker = ";"
<
------------------------------------------------------------------------------
*'delimitMate_apostrophes'*
Values: Strings separated by ":". ~
@@ -274,31 +368,42 @@ When the cursor is inside an empty pair or located next to the left of a
closing delimiter, the cursor is placed outside the pair to the right of the
closing delimiter.
When |'delimitMate_smart_matchpairs'| is not empty and it matches the text to
the right of the cursor, delimitMate will not automatically insert the closing
pair.
Unless |'delimitMate_matchpairs'| or |'delimitMate_quotes'| are set, this
script uses the values in '&matchpairs' to identify the pairs, and ", ' and `
for quotes respectively.
<S-Tab> will jump over a single closing delimiter or quote, <C-G>g will jump
over contiguous delimiters and/or quotes.
The following table shows the behaviour, this applies to quotes too (the final
position of the cursor is represented by a "|"):
With auto-close: >
Type | You get
====================
=======================
( | (|)
|
-----------|-----------
() | ()|
|
-----------|-----------
(<S-Tab> | ()|
-----------|-----------
{("<C-G>g | {("")}|
<
Without auto-close: >
Type | You get
=====================
=========================
() | (|)
-|
--------------|----------
()) | ()|
-|
--------------|----------
()<S-Tab> | ()|
--------------|----------
{}()""<C-G>g | {("")}|
<
NOTE: Abbreviations will not be expanded by delimiters used on delimitMate,
you should use <C-]> (read |i_CTRL-]|) to expand them on the go.
@@ -306,26 +411,38 @@ you should use <C-]> (read |i_CTRL-]|) to expand them on the go.
------------------------------------------------------------------------------
3.2 EXPANSION OF SPACE AND CAR RETURN *delimitMateExpansion*
When the cursor is inside an empty pair of delimiters, <Space> and <CR> can be
When the cursor is inside an empty pair of any matchpair, <Space> and <CR> can be
expanded, see |'delimitMate_expand_space'| and
|'delimitMate_expand_cr'|:
Expand <Space> to: >
<Space><Space><Left> | You get
====================================
You start with | You get
==============================
(|) | ( | )
<
Expand <CR> to: >
<CR><CR><Up> | You get
============================
You start with | You get
==============================
(|) | (
| |
| )
<
NOTE that the expansion of <CR> will brake the redo command.
When you have |'delimitMate_jump_expansion'| enabled, if there is an existing
closing paren/bracket/etc. on the next line, delimitMate will make the cursor
jump over any whitespace/<CR> and place it after the existing closing
delimiter instead of inserting a new one.
When |'delimitMate_expand_cr'| is set to 2, the following will also happen: >
You start with | You get
==============================
(foo|) | (foo
| |
| )
<
Since <Space> and <CR> are used everywhere, I have made the functions involved
in expansions global, so they can be used to make custom mappings. Read
@@ -335,8 +452,7 @@ in expansions global, so they can be used to make custom mappings. Read
3.3 BACKSPACE *delimitMateBackspace*
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.
expansions are enabled, <BS> will also delete the expansions.
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
@@ -360,11 +476,11 @@ e.g. typing at the "|": >
------------------------------------------------------------------------------
3.4 SMART QUOTES *delimitMateSmartQuotes*
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.
Only one quote will be inserted following a quote, a "\", following or
preceding a keyword character, or when the number of quotes in the current
line is odd. This should cover closing quotes after a string, opening quotes
before a string, escaped quotes and apostrophes. See more details about
customizing this feature on |'delimitMate_smart_quotes'|.
e.g. typing at the "|": >
@@ -375,6 +491,22 @@ e.g. typing at the "|": >
" | let i = "| | let i = "|"
'm | I| | I'm|
<
------------------------------------------------------------------------------
3.4 SMART MATCHPAIRS *delimitMateSmartMatchpairs*
This is similar to "smart quotes", but applied to the characters in
|'delimitMate_matchpairs'|. The difference is that delimitMate will not
auto-close the pair when the regex matches the text on the right of the
cursor. See |'delimitMate_smart_matchpairs'| for more details.
e.g. typing at the "|": >
What | Before | After
=======================================
( | function| | function(|)
( | |var | (|var
<
------------------------------------------------------------------------------
3.5 BALANCING MATCHING PAIRS *delimitMateBalance*
@@ -386,9 +518,9 @@ e.g. typing at the "|": >
What | Before | After
=======================================
( | |) | (|)
( | | | (|)
( | (|) | ((|))
( | |) | (|)
(( | |) | ((|))
<
------------------------------------------------------------------------------
3.6 FILE TYPE BASED CONFIGURATION *delimitMateFileType*
@@ -433,6 +565,16 @@ know about it.
Re-sets all the mappings used for this script, use it if any option has been
changed or if the filetype option hasn't been set yet.
------------------------------------------------------------------------------
:DelimitMateOn *:DelimitMateOn*
Enable delimitMate mappings.
------------------------------------------------------------------------------
:DelimitMateOff *:DelimitMateOff*
Disable delimitMate mappings.
------------------------------------------------------------------------------
:DelimitMateSwitch *:DelimitMateSwitch*
@@ -521,25 +663,12 @@ In order to make custom mappings easier and prevent overwritting existing
ones, delimitMate uses the |<Plug>| + |hasmapto()| (|usr_41.txt|) construct
for its mappings.
The following are the mappings alway set by delimitMate:
These are the default mappings for the extra features:
<BS> is mapped to <Plug>delimitMateBS
<S-BS> is mapped to <Plug>delimitMateS-BS
<S-Tab> is mapped to <Plug>delimitMateS-Tab
<Del> is mapped to <Plug>delimitMateDel
<Esc> is mapped to <Plug>delimitMateEsc
<Left> is mapped to <Plug>delimitMateLeft
<Right> is mapped to <Plug>delimitMateRight
<Home> is mapped to <Plug>delimitMateHome
<End> is mapped to <Plug>delimitMateEnd
<Up> is mapped to <Plug>delimitMateUp
<Down> is mapped to <Plug>delimitMateDown
<PageUp> is mapped to <Plug>delimitMatePageUp
<PageDown> is mapped to <Plug>delimitMatePageDown
<S-Down> is mapped to <Plug>delimitMateS-Down
<S-Up> is mapped to <Plug>delimitMateS-Up
<LeftMouse> is mapped to <Plug>delimitMateMLeftMouse
<RightMouse> is mapped to <Plug>delimitMateMRightMouse
<C-G>g is mapped to <Plug>delimitMateJumpMany
The rest of the mappings correspond to parens, quotes, CR, Space, etc. and they
depend on the values of the delimitMate options, they have the following form:
@@ -553,22 +682,22 @@ e.g.: for "(":
e.g.: If you have <CR> expansion enabled, you might want to skip it on pop-up
menus:
imap <expr> <CR> pumvisible() ?
\"\<c-y>" :
\ "<Plug>delimitMateCR"
imap <expr> <CR> pumvisible()
\ ? "\<C-Y>"
\ : "<Plug>delimitMateCR"
==============================================================================
6. FUNCTIONS *delimitMateFunctions*
------------------------------------------------------------------------------
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>" :
\ "<Plug>delimitMateCR" :
\ "external_mapping"
<
@@ -579,23 +708,56 @@ Returns 1 if there is a closing delimiter or a quote to the right of the
cursor, 0 otherwise.
------------------------------------------------------------------------------
delimitMate#JumpAny(key) *delimitMate#JumpAny()*
delimitMate#JumpAny() *delimitMate#JumpAny()*
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("\<C-Tab>")<CR>
inoremap <expr> <C-Tab> delimitMate#JumpAny()
<
==============================================================================
7. AUTOCOMMANDS *delimitMateAutocmds*
delimitMate emits 2 |User| autocommands to make it easier for users to
leverage delimitMate's support for per-filetype customization.
------------------------------------------------------------------------------
delimitMate_map *delimitMate_map*
This |User| event is emittted just prior to delimitMate defining its
buffer-local key mappings. You can use this command to define your own
mappings that are disabled when delimitMate is turned off or excludes the
current filetype.
>
au User delimitMate_map call s:delimitMate_map()
function s:delimitMate_map()
imap <buffer><expr> <C-Tab> delimitMate#JumpAny()
endfunction
<
------------------------------------------------------------------------------
delimitMate_unmap *delimitMate_unmap*
This |User| event is emitted just after delimitMate clears its buffer-local
key mappings. You can use this command to clear your own mappings that you set
in response to |delimitMate_map|.
>
au User delimitMate_unmap call s:delimitMate_unmap()
function s:delimitMate_unmap()
silent! iunmap <buffer> <C-Tab>
endfunction
<
Note: This event may be emitted before |delimitMate_map|, and may be emitted
multiple times in a row without any intervening |delimitMate_map| events.
==============================================================================
7. TODO LIST *delimitMateTodo*
8. TODO LIST *delimitMateTodo*
- Automatic set-up by file type.
- Make block-wise visual wrapping work on un-even regions.
==============================================================================
8. MAINTAINER *delimitMateMaintainer*
9. MAINTAINER *delimitMateMaintainer*
Hi there! My name is Israel Chauca F. and I can be reached at:
mailto:israelchauca@gmail.com
@@ -604,40 +766,62 @@ Feel free to send me any suggestions and/or comments about this plugin, I'll
be very pleased to read them.
==============================================================================
9. CREDITS *delimitMateCredits*
10. CREDITS *delimitMateCredits*
Some of the code that make this script is modified or just shamelessly copied
from the following sources:
Contributors: ~
- Ian McCracken
- Kim Silkebækken ~
Fixed mappings being echoed in the terminal.
- Eric Van Dewoestine ~
Implemented smart matchpairs.
Some of the code that makes this script was modified or just shamelessly
copied from the following sources:
- Ian McCracken ~
Post titled: Vim, Part II: Matching Pairs:
http://concisionandconcinnity.blogspot.com/
- Aristotle Pagaltzis
- Aristotle Pagaltzis ~
From the comments on the previous blog post and from:
http://gist.github.com/144619
- Karl Guertin
- Karl Guertin ~
AutoClose:
http://www.vim.org/scripts/script.php?script_id=1849
- Thiago Alves
- Thiago Alves ~
AutoClose:
http://www.vim.org/scripts/script.php?script_id=2009
- Edoardo Vacchi
- 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.
==============================================================================
10. HISTORY *delimitMateHistory*
11. HISTORY *delimitMateHistory*
Version Date Release notes ~
|---------|------------|-----------------------------------------------------|
2.5.1 2010-09-30 * Current release:
- Remove visual wrapping. Surround.vim offers a much
2.8 2013-07-15 * Current release:
- Add :DelimitMateOn & :DelimitMateOff.
|---------|------------|-----------------------------------------------------|
2.7 2013-07-15 * - Lots of bug fixes.
- Add delimitMate_offByDefault.
- Add delimitMate_eol_marker.
- Reduce the number of mappings.
- Stop using setline().
- Better handling of nested quotes.
- Allow a custom pattern for smart_quotes.
|---------|------------|-----------------------------------------------------|
2.6 2011-01-14 * - Add smart_matchpairs feature.
- Add mapping to jump over contiguous delimiters.
- Fix behaviour of b:loaded_delimitMate.
|---------|------------|-----------------------------------------------------|
2.5.1 2010-09-30 * - Remove visual wrapping. Surround.vim offers a much
better implementation.
- Minor mods to DelimitMateTest.
|---------|------------|-----------------------------------------------------|
@@ -668,7 +852,7 @@ This script was inspired by the auto-completion of delimiters on TextMate.
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
- Fix: <CR> expansion doesn't break 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.
@@ -758,4 +942,4 @@ _____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|____ ~
__|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_ ~
_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|_____|____ ~
vim:tw=78:et:ts=2:sw=2:ft=help:norl:formatoptions+=tcroqn:autoindent:
vim:tw=78:et:ts=8:sw=2:ft=help:norl:formatoptions+=tcroqn:autoindent:

View File

@@ -1,10 +1,10 @@
" ============================================================================
" File: plugin/delimitMate.vim
" Version: 2.5.1
" Modified: 2010-09-30
" Version: 2.7
" Modified: 2013-07-15
" Description: This plugin provides auto-completion for quotes, parens, etc.
" Maintainer: Israel Chauca F. <israelchauca@gmail.com>
" Manual: Read ":help delimitMate".
" ============================================================================
" Initialization: {{{
@@ -13,13 +13,8 @@ if exists("g:loaded_delimitMate") || &cp
finish
endif
let g:loaded_delimitMate = 1
if exists("s:loaded_delimitMate") && !exists("g:delimitMate_testing")
" Don't define the functions if they already exist: just do the work
" (unless we are testing):
call s:DelimitMateDo()
finish
endif
let save_cpo = &cpo
set cpo&vim
if v:version < 700
echoerr "delimitMate: this plugin requires vim >= 7!"
@@ -27,55 +22,52 @@ if v:version < 700
endif
let s:loaded_delimitMate = 1
let delimitMate_version = "2.5.1"
let delimitMate_version = "2.8"
"}}}
" Functions: {{{
function! s:option_init(name, default) "{{{
let b = exists("b:delimitMate_" . a:name)
let g = exists("g:delimitMate_" . a:name)
let prefix = "_l_delimitMate_"
if !b && !g
let sufix = a:default
elseif !b && g
exec "let sufix = g:delimitMate_" . a:name
let opt_name = "delimitMate_" . a:name
" Find value to use.
if !has_key(b:, opt_name) && !has_key(g:, opt_name)
let value = a:default
elseif has_key(b:, opt_name)
let value = b:[opt_name]
else
exec "let sufix = b:delimitMate_" . a:name
let value = g:[opt_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
call s:set(a:name, value)
endfunction "}}}
function! s:init() "{{{
" Initialize variables:
" autoclose
call s:option_init("autoclose", 1)
" matchpairs
call s:option_init("matchpairs", string(&matchpairs)[1:-2])
call s:option_init("matchpairs_list", split(b:_l_delimitMate_matchpairs, ','))
call s:option_init("left_delims", split(b:_l_delimitMate_matchpairs, ':.,\='))
call s:option_init("right_delims", split(b:_l_delimitMate_matchpairs, ',\=.:'))
call s:option_init("matchpairs_list", map(split(s:get('matchpairs', ''), '.:.\zs,\ze.:.'), 'split(v:val, ''^.\zs:\ze.$'')'))
let pairs = s:get('matchpairs_list', [])
if len(filter(pairs, 'v:val[0] ==# v:val[1]'))
echohl ErrorMsg
echom 'delimitMate: each member of a pair in delimitMate_matchpairs must be different from each other.'
echom 'delimitMate: invalid pairs: ' . join(map(pairs, 'join(v:val, ":")'), ', ')
echohl Normal
return 0
endif
call s:option_init("left_delims", map(copy(s:get('matchpairs_list', [])), 'v:val[0]'))
call s:option_init("right_delims", map(copy(s:get('matchpairs_list', [])), 'v:val[1]'))
" quotes
call s:option_init("quotes", "\" ' `")
call s:option_init("quotes_list", split(b:_l_delimitMate_quotes))
call s:option_init("quotes_list",split(s:get('quotes', ''), '\s\+'))
" nesting_quotes
call s:option_init("nesting_quotes", [])
" excluded_regions
call s:option_init("excluded_regions", "Comment")
call s:option_init("excluded_regions_list", split(b:_l_delimitMate_excluded_regions, ',\s*'))
let enabled = len(b:_l_delimitMate_excluded_regions_list) > 0
call s:option_init("excluded_regions_list", split(s:get('excluded_regions', ''), ',\s*'))
let enabled = len(s:get('excluded_regions_list', [])) > 0
call s:option_init("excluded_regions_enabled", enabled)
" excluded filetypes
call s:option_init("excluded_ft", "")
" 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!"
@@ -90,7 +82,6 @@ function! s:init() "{{{
let g:delimitMate_expand_space = 1
endif
call s:option_init("expand_space", 0)
" 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!"
@@ -104,47 +95,76 @@ function! s:init() "{{{
unlet g:delimitMate_expand_cr
let g:delimitMate_expand_cr = 1
endif
if (&backspace !~ 'eol' || &backspace !~ 'start') &&
if ((&backspace !~ 'eol' || &backspace !~ 'start') && &backspace != 2) &&
\ ((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
echom "delimitMate: There seems to be some incompatibility with your settings that may interfer with the expansion of <CR>. See :help 'delimitMate_expand_cr' for details."
endif
call s:option_init("expand_cr", 0)
" expand_in_quotes
call s:option_init('expand_inside_quotes', 0)
" jump_expansion
call s:option_init("jump_expansion", 0)
" smart_matchpairs
call s:option_init("smart_matchpairs", '^\%(\w\|\!\|[£$]\|[^[:punct:][:space:]]\)')
" smart_quotes
call s:option_init("smart_quotes", 1)
" XXX: backward compatibility. Ugly, should go the way of the dodo soon.
let quotes = escape(join(s:get('quotes_list', []), ''), '\-^[]')
let default_smart_quotes = '\%(\w\|[^[:punct:][:space:]' . quotes . ']\|\%(\\\\\)*\\\)\%#\|\%#\%(\w\|[^[:space:][:punct:]' . quotes . ']\)'
if exists('g:delimitMate_smart_quotes') && type(g:delimitMate_smart_quotes) == type(0)
if g:delimitMate_smart_quotes
unlet g:delimitMate_smart_quotes
else
unlet g:delimitMate_smart_quotes
let g:delimitMate_smart_quotes = ''
endif
endif
if exists('b:delimitMate_smart_quotes') && type(b:delimitMate_smart_quotes) == type(0)
if b:delimitMate_smart_quotes
unlet b:delimitMate_smart_quotes
if exists('g:delimitMate_smart_quotes') && type(g:delimitMate_smart_quotes) && g:delimitMate_smart_quotes
let b:delimitMate_smart_quotes = default_smart_quotes
endif
else
unlet b:delimitMate_smart_quotes
let b:delimitMate_smart_quotes = ''
endif
endif
call s:option_init("smart_quotes", default_smart_quotes)
" apostrophes
call s:option_init("apostrophes", "")
call s:option_init("apostrophes_list", split(b:_l_delimitMate_apostrophes, ":\s*"))
call s:option_init("apostrophes_list", split(s:get('apostrophes', ''), ":\s*"))
" tab2exit
call s:option_init("tab2exit", 1)
" balance_matchpairs
call s:option_init("balance_matchpairs", 0)
let b:_l_delimitMate_buffer = []
let b:loaded_delimitMate = 1
" eol marker
call s:option_init("insert_eol_marker", 1)
call s:option_init("eol_marker", "")
" Everything is fine.
return 1
endfunction "}}} Init()
"}}}
function! s:get(name, default) "{{{
let bufoptions = delimitMate#Get()
return get(bufoptions, a:name, a:default)
endfunction "}}}
" Functions: {{{
function! s:set(...) " {{{
return call('delimitMate#Set', a:000)
endfunction " }}}
function! s:Map() "{{{
" Set mappings:
try
let save_cpo = &cpo
let save_keymap = &keymap
let save_iminsert = &iminsert
let save_imsearch = &imsearch
let save_cpo = &cpo
set keymap=
set cpo&vim
if b:_l_delimitMate_autoclose
silent! doautocmd <nomodeline> User delimitMate_map
if s:get('autoclose', 1)
call s:AutoClose()
else
call s:NoAutoClose()
@@ -158,126 +178,103 @@ function! s:Map() "{{{
endtry
let b:delimitMate_enabled = 1
endfunction "}}} Map()
function! s:Unmap() " {{{
let imaps =
\ 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>'] +
\ s:get('right_delims', []) +
\ s:get('left_delims', []) +
\ s:get('quotes_list', []) +
\ s:get('apostrophes_list', []) +
\ ['<BS>', '<C-h>', '<S-BS>', '<Del>', '<CR>', '<Space>', '<S-Tab>', '<Esc>'] +
\ ['<Up>', '<Down>', '<Left>', '<Right>', '<LeftMouse>', '<RightMouse>'] +
\ ['<Home>', '<End>', '<PageUp>', '<PageDown>', '<S-Down>', '<S-Up>']
\ ['<C-Left>', '<C-Right>'] +
\ ['<Home>', '<End>', '<PageUp>', '<PageDown>', '<S-Down>', '<S-Up>', '<C-G>g']
for map in imaps
if maparg(map, "i") =~? 'delimitMate'
if maparg(map, "i") =~# '^<Plug>delimitMate'
if map == '|'
let map = '<Bar>'
endif
exec 'silent! iunmap <buffer> ' . map
endif
endfor
if !has('gui_running')
silent! iunmap <C-[>OC
endif
silent! doautocmd <nomodeline> User delimitMate_unmap
let b:delimitMate_enabled = 0
endfunction " }}} s:Unmap()
function! s:TestMappingsDo() "{{{
%d
if !exists("g:delimitMate_testing")
silent call delimitMate#TestMappings()
else
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 s:init()
call s:Unmap()
call s:Map()
call delimitMate#TestMappings()
normal o
endfor
endfor
let b:delimitMate_expand_space = temp_varsDM[0]
let b:delimitMate_expand_cr = temp_varsDM[1]
let b:delimitMate_autoclose = temp_varsDM[2]
unlet temp_varsDM
function! s:test() "{{{
if &modified
let confirm = input("Modified buffer, type \"yes\" to write and proceed "
\ . "with test: ") ==? 'yes'
if !confirm
return
endif
normal gg
endif
call delimitMate#Test()
g/\%^$/d
0
endfunction "}}}
function! s:DelimitMateDo(...) "{{{
" Initialize settings:
call s:init()
function! s:setup(...) "{{{
let swap = a:0 && a:1 == 2
let enable = a:0 && a:1
let disable = a:0 && !a:1
" First, remove all magic, if needed:
if get(b:, 'delimitMate_enabled', 0)
call s:Unmap()
" Switch
if swap
echo "delimitMate is disabled."
return
endif
endif
if disable
" Just disable the mappings.
return
endif
if !a:0
" 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 s:Unmap()
" Finish here:
return 1
endif
" First, remove all magic, if needed:
if exists("b:delimitMate_enabled") && b:delimitMate_enabled == 1
call s:Unmap()
" Check if user tried to disable using b:loaded_delimitMate
if exists("b:loaded_delimitMate")
return 1
endif
endif
" Initialize settings:
if ! s:init()
" Something went wrong.
return
endif
if enable || swap || !get(g:, 'delimitMate_offByDefault', 0)
" Now, add magic:
call s:Map()
if a:0 > 0
echo "delimitMate has been reset."
if a:0
echo "delimitMate is enabled."
endif
endif
endfunction "}}}
function! s:DelimitMateSwitch() "{{{
call s:init()
if exists("b:delimitMate_enabled") && b:delimitMate_enabled
call s:Unmap()
echo "delimitMate has been disabled."
else
call s:Unmap()
call s:Map()
echo "delimitMate has been enabled."
function! s:TriggerAbb() "{{{
if v:version < 703
\ || ( v:version == 703 && !has('patch489') )
\ || pumvisible()
return ''
endif
return "\<C-]>"
endfunction "}}}
function! s:Finish()
if exists('g:delimitMate_loaded')
return delimitMate#Finish()
endif
return ''
endfunction
function! s:FlushBuffer()
if exists('g:delimitMate_loaded')
return delimitMate#FlushBuffer()
endif
return ''
endfunction
"}}}
" Mappers: {{{
function! s:NoAutoClose() "{{{
" inoremap <buffer> ) <C-R>=delimitMate#SkipDelim('\)')<CR>
for delim in b:_l_delimitMate_right_delims + b:_l_delimitMate_quotes_list
for delim in s:get('right_delims', []) + s:get('quotes_list', [])
if delim == '|'
let delim = '<Bar>'
endif
exec 'inoremap <silent> <Plug>delimitMate' . delim . ' <C-R>=delimitMate#SkipDelim("' . escape(delim,'"') . '")<CR>'
exec 'inoremap <silent> <Plug>delimitMate' . delim . ' <C-R>=<SID>TriggerAbb().delimitMate#SkipDelim("' . escape(delim,'"') . '")<CR>'
exec 'silent! imap <unique> <buffer> '.delim.' <Plug>delimitMate'.delim
endfor
endfunction "}}}
@@ -286,33 +283,40 @@ function! s:AutoClose() "{{{
" Add matching pair and jump to the midle:
" inoremap <silent> <buffer> ( ()<Left>
let i = 0
while i < len(b:_l_delimitMate_matchpairs_list)
let ld = b:_l_delimitMate_left_delims[i] == '|' ? '<bar>' : b:_l_delimitMate_left_delims[i]
let rd = b:_l_delimitMate_right_delims[i] == '|' ? '<bar>' : b:_l_delimitMate_right_delims[i]
exec 'inoremap <silent> <Plug>delimitMate' . ld . ' ' . ld . '<C-R>=delimitMate#ParenDelim("' . escape(rd, '|') . '")<CR>'
exec 'silent! imap <unique> <buffer> '.ld.' <Plug>delimitMate'.ld
while i < len(s:get('matchpairs_list', []))
let ld = s:get('left_delims', [])[i] == '|' ? '<bar>' : s:get('left_delims', [])[i]
let rd = s:get('right_delims', [])[i] == '|' ? '<bar>' : s:get('right_delims', [])[i]
exec 'inoremap <expr><silent> <Plug>delimitMate' . ld
\. ' <SID>TriggerAbb().delimitMate#ParenDelim("' . escape(rd, '|') . '")'
exec 'silent! imap <unique> <buffer> '.ld
\.' <Plug>delimitMate'.ld
let i += 1
endwhile
" Exit from inside the matching pair:
for delim in b:_l_delimitMate_right_delims
exec 'inoremap <silent> <Plug>delimitMate' . delim . ' <C-R>=delimitMate#JumpOut("\' . delim . '")<CR>'
exec 'silent! imap <unique> <buffer> ' . delim . ' <Plug>delimitMate'. delim
for delim in s:get('right_delims', [])
let delim = delim == '|' ? '<bar>' : delim
exec 'inoremap <expr><silent> <Plug>delimitMate' . delim
\. ' <SID>TriggerAbb().delimitMate#JumpOut("\' . delim . '")'
exec 'silent! imap <unique> <buffer> ' . delim
\. ' <Plug>delimitMate'. delim
endfor
" Add matching quote and jump to the midle, or exit if inside a pair of matching quotes:
" inoremap <silent> <buffer> " <C-R>=delimitMate#QuoteDelim("\"")<CR>
for delim in b:_l_delimitMate_quotes_list
for delim in s:get('quotes_list', [])
if delim == '|'
let delim = '<Bar>'
endif
exec 'inoremap <silent> <Plug>delimitMate' . delim . ' <C-R>=delimitMate#QuoteDelim("\' . delim . '")<CR>'
exec 'silent! imap <unique> <buffer> ' . delim . ' <Plug>delimitMate' . delim
exec 'inoremap <expr><silent> <Plug>delimitMate' . delim
\. ' <SID>TriggerAbb()."<C-R>=delimitMate#QuoteDelim(\"\\\' . delim . '\")<CR>"'
exec 'silent! imap <unique> <buffer> ' . delim
\. ' <Plug>delimitMate' . delim
endfor
" Try to fix the use of apostrophes (kept for backward compatibility):
" inoremap <silent> <buffer> n't n't
for map in b:_l_delimitMate_apostrophes_list
for map in s:get('apostrophes_list', [])
exec "inoremap <silent> " . map . " " . map
exec 'silent! imap <unique> <buffer> ' . map . ' <Plug>delimitMate' . map
endfor
@@ -321,62 +325,38 @@ endfunction "}}}
function! s:ExtraMappings() "{{{
" If pair is empty, delete both delimiters:
inoremap <silent> <Plug>delimitMateBS <C-R>=delimitMate#BS()<CR>
" If pair is empty, delete closing delimiter:
inoremap <silent> <expr> <Plug>delimitMateS-BS delimitMate#WithinEmptyPair() ? "\<C-R>=delimitMate#Del()\<CR>" : "\<S-BS>"
" Expand return if inside an empty pair:
inoremap <silent> <Plug>delimitMateCR <C-R>=delimitMate#ExpandReturn()<CR>
" Expand space if inside an empty pair:
inoremap <silent> <Plug>delimitMateSpace <C-R>=delimitMate#ExpandSpace()<CR>
" Jump out ot any empty pair:
inoremap <silent> <Plug>delimitMateS-Tab <C-R>=delimitMate#JumpAny("\<S-Tab>")<CR>
" Change char buffer on Del:
inoremap <silent> <Plug>delimitMateDel <C-R>=delimitMate#Del()<CR>
" Flush the char buffer on movement keystrokes or when leaving insert mode:
for map in ['Esc', 'Left', 'Right', 'Home', 'End']
exec 'inoremap <silent> <Plug>delimitMate'.map.' <C-R>=<SID>Finish()<CR><'.map.'>'
if !hasmapto('<Plug>delimitMate'.map, 'i')
exec 'silent! imap <unique> <buffer> <'.map.'> <Plug>delimitMate'.map
endif
endfor
" Except when pop-up menu is active:
for map in ['Up', 'Down', 'PageUp', 'PageDown', 'S-Down', 'S-Up']
exec 'inoremap <silent> <expr> <Plug>delimitMate'.map.' pumvisible() ? "\<'.map.'>" : "\<C-R>=\<SID>Finish()\<CR>\<'.map.'>"'
if !hasmapto('<Plug>delimitMate'.map, 'i')
exec 'silent! imap <unique> <buffer> <'.map.'> <Plug>delimitMate'.map
endif
endfor
" Avoid ambiguous mappings:
for map in ['LeftMouse', 'RightMouse']
exec 'inoremap <silent> <Plug>delimitMateM'.map.' <C-R>=delimitMate#Finish()<CR><'.map.'>'
if !hasmapto('<Plug>delimitMate'.map, 'i')
exec 'silent! imap <unique> <buffer> <'.map.'> <Plug>delimitMateM'.map
endif
endfor
" Map away!
if !hasmapto('<Plug>delimitMateDel', 'i')
silent! imap <unique> <buffer> <Del> <Plug>delimitMateDel
endif
if !hasmapto('<Plug>delimitMateBS','i')
if empty(maparg('<BS>', 'i'))
silent! imap <unique> <buffer> <BS> <Plug>delimitMateBS
endif
if !hasmapto('<Plug>delimitMateS-BS','i')
if empty(maparg('<C-H>', 'i'))
silent! imap <unique> <buffer> <C-h> <Plug>delimitMateBS
endif
endif
" If pair is empty, delete closing delimiter:
inoremap <silent> <expr> <Plug>delimitMateS-BS delimitMate#WithinEmptyPair() ? "\<Del>" : "\<S-BS>"
if !hasmapto('<Plug>delimitMateS-BS','i') && maparg('<S-BS>', 'i') == ''
silent! imap <unique> <buffer> <S-BS> <Plug>delimitMateS-BS
endif
if b:_l_delimitMate_expand_cr != 0 && !hasmapto('<Plug>delimitMateCR', 'i')
" Expand return if inside an empty pair:
inoremap <expr><silent> <Plug>delimitMateCR <SID>TriggerAbb()."\<C-R>=delimitMate#ExpandReturn()\<CR>"
if s:get('expand_cr', 0) && !hasmapto('<Plug>delimitMateCR', 'i') && maparg('<CR>', 'i') == ''
silent! imap <unique> <buffer> <CR> <Plug>delimitMateCR
endif
if b:_l_delimitMate_expand_space != 0 && !hasmapto('<Plug>delimitMateSpace', 'i')
" Expand space if inside an empty pair:
inoremap <expr><silent> <Plug>delimitMateSpace <SID>TriggerAbb()."\<C-R>=delimitMate#ExpandSpace()\<CR>"
if s:get('expand_space', 0) && !hasmapto('<Plug>delimitMateSpace', 'i') && maparg('<Space>', 'i') == ''
silent! imap <unique> <buffer> <Space> <Plug>delimitMateSpace
endif
if b:_l_delimitMate_tab2exit && !hasmapto('<Plug>delimitMateS-Tab', 'i')
" Jump over any delimiter:
inoremap <expr><silent> <Plug>delimitMateS-Tab <SID>TriggerAbb()."\<C-R>=delimitMate#JumpAny()\<CR>"
if s:get('tab2exit', 0) && !hasmapto('<Plug>delimitMateS-Tab', 'i') && maparg('<S-Tab>', 'i') == ''
silent! imap <unique> <buffer> <S-Tab> <Plug>delimitMateS-Tab
endif
" 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>
" Jump over next delimiters
inoremap <expr><buffer> <Plug>delimitMateJumpMany <SID>TriggerAbb()."\<C-R>=delimitMate#JumpMany()\<CR>"
if !hasmapto('<Plug>delimitMateJumpMany', 'i') && maparg("<C-G>g", 'i') == ''
imap <silent> <buffer> <C-G>g <Plug>delimitMateJumpMany
endif
endfunction "}}}
@@ -384,16 +364,17 @@ endfunction "}}}
" Commands: {{{
call s:DelimitMateDo()
" Let me refresh without re-loading the buffer:
command! -bar DelimitMateReload call s:DelimitMateDo(1)
command! -bar DelimitMateReload call s:setup(1)
" Quick test:
command! -bar DelimitMateTest silent call s:TestMappingsDo()
command! -bar DelimitMateTest call s:test()
" Switch On/Off:
command! -bar DelimitMateSwitch call s:DelimitMateSwitch()
command! -bar DelimitMateSwitch call s:setup(2)
" Enable mappings:
command! -bar DelimitMateOn call s:setup(1)
" Disable mappings:
command! -bar DelimitMateOff call s:setup(0)
"}}}
" Autocommands: {{{
@@ -401,25 +382,22 @@ command! -bar DelimitMateSwitch call s:DelimitMateSwitch()
augroup delimitMate
au!
" Run on file type change.
"autocmd VimEnter * autocmd FileType * call <SID>DelimitMateDo()
autocmd FileType * call <SID>DelimitMateDo()
au FileType * call <SID>setup()
au FileType python let b:delimitMate_nesting_quotes = ['"', "'"]
" Run on new buffers.
autocmd BufNewFile,BufRead,BufEnter *
\ if !exists("b:loaded_delimitMate") |
\ call <SID>DelimitMateDo() |
au BufNewFile,BufRead,BufEnter,CmdwinEnter *
\ if !exists('b:delimitMate_was_here') |
\ call <SID>setup() |
\ let b:delimitMate_was_here = 1 |
\ endif
" Flush the char buffer:
autocmd InsertEnter * call <SID>FlushBuffer()
autocmd BufEnter *
\ if mode() == 'i' |
\ call <SID>FlushBuffer() |
\ endif
augroup END
"}}}
" This is for the default buffer when it does not have a filetype.
call s:setup()
let &cpo = save_cpo
" GetLatestVimScripts: 2754 1 :AutoInstall: delimitMate.vim
" vim:foldmethod=marker:foldcolumn=4
" vim:foldmethod=marker:foldcolumn=4:ts=2:sw=2

9
test/Makefile Normal file
View File

@@ -0,0 +1,9 @@
all: build/runVimTests
build/runVimTests/bin/runVimTests.sh -0 .
build/runVimTests: build/VimTAP
git clone https://github.com/inkarkat/runVimTests $@
# Use VimTAP as directory name, as used with runVimTestsSetup.vim.
build/VimTAP:
git clone https://github.com/inkarkat/vimtap $@

18
test/README.md Normal file
View File

@@ -0,0 +1,18 @@
# Automatic test setup
You can use `make` (or `make test` from the top level directory) to run the
tests.
# Manual test setup instructions
The plugins [runVimTests](http://www.vim.org/scripts/script.php?script_id=2565)
and [VimTAP](http://www.vim.org/scripts/script.php?script_id=2213) are needed
to run these tests.
Besides the `_setup.vim` configuration file present in this repo you need to
create a global one and place it in the same dir where the runVimTests
executable is located. Assuming the executable is at '~/bin/runVimTests' this
global configuration file should be '~/bin/runVimTestsSetup.vim' and should
have something like the following lines inside of it:
" Prepend tests repos to &rtp
let &runtimepath = '/path/to/runVimTests_dir,' . &rtp
let &runtimepath = '/path/to/vimTAP_dir,' . &rtp

12
test/_setup.vim Normal file
View File

@@ -0,0 +1,12 @@
let &rtp = expand('<sfile>:p:h:h') . ',' . &rtp . ',' . expand('<sfile>:p:h:h') . '/after'
set bs=2
ru plugin/delimitMate.vim
let runVimTests = expand('<sfile>:p:h').'/build/runVimTests'
if isdirectory(runVimTests)
let &rtp = runVimTests . ',' . &rtp
endif
let vimTAP = expand('<sfile>:p:h').'/build/VimTAP'
if isdirectory(vimTAP)
let &rtp = vimTAP . ',' . &rtp
endif

View File

@@ -0,0 +1,51 @@
let g:delimitMate_autoclose = 1
"(x" "(x)"
"(\<BS>x" "x"
"()x" "()x"
"((\<C-G>gx" "(())x"
"(x\<Esc>u" ""
"@(x" "@(x)"
"@#\<Left>(x" "@(x)#"
"(\<S-Tab>x" "()x"
let g:delimitMate_autoclose = 0
"(x" "(x"
"()x" "(x)"
"())x" "()x"
"()\<BS>x" "x"
"@()x" "@(x)"
"@#\<Left>()x" "@(x)#"
let g:delimitMate_expand_space = 1
let g:delimitMate_autoclose = 1
"(\<Space>x" "( x )"
"(\<Space>\<BS>x" "(x)"
let g:delimitMate_autoclose = 0
"()\<Space>\<BS>x" "(x)"
let g:delimitMate_autoclose = 1
# Handle backspace gracefully.
set backspace=
"(\<Esc>a\<BS>x" "(x)"
set bs=2
# closing parens removes characters. #133
"(a\<Esc>i)" "()a)"
# Add semicolon next to the closing paren. Issue #77.
new
let b:delimitMate_eol_marker = ';'
"abc(x" "abc(x);"
%d
# BS should behave accordingly.
"abc(\<BS>" "abc;"
# Expand iabbreviations
unlet b:delimitMate_eol_marker
iabb def ghi
"def(" "ghi()"
iunabb def
"abc а\<Left>(" "abc (а"
"abc ñ\<Left>(" "abc (ñ"
"abc $\<Left>(" "abc ($"
"abc £\<Left>(" "abc (£"
"abc d\<Left>(" "abc (d"
"abc \<C-V>(\<Left>(" "abc (("
"abc .\<Left>(" "abc ()."
"abc \<Left>(" "abc () "

View File

@@ -0,0 +1,42 @@
let g:delimitMate_matchpairs = '(:),{:},[:],<:>,¿:?,¡:!,,::'
let lines = readfile(expand('<sfile>:t:r').'.txt')
call vimtest#StartTap()
let testsnumber = len(filter(copy(lines), 'v:val =~ ''^"'''))
let itemsnumber = len(split(g:delimitMate_matchpairs, '.:.\zs,\ze.:.'))
call vimtap#Plan(testsnumber * itemsnumber)
let tcount = 1
let reload = 1
for item in lines
if item =~ '^#\|^\s*$'
" A comment or empty line.
continue
endif
if item !~ '^"'
" A command.
exec item
call vimtap#Diag(item)
let reload = 1
continue
endif
if reload
DelimitMateReload
call vimtap#Diag('DelimitMateReload')
let reload = 0
endif
let [input, output] = split(item, '"\%(\\.\|[^\\"]\)*"\zs\s*\ze"\%(\\.\|[^\\"]\)*"')
for [s:l,s:r] in map(split(g:delimitMate_matchpairs, '.:.\zs,\ze.:.'), 'split(v:val, ''.\zs:\ze.'')')
let input2 = substitute(input, '(', s:l, 'g')
let input2 = substitute(input2, ')', s:r, 'g')
let output2 = substitute(output, '(', s:l, 'g')
let output2 = substitute(output2, ')', s:r, 'g')
%d
exec 'normal i'.eval(input2)."\<Esc>"
let line = getline('.')
let passed = line == eval(output2)
call vimtap#Is(line, eval(output2), input2)
", input2 . ' => ' . string(line) .
" \ (passed ? ' =' : ' !') . '= ' . string(eval(output2)))
let tcount += 1
endfor
endfor
call vimtest#Quit()

73
test/autoclose_quotes.txt Normal file
View File

@@ -0,0 +1,73 @@
let g:delimitMate_autoclose = 1
"'x" "'x'"
"'x\<Esc>u" ""
"''x" "''x"
"'\<BS>x" "x"
"'\<C-G>gx" "''x"
# This will fail for double quote.
"'\"x" "'\"x\"'"
"@'x" "@'x'"
"@#\<Left>'x" "@'x'#"
"'\<S-Tab>x" "''x"
"abc'" "abc'"
"abc\\'x" "abc\\'x"
"u'Привет'" "u'Привет'"
"u'string'" "u'string'"
let g:delimitMate_autoclose = 0
"'x" "'x"
"''x" "'x'"
"'''x" "''x"
"''\<BS>x" "x"
"@''x" "@'x'"
"@#\<Left>''x" "@'x'#"
let g:delimitMate_expand_space = 1
let g:delimitMate_autoclose = 1
"'\<Space>x" "' x'"
let g:delimitMate_expand_inside_quotes = 1
"'\<Space>x" "' x '"
"'\<Space>\<BS>x" "'x'"
"abc\\''\<Space>x" "abc\\' x'"
let g:delimitMate_autoclose = 0
"''\<Space>\<BS>x" "'x'"
let g:delimitMate_autoclose = 1
# Handle backspace gracefully.
set backspace=
"'\<Esc>a\<BS>x" "'x'"
set backspace=2
set cpo=ces$
"'x" "'x'"
# Make sure smart quote works beyond first column.
" 'x" " 'x'"
# smart quote, check fo char on the right.
"a\<space>b\<left>'" "a 'b"
# Make sure we jump over a quote on the right. #89.
"('test'x" "('test'x)"
# Duplicate whole line when inserting quote at bol #105
"}\<Home>'" "''}"
"'\<Del>abc '" "'abc '"
"''abc '" "''abc ''"
# Nesting quotes:
let g:delimitMate_nesting_quotes = split(g:delimitMate_quotes, '\s\+')
"'''x" "'''x'''"
"''''x" "''''x''''"
"''x" "''x"
"'x" "'x'"
unlet g:delimitMate_nesting_quotes
# expand iabbreviations
iabb def ghi
"def'" "ghi'"
let g:delimitMate_smart_quotes = '\w\%#\_.'
"xyz'x" "xyz'x"
"xyz 'x" "xyz 'x'"
let g:delimitMate_smart_quotes = '\s\%#\_.'
"abc'x" "abc'x'"
"abc 'x" "abc 'x"
# let's try the negated form
let g:delimitMate_smart_quotes = '!\w\%#\_.'
"cba'x" "cba'x'"
"cba 'x" "cba 'x"
let g:delimitMate_smart_quotes = '!\s\%#\_.'
"zyx'x" "zyx'x"
"zyx 'x" "zyx 'x'"
unlet g:delimitMate_smart_quotes
"'\<CR>\<BS>" "''"

47
test/autoclose_quotes.vim Normal file
View File

@@ -0,0 +1,47 @@
"let g:delimitMate_quotes = '" '' ` ” « |'
let g:delimitMate_quotes = '" '' ` « |'
let lines = readfile(expand('<sfile>:t:r').'.txt')
call vimtest#StartTap()
let testsnumber = len(filter(copy(lines), 'v:val =~ ''^"'''))
let itemsnumber = len(split(g:delimitMate_quotes, ' '))
call vimtap#Plan(testsnumber * itemsnumber)
let reload = 1
let tcount = 1
let linenr = 0
for item in lines
let linenr += 1
if item =~ '^#\|^\s*$'
" A comment or empty line.
continue
endif
if item !~ '^"'
" A command.
exec item
call vimtap#Diag(item)
let reload = 1
continue
endif
if reload
DelimitMateReload
call vimtap#Diag('DelimitMateReload')
let reload = 0
endif
let quotes = split(g:delimitMate_quotes, '\s')
for quote in quotes
if vimtap#Skip(1, tcount != 26, "This test is invalid for double quote.")
let tcount += 1
continue
endif
let [input, output] = split(item, '"\%(\\.\|[^\\"]\)*"\zs\s*\ze"\%(\\.\|[^\\"]\)*"')
let input_q = substitute(input,"'" , escape(escape(quote, '"'), '\'), 'g')
let output_q = substitute(output,"'" , escape(escape(quote, '"'), '\'), 'g')
%d
exec 'normal i'.eval(input_q)."\<Esc>"
if quote == '”'
call vimtap#Todo(1)
endif
call vimtap#Is(getline('.'), eval(output_q), 'Line '.linenr.': '.eval(substitute(input_q, '\\<', '<','g')))
let tcount += 1
endfor
endfor
call vimtest#Quit()

44
test/eol_marker.vim Normal file
View File

@@ -0,0 +1,44 @@
let g:delimitMate_expand_cr = 1
let g:delimitMate_eol_marker = ';'
call vimtest#StartTap()
call vimtap#Plan(8)
" NOTE: Do not forget to update the plan ^
let g:delimitMate_insert_eol_marker = 0
DelimitMateReload
normal i(
call vimtap#Is(getline(1), '()', 'value = 1, case 1')
%d _
exec "normal i(\<CR>x"
call vimtap#Like(join(getline(1,line('$')), "\<NL>"),
\ '^(\n\s*x\n)$', ' "normal i(\<CR>x", Value = 2, case 2')
let g:delimitMate_insert_eol_marker = 1
DelimitMateReload
%d _
normal i(
call vimtap#Is(getline(1), '();', '"normal i(", value = 1, case 1')
%d _
exec "normal i(\<CR>x"
call vimtap#Like(join(getline(1,line('$')), "\<NL>"),
\ '^(\n\s*x\n);$', '"normal i(\<CR>x", Value = 2, case 2')
%d _
let g:delimitMate_insert_eol_marker = 2
DelimitMateReload
normal i(
call vimtap#Is(getline(1), '()', '"normal i(", Value = 2, case 1')
%d _
exec "normal i(\<CR>x"
call vimtap#Like(join(getline(1,line('$')), "\<NL>"),
\ '^(\n\s*x\n);$', '"normal i(\<CR>x", Value = 2, case 2')
%d _
exec "normal i{(\<CR>x"
call vimtap#Like(join(getline(1,line('$')), "\<NL>"),
\ '^{(\n\s*x\n)};$', ' "normal i{(\<CR>x", Value = 2, case 3')
%d _
exec "normal i;\<Esc>I{(\<CR>x"
call vimtap#Like(join(getline(1,line('$')), "\<NL>"),
\ '^{(\n\s*x\n)};$', ' "normal i{(\<CR>x", Value = 2, case 4')
" End: quit vim.
call vimtest#Quit()

96
test/expand_cr.txt Normal file
View File

@@ -0,0 +1,96 @@
#
%d
filetype indent on
set bs=2 et sts=4 sw=4 ft=javascript
call setline(1, '$(document).ready(function() {})')
DelimitMateReload
exec "normal 31|i\<CR>x\<Esc>"
================================================================================
$(document).ready(function() {
x
})
--------------------------------------------------------------------------------
# Issue #95
new
let b:delimitMate_jump_expansion = 1
DelimitMateReload
exec "normal i(\<CR>test)x"
================================================================================
(
test
)x
--------------------------------------------------------------------------------
# Remove CR expansion on BS
%d
exec "normal i(\<CR>\<BS>x"
================================================================================
(x)
--------------------------------------------------------------------------------
# Consider indentation with BS inside an empty CR expansion.
%d
exec "normal i( \<CR>\<BS>\<BS>x"
================================================================================
(x)
--------------------------------------------------------------------------------
# Conflict with indentation settings (cindent). Issue #95
se cindent
call setline(1, ['sub foo {',' while (1) {', ' ', ' }', '}'])
call cursor(3, 8)
normal a}x
================================================================================
sub foo {
while (1) {
}x
}
--------------------------------------------------------------------------------
%d
call setline(1, '"{bracketed}')
normal A"x
================================================================================
"{bracketed}"x
--------------------------------------------------------------------------------
# Syntax folding enabled by autocmd breaks expansion. But ti can't be tested
# with :normal
new
autocmd InsertEnter * let w:fdm=&foldmethod | setl foldmethod=manual
autocmd InsertLeave * let &foldmethod = w:fdm
set foldmethod=marker
set foldmarker={,}
set foldlevel=0
set backspace=2
exec "normal iabc {\<CR>x"
================================================================================
abc {
x
}
--------------------------------------------------------------------------------
# expand_cr != 2
%d_
call setline(1, 'abc(def)')
exec "normal $i\<CR>x"
================================================================================
abc(def
x)
--------------------------------------------------------------------------------
# expand_cr == 2
%d_
let delimitMate_expand_cr = 2
DelimitMateReload
call setline(1, 'abc(def)')
exec "normal $i\<CR>x"
================================================================================
abc(def
x
)
--------------------------------------------------------------------------------
# Play nice with smartindent
%d_
set all&
set smartindent
exec "normal $i{\<CR>x"
================================================================================
{
x
}
--------------------------------------------------------------------------------

55
test/expand_cr.vim Normal file
View File

@@ -0,0 +1,55 @@
let g:delimitMate_expand_cr = 1
"DelimitMateReload
let lines = readfile(expand('<sfile>:t:r').'.txt')
call vimtest#StartTap()
let testsnumber = len(filter(copy(lines), 'v:val =~ ''^=\{80}$'''))
call vimtap#Plan(testsnumber)
let tcount = 1
let expect = 0
let evaluate = 0
let commands = []
let header = ''
for item in lines
if item =~ '^=\{80}$'
let expect = 1
let expected = []
continue
endif
if item =~ '^#' && expect == 0
" A comment.
let header = empty(header) ? item[1:] : 'Lines should match.'
continue
endif
if item =~ '^\s*$' && expect == 0
" An empty line.
continue
endif
if ! expect
" A command.
call add(commands, item)
exec item
"call vimtap#Diag(item)
continue
endif
if item =~ '^-\{80}$'
let expect = 0
endif
if expect
call add(expected, item)
continue
endif
let lines = getline(1, line('$'))
let passed = lines == expected
echom string(lines)
echom string(expected)
call vimtap#Is(lines, expected, header)
echom string(commands)
for cmd in commands
call vimtap#Diag(cmd)
endfor
let commands = []
let header = ''
let tcount += 1
endfor
call vimtest#Quit()

8
test/expand_space.txt Normal file
View File

@@ -0,0 +1,8 @@
# Issue #95
new
let b:delimitMate_jump_expansion = 1
DelimitMateReload
exec "normal i( test)x"
================================================================================
( test )x
--------------------------------------------------------------------------------

42
test/expand_space.vim Normal file
View File

@@ -0,0 +1,42 @@
let g:delimitMate_expand_space = 1
"DelimitMateReload
let lines = readfile(expand('<sfile>:t:r').'.txt')
call vimtest#StartTap()
let testsnumber = len(filter(copy(lines), 'v:val =~ ''^=\{80}$'''))
call vimtap#Plan(testsnumber)
let tcount = 1
let expect = 0
let evaluate = 0
for item in lines
if item =~ '^=\{80}$'
let expect = 1
let expected = []
continue
endif
if item =~ '^#\|^\s*$' && expect == 0
" A comment or empty line.
continue
endif
if ! expect
" A command.
exec item
call vimtap#Diag(item)
continue
endif
if item =~ '^-\{80}$'
let expect = 0
endif
if expect
call add(expected, item)
continue
endif
let lines = getline(1, line('$'))
let passed = lines == expected
echom string(lines)
echom string(expected)
call vimtap#Ok(passed, string(expected) .
\ (passed ? ' =' : ' !') . '= ' . string(lines))
let tcount += 1
endfor
call vimtest#Quit()

View File

@@ -0,0 +1,8 @@
let g:delimitMate_expand_cr = 1
let g:delimitMate_eol_marker = ';'
call vimtest#StartTap()
call vimtap#Plan(1)
call vimtap#Like(maparg('(', 'i'), '<Plug>delimitMate(', 'Mappings defined for the first buffer without filetype set.')
call vimtest#Quit()