Allow disabling matching within strings/comments

fixes #26
This commit is contained in:
Andy K. Massimino
2018-03-14 23:48:41 -04:00
parent 257a1e2b80
commit f2a555e878
5 changed files with 41 additions and 3 deletions

View File

@@ -383,6 +383,13 @@ let g:matchup_delim_stopline = 1500
```
default: 1500
To disable matching within strings and comments,
```vim
let g:matchup_delim_noskips = 1 " recognize symbols within comments
let g:matchup_delim_noskips = 2 " don't recognize anything in comments
```
default: 0 (matching is enabled within strings and comments)
### Variables
match-up understands the following variables from matchit.

View File

@@ -29,6 +29,7 @@ function! s:init_options()
\ get(g:, 'matchparen_insert_timeout', 60))
call s:init_option('matchup_delim_count_fail', 0)
call s:init_option('matchup_delim_noskips', 0)
call s:init_option('matchup_motion_enabled', 1)
call s:init_option('matchup_motion_cursor_end', 1)

View File

@@ -349,14 +349,16 @@ function! s:get_delim(opts) " {{{1
let s:invert_skip = 0
if a:opts.direction ==# 'current'
let l:check_skip = get(a:opts, 'check_skip', 0)
let l:check_skip = get(a:opts, 'check_skip',
\ g:matchup_delim_noskips >= 2)
if l:check_skip && matchup#delim#skip(line('.'), l:cursorpos)
return {}
endif
else
" check skip if cursor is not currently in skip
let l:check_skip = get(a:opts, 'check_skip',
\ !matchup#delim#skip(line('.'), l:cursorpos))
\ !matchup#delim#skip(line('.'), l:cursorpos)
\ || g:matchup_delim_noskips >= 2)
endif
let a:opts.cursorpos = l:cursorpos
@@ -398,10 +400,16 @@ function! s:get_delim(opts) " {{{1
\ : searchpos(l:re, 'bcnW', line('.'))
if l:lnum == 0 | break | endif
let l:wordish_skip = g:matchup_delim_noskips == 1
\ && getline(l:lnum)[l:cnum-1] =~ '[^[:punct:]]'
if a:opts.direction ==# 'current' && l:wordish_skip
return {}
endif
" note: the skip here should not be needed
" in 'current' mode, but be explicit
if a:opts.direction !=# 'current'
\ && l:check_skip
\ && (l:check_skip || l:wordish_skip)
\ && matchup#delim#skip(l:lnum, l:cnum)
" invalid match, move cursor and keep looking

View File

@@ -412,6 +412,19 @@ Options~
Default: 1500
*g:matchup_delim_noskips*
This option controls whether matching is done within strings and comments.
By default, it is set to 0 which means all valid matches are made within
strings and comments. If set to 1, symbols like `()` will still be matched
but words like `for` and `end` will not. If set to 2, nothing will be
matched within strings and comments. >
let g:matchup_delim_noskips = 1
let g:matchup_delim_noskips = 2
<
Default: 0 (matching enabled within strings and comments)
Variables~
*b:match_words*

View File

@@ -0,0 +1,9 @@
class Example
def initialize
@text = 'for text'
@text2 = 'end text2'
@text3 = '( text )'
end
end