Blame SOURCES/7.4.397

22c937
To: vim_dev@googlegroups.com
22c937
Subject: Patch 7.4.397
22c937
Fcc: outbox
22c937
From: Bram Moolenaar <Bram@moolenaar.net>
22c937
Mime-Version: 1.0
22c937
Content-Type: text/plain; charset=UTF-8
22c937
Content-Transfer-Encoding: 8bit
22c937
------------
22c937
22c937
Patch 7.4.397
22c937
Problem:    Matchparen only uses the topmost syntax item.
22c937
Solution:   Go through the syntax stack to find items. (James McCoy)
22c937
            Also use getcurpos() when possible.
22c937
Files:      runtime/plugin/matchparen.vim
22c937
22c937
22c937
*** ../vim-7.4.396/runtime/plugin/matchparen.vim	2014-06-17 17:48:21.772628007 +0200
22c937
--- runtime/plugin/matchparen.vim	2014-08-06 19:02:04.967128364 +0200
22c937
***************
22c937
*** 1,6 ****
22c937
  " Vim plugin for showing matching parens
22c937
  " Maintainer:  Bram Moolenaar <Bram@vim.org>
22c937
! " Last Change: 2014 Jun 17
22c937
  
22c937
  " Exit quickly when:
22c937
  " - this plugin was already loaded (or disabled)
22c937
--- 1,6 ----
22c937
  " Vim plugin for showing matching parens
22c937
  " Maintainer:  Bram Moolenaar <Bram@vim.org>
22c937
! " Last Change: 2014 Jul 19
22c937
  
22c937
  " Exit quickly when:
22c937
  " - this plugin was already loaded (or disabled)
22c937
***************
22c937
*** 54,67 ****
22c937
    let c_col = col('.')
22c937
    let before = 0
22c937
  
22c937
!   let c = getline(c_lnum)[c_col - 1]
22c937
    let plist = split(&matchpairs, '.\zs[:,]')
22c937
    let i = index(plist, c)
22c937
    if i < 0
22c937
      " not found, in Insert mode try character before the cursor
22c937
      if c_col > 1 && (mode() == 'i' || mode() == 'R')
22c937
        let before = 1
22c937
!       let c = getline(c_lnum)[c_col - 2]
22c937
        let i = index(plist, c)
22c937
      endif
22c937
      if i < 0
22c937
--- 54,68 ----
22c937
    let c_col = col('.')
22c937
    let before = 0
22c937
  
22c937
!   let text = getline(c_lnum)
22c937
!   let c = text[c_col - 1]
22c937
    let plist = split(&matchpairs, '.\zs[:,]')
22c937
    let i = index(plist, c)
22c937
    if i < 0
22c937
      " not found, in Insert mode try character before the cursor
22c937
      if c_col > 1 && (mode() == 'i' || mode() == 'R')
22c937
        let before = 1
22c937
!       let c = text[c_col - 2]
22c937
        let i = index(plist, c)
22c937
      endif
22c937
      if i < 0
22c937
***************
22c937
*** 87,100 ****
22c937
    " Find the match.  When it was just before the cursor move it there for a
22c937
    " moment.
22c937
    if before > 0
22c937
!     let save_cursor = winsaveview()
22c937
      call cursor(c_lnum, c_col - before)
22c937
    endif
22c937
  
22c937
!   " When not in a string or comment ignore matches inside them.
22c937
    " We match "escape" for special items, such as lispEscapeSpecial.
22c937
!   let s_skip ='synIDattr(synID(line("."), col("."), 0), "name") ' .
22c937
! 	\ '=~?  "string\\|character\\|singlequote\\|escape\\|comment"'
22c937
    execute 'if' s_skip '| let s_skip = 0 | endif'
22c937
  
22c937
    " Limit the search to lines visible in the window.
22c937
--- 88,114 ----
22c937
    " Find the match.  When it was just before the cursor move it there for a
22c937
    " moment.
22c937
    if before > 0
22c937
!     let has_getcurpos = exists("*getcurpos")
22c937
!     if has_getcurpos
22c937
!       " getcurpos() is more efficient but doesn't exist before 7.4.313.
22c937
!       let save_cursor = getcurpos()
22c937
!     else
22c937
!       let save_cursor = winsaveview()
22c937
!     endif
22c937
      call cursor(c_lnum, c_col - before)
22c937
    endif
22c937
  
22c937
!   " Build an expression that detects whether the current cursor position is in
22c937
!   " certain syntax types (string, comment, etc.), for use as searchpairpos()'s
22c937
!   " skip argument.
22c937
    " We match "escape" for special items, such as lispEscapeSpecial.
22c937
!   let s_skip = '!empty(filter(map(synstack(line("."), col(".")), ''synIDattr(v:val, "name")''), ' .
22c937
! 	\ '''v:val =~? "string\\|character\\|singlequote\\|escape\\|comment"''))'
22c937
!   " If executing the expression determines that the cursor is currently in
22c937
!   " one of the syntax types, then we want searchpairpos() to find the pair
22c937
!   " within those syntax types (i.e., not skip).  Otherwise, the cursor is
22c937
!   " outside of the syntax types and s_skip should keep its value so we skip any
22c937
!   " matching pair inside the syntax types.
22c937
    execute 'if' s_skip '| let s_skip = 0 | endif'
22c937
  
22c937
    " Limit the search to lines visible in the window.
22c937
***************
22c937
*** 147,153 ****
22c937
    endtry
22c937
  
22c937
    if before > 0
22c937
!     call winrestview(save_cursor)
22c937
    endif
22c937
  
22c937
    " If a match is found setup match highlighting.
22c937
--- 161,171 ----
22c937
    endtry
22c937
  
22c937
    if before > 0
22c937
!     if has_getcurpos
22c937
!       call setpos('.', save_cursor)
22c937
!     else
22c937
!       call winrestview(save_cursor)
22c937
!     endif
22c937
    endif
22c937
  
22c937
    " If a match is found setup match highlighting.
22c937
*** ../vim-7.4.396/src/version.c	2014-08-06 18:17:03.475147780 +0200
22c937
--- src/version.c	2014-08-06 19:06:44.627126354 +0200
22c937
***************
22c937
*** 743,744 ****
22c937
--- 743,746 ----
22c937
  {   /* Add new patch number below this line */
22c937
+ /**/
22c937
+     397,
22c937
  /**/
22c937
22c937
-- 
22c937
Often you're less important than your furniture.  If you think about it, you
22c937
can get fired but your furniture stays behind, gainfully employed at the
22c937
company that didn't need _you_ anymore.
22c937
				(Scott Adams - The Dilbert principle)
22c937
22c937
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
22c937
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
22c937
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
22c937
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///