Skip to content

Instantly share code, notes, and snippets.

@chrisbra
Created September 12, 2017 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisbra/61f11802c2da69ba3f35665ccc44f108 to your computer and use it in GitHub Desktop.
Save chrisbra/61f11802c2da69ba3f35665ccc44f108 to your computer and use it in GitHub Desktop.
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index 859fbe8f7..048bf0da2 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -5176,6 +5176,8 @@ A jump table for the options with a short description can be found at |Q_op|.
Running into the limit often means that the pattern is very
inefficient or too complex. This may already happen with the pattern
"\(.\)*" on a very long line. ".*" works much better.
+ Might also happen, on redraw, when syntax rules try to match a complex
+ file structure.
Vim may run out of memory before hitting the 'maxmempattern' limit.
*'maxmemtot'* *'mmt'*
diff --git a/runtime/pack/dist/opt/matchit/plugin/matchit.vim b/runtime/pack/dist/opt/matchit/plugin/matchit.vim
index 4c9b84592..d9bc54ae1 100644
--- a/runtime/pack/dist/opt/matchit/plugin/matchit.vim
+++ b/runtime/pack/dist/opt/matchit/plugin/matchit.vim
@@ -720,10 +720,16 @@ fun! s:MultiMatch(spflag, mode)
let openpat = substitute(openpat, ',', '\\|', 'g')
let closepat = substitute(close, '\(\\\@<!\(\\\\\)*\)\@<=\\(', '\\%(', 'g')
let closepat = substitute(closepat, ',', '\\|', 'g')
+
if skip =~ 'synID' && !(has("syntax") && exists("g:syntax_on"))
let skip = '0'
else
- execute "if " . skip . "| let skip = '0' | endif"
+ try
+ execute "if " . skip . "| let skip = '0' | endif"
+ catch /^Vim\%((\a\+)\)\=:E363/
+ " We won't find anything, so skip searching, should keep Vim responsive.
+ return
+ endtry
endif
mark '
let level = v:count1
diff --git a/runtime/plugin/matchparen.vim b/runtime/plugin/matchparen.vim
index 5db1f64c7..29e33e996 100644
--- a/runtime/plugin/matchparen.vim
+++ b/runtime/plugin/matchparen.vim
@@ -107,6 +107,7 @@ function! s:Highlight_Matching_Pair()
" certain syntax types (string, comment, etc.), for use as searchpairpos()'s
" skip argument.
" We match "escape" for special items, such as lispEscapeSpecial.
+ " Note: this may throw E363: pattern uses more memory than 'maxmempattern'
let s_skip = '!empty(filter(map(synstack(line("."), col(".")), ''synIDattr(v:val, "name")''), ' .
\ '''v:val =~? "string\\|character\\|singlequote\\|escape\\|comment"''))'
" If executing the expression determines that the cursor is currently in
@@ -114,7 +115,16 @@ function! s:Highlight_Matching_Pair()
" within those syntax types (i.e., not skip). Otherwise, the cursor is
" outside of the syntax types and s_skip should keep its value so we skip any
" matching pair inside the syntax types.
- execute 'if' s_skip '| let s_skip = 0 | endif'
+ if !has("syntax") || !exists("g:syntax_on")
+ let s:skip = 0
+ else
+ try
+ execute 'if' s_skip '| let s_skip = 0 | endif'
+ catch /^Vim\%((\a\+)\)\=:E363/
+ " We won't find anything, so skip searching, should keep Vim responsive.
+ return
+ endtry
+ endif
" Limit the search to lines visible in the window.
let stoplinebottom = line('w$')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment