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

Re: Silence inside functions please

Expand Messages
  • Preben Guldberg
    ... Actually it is more subtle than that - see below. ... But none of the lines matched by :global are changed or deleted. What I had not thought of when
    Message 1 of 11 , Aug 1, 2001
    View Source
    • 0 Attachment
      Thus wrote Erik Janssen (erik.janssen@...) on [010731]:
      > Preben Guldberg wrote:


      > > :g@^D \(\d\+\.\d\+ \d\d/\d\d/\d\d\) .*@
      > > s//\1/
      > > | +,/^COMMENTS:$/d
      > > | -j


      > FYI, in vm5.7 this is not going to work for multiple occurences as the
      > deletion and join mess up the marking that is done beforehand, see
      > manual page:

      Actually it is more subtle than that - see below.

      > The global commands work by first scanning through the [range] lines
      > and
      > marking each line where a match occurs. In a second scan the [cmd] is
      > executed for each marked line with its line number prepended. If a
      > line is
      > changed or deleted its mark disappears.

      But none of the lines matched by :global are changed or deleted.

      What I had not thought of when writing it up was that the search
      pattern is changed between the first and second :subsitute command.

      The way it works is

      Use :g to mark all '^D delta' lines, then for each of them carry
      out the sequence of commands, which goes (call the marks a...):

      a 1) On first marked line, use last pattern (/^D \d.../) for :s
      a 2) Deletes the next line and until /^COMMENTS:$/
      a 3) Join some lines
      DONE
      b 1) On first marked line, use last pattern (/^COMMENTS:$) for :s

      Oops, This does not match on the line matched by :global.

      Thus it is necessary to repeat the :global pattern for the :substitute
      command.

      > But I got it going by doing it in steps. Without your suggestions I
      > would not have made it. (The input as I specified it was not completely
      > correct: MR was not wrapped, version numbers are more complex and
      > comments may span multiple lines, empty line below the comment always,
      > etc)

      [--- snip ---] Thanks for the example.

      If your file only contains data, you might be able to pull it off with
      :global's like below (though there is no checks for comment lines that
      just say 'MRs:' or 'COMMENTS:' :-)

      > This is how I did it, maybe someone who was following the thread might
      > be
      > interested:

      Hmm, a couple of comments:

      > " Get the version number and the date from each line starting with D
      > g@^D \(\d\+\(\.\d\+\)\+ \d\d/\d\d/\d\d\) .*$@ s//\1/

      The '$' at the end of the pattern is not necessary - the '.*' pattern
      is so greedy that it will match until end of line anyway.

      > "Remove the MR + garbage + COMMENT
      > g/^MRs:$/,/^COMMENTS:$/d

      I assume that a 'MRs:' line always follows the 'D version' line.

      > " Join all non-empty lines
      > g/.\+/j

      > " Repeat it
      > g/.\+/j

      That was up to three lines of comments. (And I can tell you don't care
      about spaces at the end of lines (you may get one for empty lines)).

      > " Remove remaining empty lines
      > g/^$/d

      > I think the g/.\+/j twice might be replaced by g/.\+/jj

      If you want to go that route, the is no 'jj' command. Make it 'j|j'.

      Actually, you probably want one of

      1) Allow spaces at tne of line:

      :g/./,/^$/j

      2) No spaces at end of line in two steps

      :g/./,/^$/-j
      :g/^$/d

      3) No spaces at end of line in one step

      :g/./,/^$/j | s/ $//



      Anyway, with the first :s issue above sorted out, try

      g@^D \(\d\+\(\.\d\+\)\+ \d\d/\d\d/\d\d\) @
      s@^D \(\d\+\(\.\d\+\)\+ \d\d/\d\d/\d\d\) .*@\1@
      | +,/^COMMENTS:/d
      | -,/^$/j
      | s/ $//

      The :g and :s patterns need not be the same (no grouping, except for
      minor versions, are necessary), but it may be easier to maintain if
      they look the same (though I did strip out the .* part, it still lines
      up).

      Peppe
      --
      "Before you criticize someone, walk
      Preben "Peppe" Guldberg __/-\__ a mile in his shoes. That way, if
      c928400@... (o o) he gets angry, he'll be a mile away
      ----------------------oOOo (_) oOOo-- - and barefoot." --Sarah Jackson
    • Coen Engelbarts
      ... Err.., you seem to have solved this already, but I think somebody should ... i.e. Put the AWK stuff in a separate AWK-script-file .awk and run that.
      Message 2 of 11 , Aug 2, 2001
      View Source
      • 0 Attachment
        > Second question: I run an external command that is quite long:
        >
        > :r!sccs prs -e #|gawk 'very long awk script'
        >
        > It seems it is not possible to put newlines in the part that says
        > 'very long awk script'? Is there a way to do this because now I've
        > everything
        > on one line.

        Err.., you seem to have solved this already, but I think somebody should
        mention the obvious:

        :r!sccs prs -e #|gawk -f <name>.awk

        i.e. Put the AWK stuff in a separate AWK-script-file <name>.awk and run
        that. Works for me.

        On a *nix command line you can use a multi-line AWK command by putting '\'
        at the end of each line, except the last line.
        i.e.
        awk '<1st line> \
        <2nd line> \
        ...
        <last line>'
        This is not neccessary in an AWK script. I don't know if/how you can do this
        on the vim command line.

        HTH
        Coen
      • Erik Janssen
        ... [snip] ... [snip] yes, the obvious was mentioned. I did not explicitly exclude it in the original posting because I just intended to have a small question
        Message 3 of 11 , Aug 2, 2001
        View Source
        • 0 Attachment
          Coen Engelbarts wrote:
          >
          [snip]
          >
          > Err.., you seem to have solved this already, but I think somebody should
          > mention the obvious:
          >
          > :r!sccs prs -e #|gawk -f <name>.awk
          >
          > i.e. Put the AWK stuff in a separate AWK-script-file <name>.awk and run
          > that. Works for me.
          >
          [snip]

          yes, the obvious was mentioned. I did not explicitly exclude it in the
          original posting because I just intended to have a small question
          answered, not a problem solved ;-)

          I "dislike" the solution with a seperate file because my directories are
          cluttered already with all those small awk files. I tend to forget their
          use. This triggered the obvious remark by somebody else to use proper
          names. I do that pretty consequently, but I still have this memory
          problem... it's not a size issue, it's the refresh lines I'm afraid....

          In a shell script there are indeed the '' or here documents to prevent
          having to add another file. I was curious whether vim allows something
          similar.

          Anyway, i got my problem solved after all because they talked me out of
          awk and I do it all in some not so unreadable regexps now. This
          unfortunately adds some more messages while the script runs which was
          actually the real issue of my posting, hence the subject.

          well, one needs vim 6 for that and that's beta so it will have to wait a
          while.

          But I did part of the future migration by making all my scripts
          autonomous in adding mappings and menu's, i moved them to a $VIM/plugins
          directory an added this clever trick I saw on vim.sf.net yesterday
          night:

          if version < 600
          exec "source " . substitute(glob($VIM."/plugins/*.vim"), "\n",
          "\nsource ", "g")
          endif

          I can recommend this for everybody who is delaying the move.

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