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

Re: [PATCH] new flags for the search() function

Expand Messages
  • Benji Fisher
    ... OK, I will try another draft at the bottom of this note. ... That project is too ambitious for me (at least for now). ... I guess a file is not allowed to
    Message 1 of 13 , Nov 30, 2005
      On Wed, Nov 30, 2005 at 08:29:40PM +0100, Bram Moolenaar wrote:
      >
      > Benji Fisher wrote:
      >
      > The example looks fine to me. But I'm not sure if the explanation is
      > clear, e.g., what "keyword at the current cursor position" means
      > exactly. Perhaps a few snippets of example text will help.

      OK, I will try another draft at the bottom of this note.

      > > I have updated the patch to add Yet Another Flag: 'c' tells the
      > > function (search() or searchpair()) to return the column number of the
      > > match instead of the line number. (Give an error message if combined
      > > with 'p' or 'm'.)
      >
      > Alternative: add a new function that returns a list with both the line
      > and column number. Otherwise you would need to search twice to get
      > both.
      >
      > :let [lnum, col] = search???()

      That project is too ambitious for me (at least for now).

      > > rettv->vval.v_number = (flags & S_SUBPAT) ? subpatnum :
      > > ((flags & SP_RETCOLUMN) ? 1 + pos.col : pos.lnum);
      > >
      > > v_number varnumber_T int or long (if SIZEOF_INT <= 3)
      > > pos.lnum linenr_T long
      >
      > Yes, casts are needed here to avoid a warning message from some
      > compilers.

      I guess a file is not allowed to have more than 2^31 - 1 lines, so
      there is not really a danger of truncation when assigning a long to an
      int. I will leave this one alone.

      Here is another attempt at documenting the new flags:

      Example of flags. >
      :echo search('\<if\|\(else\)\|\(endif\)', 'nape')
      < will search for the keywords "if", "else", and "endif" under
      or after the cursor. Because of the 'p' flag, it returns 1,
      2, or 3 depending on which keyword is found, or 0 if the
      search fails. With the cursor on the first word of the line >
      if (foo == 0) | let foo = foo + 1 | endif
      < the function returns 1. Without the 'a' flag, the function
      finds the "endif" and returns 3. The same thing happens
      without the 'e' flag if the cursor is on the "f" of "if".
      The 'n' flag tells the function not to move the cursor.

      --Benji Fisher
    • Zdenek Sekera
      ... You are doing all right, Benji! ... Yes, little harder to read, though not impossible, perhaps a few more simple(r) examples to go with it? ... I can t
      Message 2 of 13 , Dec 1 12:01 AM
        > From: Benji Fisher [mailto:benji@...]
        ...
        > > >
        > > > How about an even longer paragraph that illustrates
        > most of the
        > > > flags? (Bram, if you like this explanation and it will
        > save you some
        > > > effort, I can make an updated patch.)
        > >
        > > I find the example a bit long, takes a bit of reading to understand.
        > > And it looks like the action can be done with one command
        > > ":%s/foo/bar/ge". Am I missing something? I'm sure it is
        > possible to
        > > come up with a shorter example that shows the use of the flags.
        >
        > I may not be able to satisfy both of you when it comes to
        > documentation!

        You are doing all right, Benji!

        > My current suggestion includes a shorter, less
        > comprehensive, more interesting example:
        >
        > Example of flags. >
        > :echo search('\<if\|\(else\)\|\(endif\)', 'nape')
        > < will search for the keywords "if", "else", and
        > "endif" under
        > or after the cursor. Because of the 'p' flag,
        > it returns 1,
        > 2, or 3 depending on which keyword is found, or 0 if the
        > search fails. Without the 'a' and 'e' flags,
        > this will not
        > find a keyword at the current cursor position;
        > with the 'a'
        > flag but not the 'e' flag, it will not find the
        > keyword under
        > the cursor if the cursor is in the middle or
        > end of the word.
        > The 'n' flag tells the function not to move the cursor.
        >

        Yes, little harder to read, though not impossible, perhaps a few
        more simple(r) examples to go with it?

        > I have updated the patch to add Yet Another Flag: 'c' tells the
        > function (search() or searchpair()) to return the column number of the
        > match instead of the line number. (Give an error message if combined
        > with 'p' or 'm'.)
        >

        I can't think at this minute when would I need to use it, however,
        I would imagine that knowing both *line* and *column* of the match
        should be *very* useful. I know it's not obvious to return two values,
        perhaps 'line:column' format or similar?

        Cheers,

        ---Zdenek
      • Zdenek Sekera
        ... Hmmm, we agree (see my previous email) :-) ... Agreed again (see my previous email), what a day! :-):-)
        Message 3 of 13 , Dec 1 12:47 AM
          > -----Original Message-----
          > From: Bram@... [mailto:Bram@...]
          > Sent: 30 November 2005 20:30
          > To: Benji Fisher
          > Cc: vim-dev@...
          > Subject: Re: [PATCH] new flags for the search() function
          >
          >
          > Benji Fisher wrote:
          >
          > > I may not be able to satisfy both of you when it comes to
          > > documentation! My current suggestion includes a shorter, less
          > > comprehensive, more interesting example:
          >
          > The example looks fine to me. But I'm not sure if the explanation is
          > clear, e.g., what "keyword at the current cursor position" means
          > exactly. Perhaps a few snippets of example text will help.
          >

          Hmmm, we agree (see my previous email) :-)

          > > I have updated the patch to add Yet Another Flag: 'c'
          > tells the
          > > function (search() or searchpair()) to return the column
          > number of the
          > > match instead of the line number. (Give an error message
          > if combined
          > > with 'p' or 'm'.)
          >
          > Alternative: add a new function that returns a list with both the line
          > and column number. Otherwise you would need to search twice to get
          > both.
          >
          > :let [lnum, col] = search???()
          >

          Agreed again (see my previous email), what a day! :-):-)

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