Blob Blame History Raw
To: vim-dev@vim.org
Subject: Patch 7.1.269
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
------------

Patch 7.1.269
Problem:    The matchparen plugin has an arbitrary limit for the number of
	    lines to look for a match.
Solution:   Rely on the searchpair() timeout.
Files:	    runtime/plugin/matchparen.vim


*** ../vim-7.1.268/runtime/plugin/matchparen.vim	Sun Jan  6 20:05:36 2008
--- runtime/plugin/matchparen.vim	Wed Feb 27 22:39:32 2008
***************
*** 1,6 ****
  " Vim plugin for showing matching parens
  " Maintainer:  Bram Moolenaar <Bram@vim.org>
! " Last Change: 2008 Jan 06
  
  " Exit quickly when:
  " - this plugin was already loaded (or disabled)
--- 1,6 ----
  " Vim plugin for showing matching parens
  " Maintainer:  Bram Moolenaar <Bram@vim.org>
! " Last Change: 2008 Feb 27
  
  " Exit quickly when:
  " - this plugin was already loaded (or disabled)
***************
*** 34,40 ****
    endif
  
    " Avoid that we remove the popup menu.
!   if pumvisible()
      return
    endif
  
--- 34,41 ----
    endif
  
    " Avoid that we remove the popup menu.
!   " Return when there are no colors (looks like the cursor jumps).
!   if pumvisible() || (&t_Co < 8 && !has("gui_running"))
      return
    endif
  
***************
*** 60,98 ****
    endif
  
    " Figure out the arguments for searchpairpos().
-   " Restrict the search to visible lines with "stopline".
-   " And avoid searching very far (e.g., for closed folds and long lines)
-   " The "viewable" variables give a range in which we can scroll while keeping
-   " the cursor at the same position
-   " adjustedScrolloff accounts for very large numbers of scrolloff
-   let adjustedScrolloff = min([&scrolloff, (line('w$') - line('w0')) / 2])
-   let bottom_viewable = min([line('$'), c_lnum + &lines - adjustedScrolloff - 2])
-   let top_viewable = max([1, c_lnum-&lines+adjustedScrolloff + 2])
-   " one of these stoplines will be adjusted below, but the current values are
-   " minimal boundaries within the current window
-   let stoplinebottom = line('w$')
-   let stoplinetop = line('w0')
    if i % 2 == 0
      let s_flags = 'nW'
      let c2 = plist[i + 1]
-     if has("byte_offset") && has("syntax_items") && &smc > 0
-       let stopbyte = min([line2byte("$"), line2byte(".") + col(".") + &smc * 2])
-       let stopline = min([bottom_viewable, byte2line(stopbyte)])
-     else
-       let stopline = min([bottom_viewable, c_lnum + 100])
-     endif
-     let stoplinebottom = stopline
    else
      let s_flags = 'nbW'
      let c2 = c
      let c = plist[i - 1]
-     if has("byte_offset") && has("syntax_items") && &smc > 0
-       let stopbyte = max([1, line2byte(".") + col(".") - &smc * 2])
-       let stopline = max([top_viewable, byte2line(stopbyte)])
-     else
-       let stopline = max([top_viewable, c_lnum - 100])
-     endif
-     let stoplinetop = stopline
    endif
    if c == '['
      let c = '\['
--- 61,73 ----
***************
*** 111,120 ****
  	\ '=~?  "string\\|character\\|singlequote\\|comment"'
    execute 'if' s_skip '| let s_skip = 0 | endif'
  
    try
!     " Limit the search time to 500 msec to avoid a hang on very long lines.
!     let [m_lnum, m_col] = searchpairpos(c, '', c2, s_flags, s_skip, stopline, 500)
    catch /E118/
      let [m_lnum, m_col] = searchpairpos(c, '', c2, s_flags, s_skip, stopline)
    endtry
  
--- 86,132 ----
  	\ '=~?  "string\\|character\\|singlequote\\|comment"'
    execute 'if' s_skip '| let s_skip = 0 | endif'
  
+   " Limit the search to lines visible in the window.
+   let stoplinebottom = line('w$')
+   let stoplinetop = line('w0')
+   if i % 2 == 0
+     let stopline = stoplinebottom
+   else
+     let stopline = stoplinetop
+   endif
+ 
    try
!     " Limit the search time to 300 msec to avoid a hang on very long lines.
!     " This fails when a timeout is not supported.
!     let [m_lnum, m_col] = searchpairpos(c, '', c2, s_flags, s_skip, stopline, 300)
    catch /E118/
+     " Can't use the timeout, restrict the stopline a bit more to avoid taking
+     " a long time on closed folds and long lines.
+     " The "viewable" variables give a range in which we can scroll while
+     " keeping the cursor at the same position.
+     " adjustedScrolloff accounts for very large numbers of scrolloff.
+     let adjustedScrolloff = min([&scrolloff, (line('w$') - line('w0')) / 2])
+     let bottom_viewable = min([line('$'), c_lnum + &lines - adjustedScrolloff - 2])
+     let top_viewable = max([1, c_lnum-&lines+adjustedScrolloff + 2])
+     " one of these stoplines will be adjusted below, but the current values are
+     " minimal boundaries within the current window
+     if i % 2 == 0
+       if has("byte_offset") && has("syntax_items") && &smc > 0
+ 	let stopbyte = min([line2byte("$"), line2byte(".") + col(".") + &smc * 2])
+ 	let stopline = min([bottom_viewable, byte2line(stopbyte)])
+       else
+ 	let stopline = min([bottom_viewable, c_lnum + 100])
+       endif
+       let stoplinebottom = stopline
+     else
+       if has("byte_offset") && has("syntax_items") && &smc > 0
+ 	let stopbyte = max([1, line2byte(".") + col(".") - &smc * 2])
+ 	let stopline = max([top_viewable, byte2line(stopbyte)])
+       else
+ 	let stopline = max([top_viewable, c_lnum - 100])
+       endif
+       let stoplinetop = stopline
+     endif
      let [m_lnum, m_col] = searchpairpos(c, '', c2, s_flags, s_skip, stopline)
    endtry
  
*** ../vim-7.1.268/src/version.c	Sun Mar  9 14:30:12 2008
--- src/version.c	Sun Mar  9 16:21:00 2008
***************
*** 668,669 ****
--- 668,671 ----
  {   /* Add new patch number below this line */
+ /**/
+     269,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
93. New mail alarm on your palmtop annoys other churchgoers.

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///