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

[patch] fix for the Find/Replace dialog

Expand Messages
  • Thomas de Grenier de Latour
    Hi, Here is a patch that I would like you to review and consider for inclusion. It applies to vim-6.3.025. Problem: The Replace action from the :promptrepl
    Message 1 of 4 , Nov 4, 2004
    • 0 Attachment
      Hi,

      Here is a patch that I would like you to review and consider for
      inclusion. It applies to vim-6.3.025.

      Problem:
      The "Replace" action from the :promptrepl dialog use a raw string
      substitution instead of a proper s/foo/bar/ command. That means
      regexps or special replacement patterns won't work, whereas they
      work with "Search" or "Replace All" (which execute a %s/foo/bar/).
      This is confusing.

      Proposed solution:
      Execute a proper substitution command. The difficulty is that
      s/foo/bar/ would replace the first match on current line instead
      of the match under cursor. So what is done if, for instance, the
      cursor is on the 4th column, is to execute s/\(....\)foo/\1bar/
      instead. Because of that, the regular expression and the
      replacement patterns may have to be modified in case they use some
      sub-pattern references (\1, \2, etc.). This is also implemented
      (but won't work for \9 tho). Finally, once the substitution is
      done, the cursor is restored to its original position so that the
      search that is done right after takes it to the next match.

      Files: src/gui.c


      Thanks,

      --
      TGL.
    • Thomas de Grenier de Latour
      Oops, there was a mem leak with my patch because i was reusing a growing array without freeing it (i was calling ga_init instead of ga_clear). A fixed version
      Message 2 of 4 , Nov 8, 2004
      • 0 Attachment
        Oops, there was a mem leak with my patch because i was reusing a
        growing array without freeing it (i was calling ga_init instead
        of ga_clear).

        A fixed version is attached. I've also changed the regexp for
        substitution from "\(many dots...\)" to "\(.\{a number\}\)".

        --
        TGL.
      • Thomas de Grenier de Latour
        On Fri, 5 Nov 2004 00:32:14 +0100 ... Sure, if i had read the doc more in depth sooner, i would have known that there is this nice %# sequence to match the
        Message 3 of 4 , Nov 18, 2004
        • 0 Attachment
          On Fri, 5 Nov 2004 00:32:14 +0100
          Thomas de Grenier de Latour <degrenier@...> wrote:

          > The difficulty is that s/foo/bar/ would replace the first match
          > on current line instead of the match under cursor. So what is
          > done if, for instance, the cursor is on the 4th column, is to
          > execute s/\(....\)foo/\1bar/ instead.

          Sure, if i had read the doc more in depth sooner, i would have
          known that there is this nice \%# sequence to match the cursor
          position, which is exactly what was needed... Shame on me :/

          So here is a much simpler patch that uses \%# instead of the ugly
          hack above.

          --
          TGL.
        • Bram Moolenaar
          ... Note that in the current Vim 7 version (alpha version) a proper solution is used to check the length of the matched text. Your patch could be used as a
          Message 4 of 4 , Nov 18, 2004
          • 0 Attachment
            Thomas de Grenier de Latour wrote:

            > > The difficulty is that s/foo/bar/ would replace the first match
            > > on current line instead of the match under cursor. So what is
            > > done if, for instance, the cursor is on the 4th column, is to
            > > execute s/\(....\)foo/\1bar/ instead.
            >
            > Sure, if i had read the doc more in depth sooner, i would have
            > known that there is this nice \%# sequence to match the cursor
            > position, which is exactly what was needed... Shame on me :/
            >
            > So here is a much simpler patch that uses \%# instead of the ugly
            > hack above.

            Note that in the current Vim 7 version (alpha version) a proper solution
            is used to check the length of the matched text. Your patch could be
            used as a temporary solution for Vim 6.

            --
            [clop clop]
            ARTHUR: Old woman!
            DENNIS: Man!
            ARTHUR: Man, sorry. What knight lives in that castle over there?
            DENNIS: I'm thirty seven.
            ARTHUR: What?
            DENNIS: I'm thirty seven -- I'm not old!
            The Quest for the Holy Grail (Monty Python)

            /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
            /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
            \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
            \\\ Buy at Amazon and help AIDS victims -- http://ICCF.nl/click1.html ///
          Your message has been successfully submitted and would be delivered to recipients shortly.