Improve README, add some cpo&vim, start work on text_obj

This commit is contained in:
Andy K. Massimino
2017-10-31 09:31:49 -04:00
parent ad7d9b5622
commit 44b35401b5
7 changed files with 168 additions and 72 deletions

View File

@@ -5,9 +5,44 @@ include a minimal working example and a minimal vimrc file (see below), as
well as:
1. Steps to reproduce
2. Expected behaviour
3. Observed behaviour
2. Expected behavior
3. Observed behavior
If your issue is instead a feature request or anything else, please
consider if minimal examples and vimrc files might still be relevant.
### Minimal working example
Please provide a minimal working example, e.g.,
```vim
if l:x == 1
call one()
else
call two()
elseif
call three()
endif
```
### Minimal vimrc file
Please provide a minimal vimrc file that reproduces the issue. The
following should often suffice:
```vim
set nocompatible
" load match-up
let &rtp = '~/.vim/bundle/matchup.vim,' . &rtp
let &rtp .= ',~/.vim/bundle/matchup.vim/after'
" load other plugins, if necessary
" let &rtp = '~/path/to/other/plugin,' . &rtp
filetype plugin indent on
syntax enable
" match-up options go here
```

130
README.md
View File

@@ -60,35 +60,35 @@ Or use some other plugin manager:
## Features
| | feature | __match-up__ | matchit | matchparen |
| ------- | -------------------------------- | ------------- | ------------- | ------------- |
| ([a.1]) | jump between matching words | :thumbsup: | :thumbsup: | :x: |
| ([a.2]) | jump to open & close words | :thumbsup: | :question: | :x: |
| ([a.3]) | jump inside | :thumbsup: | :x: | :x: |
| ([b.1]) | full set of text objects | :thumbsup: | :question: | :x: |
| ([c.1]) | highlight `()`, `[]`, & `{}` | :thumbsup: | :x: | :thumbsup: |
| ([c.2]) | highlight _all_ matches | :thumbsup: | :x: | :x: |
| ([c.3]) | display matches off-screen | :thumbsup: | :x: | :x: |
| ([d.1]) | auto-insert open, close, & mid | :construction:| :x: | :x: |
| ([d.2]) | completion | :construction:| :x: | :x: |
| ([d.3]) | parallel transmutation | :thumbsup: | :x: | :x: |
| ([d.4]) | split & join | :construction:| :x: | :x: |
| ([e.1]) | modern, modular coding style | :thumbsup: | :x: | :x: |
| ([e.2]) | actively developed | :thumbsup: | :x: | :x: |
| | feature | __match-up__ | matchit | matchparen |
| ------- | -------------------------------- | -------------- | ------------- | ------------- |
| ([a.1]) | jump between matching words | :thumbsup: | :thumbsup: | :x: |
| ([a.2]) | jump to open & close words | :thumbsup: | :question: | :x: |
| ([a.3]) | jump inside | :thumbsup: | :x: | :x: |
| ([b.1]) | full set of text objects | :thumbsup: | :question: | :x: |
| ([c.1]) | highlight `()`, `[]`, & `{}` | :thumbsup: | :x: | :thumbsup: |
| ([c.2]) | highlight _all_ matches | :thumbsup: | :x: | :x: |
| ([c.3]) | display matches off-screen | :thumbsup: | :x: | :x: |
| ([d.1]) | auto-insert open, close, & mid | :construction: | :x: | :x: |
| ([d.2]) | completion | :construction: | :x: | :x: |
| ([d.3]) | parallel transmutation | :construction: | :x: | :x: |
| ([d.4]) | split & join | :construction: | :x: | :x: |
| ([e.1]) | modern, modular coding style | :thumbsup: | :x: | :x: |
| ([e.2]) | actively developed | :thumbsup: | :x: | :x: |
[a.1]: #a1-jump-between-matching-words
[a.2]: #a2-jump-to-open-and-close-words
[a.3]: #a3-jump-inside
[b.1]: #b1-full-set-of-text-objects
[c.1]: #c1-highlight-
[c.1]: #c1-highlight---and-
[c.2]: #c2-highlight-all-matches
[c.3]: #c3-display-matches-off-screen
[d.1]: #d1-auto-insert-open-close-and-mid
[d.2]: #d2-completion
[d.3]: #d3-parallel-transmutation
[d.4]: #d4-split-and-join
[e.1]: #e1-modern-modular-coding-style
[e.2]: #e2-actively-developed
[e.1]: #development
[e.2]: #development
[inclusive]: #inclusive-and-exclusive-motions
[exclusive]: #inclusive-and-exclusive-motions
@@ -182,17 +182,16 @@ corresponding end word.
- automatic block insertion: typing `CTRL-X CTRL-B` to produce
block skeletons.
#### (d.2) auto-completion
#### (d.2) completion
_Planned_.
Typing `CTRL-X M` will give a menu of possible words.
Typing `CTRL-X O`/`CTRL-X W` will give a menu of possible words.
#### (d.3) parallel transmutations
#### (d.3) parallel transmutation
In insert mode, after changing text inside a word, matching words will
be changed in parallel.
As an example,
be changed in parallel. As an example,
```html
<pre>
@@ -208,10 +207,11 @@ Changing `pre` to `div` and leaving insert mode will produce:
</div>
```
This must be done before leaving insert mode. A corresponding normal mode
command is planned.
Note: this currently only works for match words which define a backref
relation like `\1`. A wider set of transmutations are planned.
_Planned_: `g:matchup_auto_transmute`, `CTRL-G %` mapping.
_Planned_: `g:matchup_auto_transmute`, `CTRL-G %` mapping. A
corresponding normal mode command is also planned.
#### (d.4) split and join
@@ -226,11 +226,15 @@ that `d]%` inside a set of parenthesis behaves exactly like `d])`. For
other words, exclusive motions will not include the close word. In this
example, where `█` is the cursor position,
if █| continue | endif
```vim
if| continue | endif
```
pressing `d]%` will produce
if endif
```vim
if endif
```
To include the close word, use either `dv]%` or `vd]%`. This is vim
compatible.
@@ -243,40 +247,41 @@ compatible.
- match-up doesn't work
The plugin requires a fairly recent version of vim. Please tell me your
vim version and error messages. Try updating vim and see if the problem
persists.
The plugin requires a fairly recent version of vim. Please tell me your
vim version and error messages. Try updating vim and see if the problem
persists.
- Why does jumping not work for construct X in language Y?
Please open a new issue
Please open a new issue
- Highlighting is not correct for construct X
match-up uses matchit's filetype-specific data, which may not give enough
information to create proper highlights. To fix this, you may need to add
a highlight quirk.
match-up uses matchit's filetype-specific data, which may not give
enough information to create proper highlights. To fix this, you may
need to add a highlight quirk.
For help, please open a new issue and be a specific as possible.
- I'm having performance problems
match-up aims to be as fast as possible. If you see any performance
issues, please open a new issue and report `g:matchup#perf#times`.
match-up aims to be as fast as possible. If you see any performance
issues, please open a new issue and report `g:matchup#perf#times`.
- How can I contribute?
Read the [contribution guidelines](CONTRIBUTING.md) and
[issue template](ISSUE_TEMPLATE.md). Be as precise and detailed
as possible when submitting issues and pull requests.
Read the [contribution guidelines](CONTRIBUTING.md) and [issue
template](ISSUE_TEMPLATE.md). Be as precise and detailed as possible
when submitting issues and pull requests.
## Interoperability
- match-up is not compatible with [vimtex](https://github.com/lervag/vimtex)
and will be disabled automatically when vimtex is detected.
- the end-completion maps conflict with [vim-endwise](https://github.com/tpope/vim-endwise).
- match-up's match highlighting is not compatible with [vimtex]'s
implementation. match-up highlighting and will be disabled
automatically when vimtex is detected.
- matchit.vim should not be loaded. If it is loaded, it must be loaded
before match-up (in this case, matchit is disabled).
before match-up (in this case, matchit will be disabled when match-up
loads).
- match-up loads matchparen if it is not already loaded.
## Acknowledgments
@@ -284,20 +289,22 @@ as possible when submitting issues and pull requests.
### Origins
match-up was originally based on [@lervag](https://github.com/lervag)'s
[vimtex](github.com/lervag/vimtex). The concept and style of this plugin
and its development are heavily influenced by vimtex.
[vimtex]. The concept and style of this plugin and its development are
heavily influenced by vimtex. :beers:
[vimtex]: https://github.com/lervag/vimtex
### Other inspirations
- [matchit](http://ftp.vim.org/pub/vim/runtime/macros/matchit.txt)
- [matchparen](http://ftp.vim.org/pub/vim/runtime/doc/pi_paren.txt)
- [MatchTagAlways](https://github.com/Valloric/MatchTagAlways)
- [vim-endwise](https://github.com/tpope/vim-endwise)
- [auto-pairs](https://github.com/jiangmiao/auto-pairs)
- [delimitMate](https://github.com/Raimondi/delimitMate)
- [splitjoin.vim](https://github.com/AndrewRadev/splitjoin.vim)
- [vim-surround](https://github.com/tpope/vim-surround)
- [vim-sandwich](https://github.com/machakann/vim-sandwich)
- [MatchTagAlways](https://github.com/Valloric/MatchTagAlways)
## license
@@ -354,11 +361,34 @@ Features not in matchit:
Jump into
z[]% go to the center of the next group of matchwords
- the end-completion maps conflict with [vim-endwise](https://github.com/tpope/vim-endwise).
## Development
### TODO
### Reporting problems
- vim proper doc/
- Add screenshots
This is a brand new plugin and there are likely to be many bugs.
Thorough issue reports are encouraged. Please read the [issue
template](ISSUE_TEMPLATE.md) first. Be as precise and detailed as
possible when submitting issues.
Feature requests are also welcome.
### Contributing
Read the [contribution guidelines](CONTRIBUTING.md) before contributing.
### Planned feature wish-list
This is a set of features planned for "version 1" but require a bit more
research before they can be tackled.
### Todo list
- write proper vim doc
- thoroughly test with unicode, tabs
- add screenshots and animations
- can match-up be integrated with
[vim-surround](https://github.com/tpope/vim-surround)?

View File

@@ -765,7 +765,10 @@ function! s:get_matching_delims(down) dict " {{{1
" let s:foo+= 1
" improves perceptual performance
sleep 1m
" XXX use s: mode flag
if mode() ==# 'i'
sleep 1m
endif
" call matchup#perf#tic('q7')
" TODO support timeout
@@ -1006,6 +1009,7 @@ function! s:init_delim_lists() " {{{1
let l:curaug = l:words[0]
" TODO: \0 should match the whole pattern..
" augments[0] is the original words[0] with original capture groups
let l:augments[0] = l:curaug " XXX does putting this in 0 make sense?
for l:j in l:order
" these indexes are not invalid because we work backwards
@@ -1025,7 +1029,11 @@ function! s:init_delim_lists() " {{{1
let l:words[0] = l:augments[l:order[-1]]
endif
echo l:augments
" as a concrete example,
" l:augments = { '0': '\<\(wh\%[ile]\|for\)\>', '1': '\<\1\>'}
" l:words[0] = \<\1\>
" echo l:augments l:words[0]
" now for the rest of the words...
for l:i in range(1, len(l:words)-1)

View File

@@ -29,3 +29,4 @@ endif
let s:file = expand('<sfile>')
" vim: fdm=marker sw=2

View File

@@ -4,6 +4,9 @@
" Email: a@normed.space
"
let s:save_cpo = &cpo
set cpo&vim
function! matchup#pos#set_cursor(...) " {{{1
call cursor(s:parse_args(a:000))
endfunction
@@ -92,4 +95,7 @@ endfunction
" }}}1
let &cpo = s:save_cpo
" vim: fdm=marker sw=2

View File

@@ -4,6 +4,9 @@
" Email: a@normed.space
"
let s:save_cpo = &cpo
set cpo&vim
function! matchup#text_obj#init_module() " {{{1
if !g:matchup_text_obj_enabled | return | endif
@@ -21,45 +24,45 @@ function! matchup#text_obj#init_module() " {{{1
endfunction
" }}}1
function! matchup#text_obj#delimited(is_inner, mode, type) " {{{1
if a:mode
function! matchup#text_obj#delimited(is_inner, visual, type) " {{{1
if a:visual
let l:selection = getpos("'<")[1:2] + getpos("'>")[1:2]
call matchup#pos#set_cursor(getpos("'>"))
endif
let [l:open, l:close] = matchup#delim#get_surrounding(a:type)
if empty(l:open)
if a:mode
if a:visual
normal! gv
endif
return
endif
let [l1, c1, l2, c2] = [l:open.lnum, l:open.cnum, l:close.lnum, l:close.cnum]
let [l:l1, l:c1, l:l2, l:c2] = [l:open.lnum, l:open.cnum,
\ l:close.lnum, l:close.cnum]
" Determine if operator is linewise
let l:linewise = index(g:matchup_text_obj_linewise_operators, v:operator) >= 0
let l:linewise = index(g:matchup_text_obj_linewise_operators,
\ v:operator) >= 0
let l:linewise = 1
" Adjust the borders
if a:is_inner
if has_key(l:open, 'env_cmd') && !empty(l:open.env_cmd)
let l1 = l:open.env_cmd.pos_end.lnum
let c1 = l:open.env_cmd.pos_end.cnum+1
else
let c1 += len(l:open.match)
endif
let c1 += len(l:open.match)
let c2 -= 1
let l:is_inline = (l2 - l1) > 1
\ && match(strpart(getline(l1), c1), '^\s*$') >= 0
\ && match(strpart(getline(l2), 0, c2), '^\s*$') >= 0
let l:is_inline = (l:l2 - l:l1) > 1 ? 1 : 0
" \ && match(strpart(getline(l1), c1 ), '^\s*$') >= 0
" \ && match(strpart(getline(l2), 0, c2), '^\s*$') >= 0
if l:is_inline
let l1 += 1
let c1 = strlen(matchstr(getline(l1), '^\s*')) + 1
let l2 -= 1
let c2 = strlen(getline(l2))
if c2 == 0 && ! l:linewise
if c2 == 0 && !l:linewise
let l2 -= 1
let c2 = len(getline(l2)) + 1
endif
@@ -69,9 +72,11 @@ function! matchup#text_obj#delimited(is_inner, mode, type) " {{{1
endif
else
let c2 += len(l:close.match) - 1
endif
" Select next pair if we reached the same selection
if a:mode && l:selection == [l1, c1, l2, c2]
" select next pair if we reached the same selection
if a:visual && l:selection == [l1, c1, l2, c2]
echo 'foobar' | sleep 1
call matchup#pos#set_cursor(matchup#pos#next([l2, c2]))
let [l:open, l:close] = matchup#delim#get_surrounding(a:type)
if empty(l:open)
@@ -85,12 +90,14 @@ function! matchup#text_obj#delimited(is_inner, mode, type) " {{{1
let l:is_inline = (l2 - l1) > 1
\ && match(strpart(getline(l1), 0, c1-1), '^\s*$') >= 0
\ && match(strpart(getline(l2), 0, c2), '^\s*$') >= 0
endif
" Determine the select mode
let l:select_mode = l:is_inline && l:linewise ? 'V'
\ : (v:operator ==# ':') ? visualmode() : 'v'
echo l:is_inline l:linewise v:operator visualmode()
\ l:l2 l:l1 l:l2-l:l1 | sleep 1
" Apply selection
execute 'normal!' l:select_mode
call matchup#pos#set_cursor(l1, c1)
@@ -100,4 +107,7 @@ endfunction
" }}}1
let &cpo = s:save_cpo
" vim: fdm=marker sw=2

View File

@@ -1,3 +1,8 @@
" vim match-up - matchit replacement and more
"
" Maintainer: Andy Massimino
" Email: a@normed.space
"
if !get(g:, 'matchup_enabled', 1)
finish
@@ -24,3 +29,4 @@ au! matchparen
call matchup#init()
" vim: fdm=marker sw=2