Loading ...
Sorry, an error occurred while loading the content.
 

patch - enable 'p' flag for searchpair

Expand Messages
  • ap
    Hi, I put a small patch together, which enables the p flag for searchpair() and searchpairpos(). I find it occasionally useful, to know which of the 3
    Message 1 of 2 , Feb 4, 2008
      Hi,

      I put a small patch together, which enables the 'p' flag for
      searchpair() and searchpairpos(). I find it occasionally useful, to
      know which of the 3 patterns (start,mid,end) actually matched, e.g.
      for a script that swaps function arguments. If I'm not mistaken,
      this must currently be done with (e.g.) an additional
      search('\%#...') or something else. It should not break current
      script code, because as of now the 'p' gives an error. (It would
      break code, which uses a try block to check for the given flags,
      maybe in a wrapper function....)

      let subpat = searchpair('(',',',')','p')
      let subpat = searchpairpos('(',',',')','p')[2]

      subpat is 1,2,3 or 0 if search failed. 'p' and 'm' are mutually
      exclusive.


      http://www.fh-trier.de/~politza/vim/patch_sp_pflag.diff


      -ap

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_dev" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Bram Moolenaar
      ... I m a bit confused. When searching forward, wouldn t the result always be 3? And when searching backward always 1? -- I think that you ll agree that
      Message 2 of 2 , Feb 6, 2008
        A.Politz wrote:

        > I put a small patch together, which enables the 'p' flag for
        > searchpair() and searchpairpos(). I find it occasionally useful, to
        > know which of the 3 patterns (start,mid,end) actually matched, e.g.
        > for a script that swaps function arguments. If I'm not mistaken,
        > this must currently be done with (e.g.) an additional
        > search('\%#...') or something else. It should not break current
        > script code, because as of now the 'p' gives an error. (It would
        > break code, which uses a try block to check for the given flags,
        > maybe in a wrapper function....)
        >
        > let subpat = searchpair('(',',',')','p')
        > let subpat = searchpairpos('(',',',')','p')[2]
        >
        > subpat is 1,2,3 or 0 if search failed. 'p' and 'm' are mutually
        > exclusive.
        >
        >
        > http://www.fh-trier.de/~politza/vim/patch_sp_pflag.diff

        I'm a bit confused. When searching forward, wouldn't the result always
        be 3? And when searching backward always 1?

        --
        I think that you'll agree that engineers are very effective in their social
        interactions. It's the "normal" people who are nuts.
        (Scott Adams - The Dilbert principle)

        /// Bram Moolenaar -- Bram@... -- 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 ///

        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_dev" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      Your message has been successfully submitted and would be delivered to recipients shortly.