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

Re: searchpair bug?

Expand Messages
  • Colin Keith
    ... Given that Bram probably knows a Vim bug when he sees one and I wouldn t know one if it smacked me around the side of the head, this is probably wrong...
    Message 1 of 5 , Apr 29, 2002
    • 0 Attachment
      On Mon, Apr 29, 2002 at 02:00:29PM -0700, Gary Holloway wrote:
      > 12:endif
      > 13:
      > 14:if
      > 15:else
      > 16:endif
      >
      > :echo searchpair('if', 'else', 'endif', 'bWn')
      >
      > and I get 12!
      >
      > Bug?

      Given that Bram probably knows a Vim bug when he sees one and I wouldn't know
      one if it smacked me around the side of the head, this is probably wrong...
      but it occurred to me that it might be worth pointing out that line 12 does
      contain an 'if'. You're only doing a pattern match with no anchors, so is it
      not correct to match against the 'if' in 'endif'? If you match against '\<if\>'
      it works correctly, returning 0. ... ?


      Colin.
    • Bram Moolenaar
      ... You are completely right, of course. The problem is in the example of the searchpair() help. It doesn t mention the . -- Life is a gift, living
      Message 2 of 5 , Apr 30, 2002
      • 0 Attachment
        Colin Keith wrote:

        > On Mon, Apr 29, 2002 at 02:00:29PM -0700, Gary Holloway wrote:
        > > 12:endif
        > > 13:
        > > 14:if
        > > 15:else
        > > 16:endif
        > >
        > > :echo searchpair('if', 'else', 'endif', 'bWn')
        > >
        > > and I get 12!
        > >
        > > Bug?
        >
        > Given that Bram probably knows a Vim bug when he sees one and I
        > wouldn't know one if it smacked me around the side of the head, this
        > is probably wrong... but it occurred to me that it might be worth
        > pointing out that line 12 does contain an 'if'. You're only doing a
        > pattern match with no anchors, so is it not correct to match against
        > the 'if' in 'endif'? If you match against '\<if\>' it works correctly,
        > returning 0. ... ?

        You are completely right, of course. The problem is in the example of
        the searchpair() help. It doesn't mention the \< and \>.

        --
        Life is a gift, living is an art. (Bram Moolenaar)

        /// Bram Moolenaar -- Bram@... -- http://www.moolenaar.net \\\
        /// Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim \\\
        \\\ Project leader for A-A-P -- http://www.a-a-p.org ///
        \\\ Help me helping AIDS orphans in Uganda - http://iccf-holland.org ///
      • Gary Holloway
        / FROM: Bram Moolenaar , Apr 30 13:47 2002 ... [snip] ... [snip] END: Bram Moolenaar Of course (duh :), sorry bout that. I was trying
        Message 3 of 5 , Apr 30, 2002
        • 0 Attachment
          / FROM: Bram Moolenaar <Bram@...>, Apr 30 13:47 2002
          | ABOUT: Re: searchpair bug?
          |
          | Colin Keith wrote:
          |
          | > On Mon, Apr 29, 2002 at 02:00:29PM -0700, Gary Holloway wrote:
          | > > 12:endif
          | > > 13:
          | > > 14:if
          | > > 15:else
          | > > 16:endif
          | > >
          | > > :echo searchpair('if', 'else', 'endif', 'bWn')
          | > >
          | > > and I get 12!
          | > >
          | > > Bug?
          | >
          [snip]
          | > You're only doing a
          | > pattern match with no anchors, so is it not correct to match against
          | > the 'if' in 'endif'? If you match against '\<if\>' it works correctly,
          | > returning 0. ... ?
          |
          | You are completely right, of course. The problem is in the example of
          | the searchpair() help. It doesn't mention the \< and \>.
          |
          [snip]
          \ END: Bram Moolenaar

          Of course (duh :), sorry 'bout that.

          I was trying to simplify my real situation:

          searchpair('\%(\i\+\>\%(\*\|\s\)*\)\+(\s*\%(\%(\%(,\s*\)\?\i\+\>\%(\*\|\s\)*\)\+\|\%(\%(\n[^)].*\)*\n\)\)\?)\n{', '', '^}', 'bWn')

          But it turns out it's really the same problem; adding the '^' anchor to my
          start pattern in this case solves my problem.

          Thanks!

          ----------------------------------------

          However just for my curiosity... :)

          I'm still not sure why I need the ^ anchor in my "real" case; see below.

          1:/* =============================================================== */
          2:
          3:/*
          4: * STATIC FUNCTION: check_free
          5: * Free a check bag node.
          6: */
          7:
          8:static void check_free(
          9:CKType *ckptr // IN: Node to be free'd
          10:)
          11:{
          12: del_bag(ckptr->ytd_bag);
          13:
          14: free(ckptr);
          15:}
          16:
          17:/* =============================================================== */
          18:
          19:/*
          20: * STATIC FUNCTION: dealmemo_free
          21: * Free a dealmemo bag node.
          22: */
          23:
          24:static void dealmemo_free(
          25:DMType *dmptr // IN: Node to be free'd
          26:)
          27:{
          28: del_bag(dmptr->dealwci_bag );
          29: del_bag(dmptr->dealover_bag);
          30:
          31: free(dmptr);
          32:}
          33:
          34:/* =============================================================== */

          Now, sitting on any of lines 16-23, the following searchpair returns 8.

          :echo searchpair('\%(\i\+\>\%(\*\|\s\)*\)\+(\s*\%(\%(\%(,\s*\)\?\i\+\>\%(\*\|\s\)*\)\+\|\%(\%(\n[^)].*\)*\n\)\)\?)\n{', '', '^}', 'bWn')

          Searching for the start pattern is correctly locating only lines 8-11 and 24-27
          as the two matches -- whereas in my initial post's example, of course,
          searching for 'if' finds the 'if' part of 'endif' -- I should have seen that
          myself :(.

          And searching for the end pattern correctly locates only lines 15 and 32.

          So back to the original question; why is searchpair returning non-zero when
          initiated from one of lines 16-23?

          Is it because the start pattern is multi-line?

          -gary
        Your message has been successfully submitted and would be delivered to recipients shortly.