Allow same-character matching (fix #102)

commit 9fbba60cee83af1f92a9deebc4b48ca4027d6537
Author: Andy K. Massimino <f8a663@normed.space>
Date:   Fri Nov 27 09:36:11 2020 -0500

    Cleanup for same match

commit 2bf5e26f9e6ecb3f0874426e00cf15dd3f09a11a
Author: Andy K. Massimino <f8a663@normed.space>
Date:   Thu Nov 19 16:10:13 2020 -0500

    WIP same experiments

commit dcc2d874c5b92bccb0d043213264ef31c9b3a033
Author: Andy K. Massimino <f8a663@normed.space>
Date:   Sun Aug 30 11:49:20 2020 -0400

    WIP same char
This commit is contained in:
Andy K. Massimino
2020-11-27 09:36:52 -05:00
parent 309c3a74e7
commit f1e6716874
5 changed files with 74 additions and 16 deletions

View File

@@ -81,13 +81,13 @@ together with other plugins.
| ------- | -------------------------------- | -------------- | ------------- | ------------- |
| ([a.1]) | jump between matching words | :thumbsup: | :thumbsup: | :x: |
| ([a.2]) | jump to open & close words | :thumbsup: | :thumbsup: | :x: |
| ([a.3]) | jump inside | :thumbsup: | :x: | :x: |
| ([a.3]) | jump inside (`z%`) | :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: |
| ([c.4]) | show where you are (breadcrumbs) | :thumbsup: | :x: | :x: |
| ([d.1]) | modern, modular coding style | :thumbsup: | :x: | :x: |
| ([d.2]) | actively developed | :thumbsup: | :x: | :x: |
[a.1]: #a1-jump-between-matching-words
[a.2]: #a2-jump-to-open-and-close-words
@@ -96,8 +96,8 @@ together with other plugins.
[c.1]: #c1-highlight---and-
[c.2]: #c2-highlight-all-matches
[c.3]: #c3-display-matches-off-screen
[c.4]: #c4-where-am-i
[d.1]: #development
[d.2]: #development
[inclusive]: #inclusive-and-exclusive-motions
[exclusive]: #inclusive-and-exclusive-motions
@@ -231,9 +231,42 @@ since these commands make sure not to leave stale matches around.
If a open or close which would have been highlighted is on a line
positioned outside the current window, the match is shown in the
status line. If both the open and close match are off-screen, the
status line or popup window.
If both the open and close match are off-screen, the
close match is preferred.
(See the option `g:matchup_matchparen_offscreen`).
See the option `g:matchup_matchparen_offscreen` for more details.
For popup style (supported in recent vim and neovim versions):
```vim
let g:matchup_matchparen_offscreen = {'method': 'popup'}
```
For status line style (default):
```vim
let g:matchup_matchparen_offscreen = {'method': 'status'}
```
#### (c.4) where am I?
If you are lost, you can ask match-up where you are using
:MatchupWhereAmI?
This echos your position in the code in a breadcrumb-style by finding
successive matching words, like doing `[%` repeatedly.
It's useful to bind this to a key (not bound by default)
```vim
nnoremap <c-k> :<c-u>MatchupWhereAmI?<cr>
```
If you are really lost, you can ask a bit harder to get a more detailed
print out.
:MatchupWhereAmI??
### Inclusive and exclusive motions

View File

@@ -71,6 +71,9 @@ function! s:get_match_words()
" generic environment
let l:match_words .= ',\\begin\s*{\([^}]*\)}:\\end\s*{\1}'
" dollar sign math
let l:match_words .= ',\$:\$\g{syn;!texMathZoneX}'
return l:match_words
endfunction

View File

@@ -563,6 +563,21 @@ function! s:parser_delim_new(lnum, cnum, opts) " {{{1
continue
endif
" handle syntax check- currently used for 'same' matches
if has_key(l:extra_entry, 'syn')
let l:pat = l:extra_entry.syn
if l:pat[0] == '!'
let l:pat = l:pat[1:]
if matchup#util#in_synstack(l:pat, a:lnum, a:cnum)
continue
endif
else
if !matchup#util#in_synstack(l:pat, a:lnum, a:cnum)
continue
endif
endif
endif
let l:found = 1
break
endfor
@@ -572,8 +587,6 @@ function! s:parser_delim_new(lnum, cnum, opts) " {{{1
break
endfor
" reset ignorecase (defunct)
if !l:found
return {}
endif
@@ -716,15 +729,19 @@ function! s:get_matching_delims(down, stopline) dict " {{{1
let l:open = l:ic . l:open
let l:close = l:ic . l:close
let [l:lnum_corr, l:cnum_corr] = searchpairpos(l:open, '', l:close,
\ 'n'.l:flags, l:skip, l:stopline, matchup#perf#timeout())
" handle 'same' matches (TODO refactor to separate parser)
if l:open == l:close
let [l:lnum_corr, l:cnum_corr] = searchpos(l:open,
\ 'n'.l:flags, l:stopline, matchup#perf#timeout(), l:skip)
else
let [l:lnum_corr, l:cnum_corr] = searchpairpos(l:open, '', l:close,
\ 'n'.l:flags, l:skip, l:stopline, matchup#perf#timeout())
endif
call matchup#perf#toc('get_matching_delims', 'initial_pair')
" if nothing found, bail immediately
if l:lnum_corr == 0
" reset ignorecase (defunct)
return [['', 0, 0]]
endif
@@ -740,8 +757,6 @@ function! s:get_matching_delims(down, stopline) dict " {{{1
let l:matches = matchlist(getline(l:lnum_corr), l:re_anchored)
let l:match_corr = l:matches[0]
" reset ignorecase (defunct)
" store these in these groups
if a:down
" let l:id = len(self.regextwo.mid_list)+1
@@ -806,8 +821,6 @@ function! s:get_matching_delims(down, stopline) dict " {{{1
call add(l:list, [l:match, l:lnum, l:cnum])
endwhile
" reset ignorecase (defunct)
call add(l:list, [l:match_corr, l:lnum_corr, l:cnum_corr])
if !a:down

View File

@@ -16,7 +16,7 @@ let g:matchup#re#zs = s:nbsl . '\\zs'
" \ze atom
let g:matchup#re#ze = s:nbsl . '\\ze'
" \g{special}, \g{special:arg}
" \g{special}, \g{special;arg}
let g:matchup#re#gspec = s:nbsl . '\\g{\(\w\+\);\?\(.\{-}\)\?}'
" vim: fdm=marker sw=2

View File

@@ -46,6 +46,15 @@ function! matchup#util#in_syntax(name, ...) " {{{1
endfunction
" }}}1
function! matchup#util#in_synstack(name, ...) abort " {{{1
let l:pos = a:0 > 0 ? [a:1, a:2] : [line('.'), col('.')]
let l:syn = map(synstack(l:pos[0], l:pos[1]),
\ "synIDattr(v:val, 'name')")
return match(l:syn, '^' . a:name) >= 0
endfunction
" }}}1
function! matchup#util#in_whitespace(...) " {{{1
let l:pos = a:0 > 0 ? [a:1, a:2] : [line('.'), col('.')]
return matchstr(getline(l:pos[0]), '\%'.l:pos[1].'c.') =~# '\s'