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

Silence inside functions please

Expand Messages
  • Erik Janssen
    hello all, I m writing some functions to view diff info from the version control system (sccs). This involves some messing around with buffers, like creating
    Message 1 of 11 , Jul 31, 2001
      hello all,

      I'm writing some functions to view diff info from the version control
      system (sccs). This involves some messing around with buffers, like
      creating one if it did not exist, and some :b commands to ensure that #
      has a value. My problem is that a message is displayed during after the
      :b commands. This does not look neat. How do I switch this off? Can't
      find it in the help.

      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.

      I use vim 5.7.


      Thanks,

      Erik.
    • Erik Janssen
      ... Yeah, of course. I forgot to say that I didn t like that because I tend to forget the purpose/existence of those small scripts which clutter up everywhere.
      Message 2 of 11 , Jul 31, 2001
        Bohdan Vlasyuk wrote:
        >

        > > 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'?
        > I guess no..
        >
        > > Is there a way to do this because now I've everything on one line.
        > Put it into file [say, /usr/share/vim/....], and let gawk to read
        > commands from file.
        >
        Yeah, of course. I forgot to say that I didn't like that because I tend
        to
        forget the purpose/existence of those small scripts which clutter up
        everywhere.
        I do it in awk because I can't express it in vim, but it should be in
        the vim function in my opinion. Suggestion appreciated, however ;-)

        Erik.
      • Bohdan Vlasyuk
        ... What about `maningfull names ;-). What about doing so: !echo sed s/foo/ bar// ^ ... sed s/foo/bar// ... Well, it depends on what you do in awk.. I
        Message 3 of 11 , Jul 31, 2001
          On Tue, Jul 31, 2001 at 12:55:37PM +0200, Erik Janssen wrote:


          >>> Is there a way to do this because now I've everything on one line.
          >> Put it into file [say, /usr/share/vim/....], and let gawk to read
          >> commands from file.
          > Yeah, of course. I forgot to say that I didn't like that because I
          > tend to forget the purpose/existence of those small scripts which
          > clutter up everywhere.
          What about `maningfull names' ;-).

          What about doing so:

          !echo sed 's/foo/
          \bar//'
          ^
          you see, that `/' in the forst line kills last \n, so it produces:
          :so % ->
          :!echo sed 's/foo/bar//'
          sed s/foo/bar//

          > I do it in awk because I can't express it in vim, but it should be
          > in the vim function in my opinion. Suggestion appreciated, however
          > ;-)
          Well, it depends on what you do in awk.. I guess you may start using
          sed before Vim scripts.

          --
          Where humor is concerned there are no standards -- no one can say what
          is good or bad, although you can be sure that everyone will.
          -- John Kenneth Galbraith
        • Erik Janssen
          ... Well, I could have expected that one, couldn t I? ;-) Actually, I even add a comment to the script itself about what it does and who calls it. I still
          Message 4 of 11 , Jul 31, 2001
            Bohdan Vlasyuk wrote:
            >
            > On Tue, Jul 31, 2001 at 12:55:37PM +0200, Erik Janssen wrote:
            >
            > >>> Is there a way to do this because now I've everything on one line.
            > >> Put it into file [say, /usr/share/vim/....], and let gawk to read
            > >> commands from file.
            > > Yeah, of course. I forgot to say that I didn't like that because I
            > > tend to forget the purpose/existence of those small scripts which
            > > clutter up everywhere.
            > What about `maningfull names' ;-).

            Well, I could have expected that one, couldn't I? ;-) Actually, I 'even'
            add a comment to the script itself about what it does and who calls it.
            I still think it is no fun to have all these small files around.
            >
            > What about doing so:
            >
            > !echo sed 's/foo/
            > \bar//'
            > ^
            > you see, that `/' in the forst line kills last \n, so it produces:
            > :so % ->
            > :!echo sed 's/foo/bar//'
            > sed s/foo/bar//


            Thanks. That's it. I was messing with \'s on the last positions
            The rest of this mail is off-topic.

            >
            > > I do it in awk because I can't express it in vim, but it should be
            > > in the vim function in my opinion. Suggestion appreciated, however
            > > ;-)
            > Well, it depends on what you do in awk.. I guess you may start using
            > sed before Vim scripts.

            I'm not on guru level with vim and sed, so I tend to !gawk a lot.
            Anyway, to defend myself I'll go into detail :-). (You're allowed to
            delete this mail now) I make a conversion from (multiple occurences of)

            D 1.3 01/07/13 11:35:26 erjansse 4 3 00585/00412/02476
            MRs:
            COMMENTS:
            cr10395 Manually synchronised with changes in ascii version

            to (multiple occurences of):

            1.3 01/07/13 cr10395 Manually synchronised with changes in ascii
            version

            which I do in awk like this, which is in my opinion a
            reasonable trade-off between shortness and readability:

            state == 2 { print delta, date, comment; state = 0; next}
            $1 ~ /D/ {delta = $2; date = $3; next}
            state == 1 { comment = $0; state = 2; next}
            /COMMENTS:/ {state = 1}


            If you can give enlightment on the appropriate
            oneliner in sed or a vim alternative without obscurities
            like "normal W"xyWW"yyW" in it (to get the 1.3 and the
            date in reg x and y), I promise I'll abandon awk. Please don't
            waste valuable time on this, i'll manage anyway ;-)
          • Preben Guldberg
            ... Is the above one or two lines? (Can t realy tell if it was wrapped, though the trailing spaces on the first line might indicate this.) ... Hmm. I am not an
            Message 5 of 11 , Jul 31, 2001
              Thus wrote Erik Janssen (erik.janssen@...) on [010731]:

              > I'm not on guru level with vim and sed, so I tend to !gawk a lot.
              > Anyway, to defend myself I'll go into detail :-). (You're allowed to
              > delete this mail now) I make a conversion from (multiple occurences of)

              > D 1.3 01/07/13 11:35:26 erjansse 4 3 00585/00412/02476
              > MRs:

              Is the above one or two lines? (Can't realy tell if it was wrapped,
              though the trailing spaces on the first line might indicate this.)

              > COMMENTS:
              > cr10395 Manually synchronised with changes in ascii version

              > to (multiple occurences of):

              > 1.3 01/07/13 cr10395 Manually synchronised with changes in ascii
              > version

              > which I do in awk like this, which is in my opinion a
              > reasonable trade-off between shortness and readability:

              > state == 2 { print delta, date, comment; state = 0; next}
              > $1 ~ /D/ {delta = $2; date = $3; next}
              > state == 1 { comment = $0; state = 2; next}
              > /COMMENTS:/ {state = 1}

              Hmm. I am not an awk man, but I think I get this.

              Just out of curiosity, would the "/D/" not match any line with a D?

              > If you can give enlightment on the appropriate
              > oneliner in sed or a vim alternative without obscurities
              > like "normal W"xyWW"yyW" in it (to get the 1.3 and the
              > date in reg x and y), I promise I'll abandon awk. Please don't
              > waste valuable time on this, i'll manage anyway ;-)

              I will assume a non-indented text like the following:

              --- Example IN ---
              D 1.3 01/07/13 11:35:26 erjansse 4 3 00585/00412/02476 MRs:
              COMMENTS:
              cr10395 Manually synchronised with changes in ascii version
              --- Example OUT ---

              So the "D" must be the first letter of the line, followed by a space.
              "COMMENTS:" must be on a line of its own and the actual comment is a
              one liner.

              In vim prior to the vim 6 development series, I would use the
              following command (join to make it one line or prepend lines 2-4 with
              a '\' in a script)

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

              The :g/pattern/ is checking for "D" at start of line, the delta
              number and a date - all in a tight space delimited format. I have
              grouped the delta version and date for reuse with the following
              :substitute (which, btw is the reason to add ".*" at the end so all
              line is matched).

              The :substitute command then replaces the line with the mentioned
              group (by reusing the latest search pattern).

              Then a tricky bit:

              ¦ Followup with a command, nested under the :global
              + Range starting at next line
              , Range delimiter, use "," to make it relevant to
              current position (the line matched by :global
              /re/ End range at next line with only the string "COMMENTS:"
              d Delete the lines in the range

              Now the current line is the one following the deleted range, so we
              join the previous line (matched by :global, and this line with "-join"


              In vim 6 (not in release state, standard disclaimers apply), you can
              get away with a :global and a :substitute line

              :g@^D \(\d\+.\d\+ \d\d/\d\d/\d\d\) \_.\{-}\nCOMMENTS:\n\(.*\)@s//\1 \2/

              The advatange is that you can add the requirements of a following
              "COMMENTS:" line (here any number of lines down, replace '\_.\{-}'
              with '.*' if it has to be on the next line).

              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
            • Erik Janssen
              Thanks Bohdan and Preben, As promised, I ll abandon awk on this one ;-) I learned a lot. If any of you also know how to inhibit status messages during function
              Message 6 of 11 , Jul 31, 2001
                Thanks Bohdan and Preben,

                As promised, I'll abandon awk on this one ;-)

                I learned a lot.

                If any of you also know how to inhibit status messages during function
                execution, I'd be most happy.

                Erik.
              • Preben Guldberg
                ... Oh well, if you speak awk fluently, I guess you can perform your magic using that. ... Great :-) ... Depends on the kind of messages and vim version. My
                Message 7 of 11 , Jul 31, 2001
                  Thus wrote Erik Janssen (erik.janssen@...) on [010731]:

                  > As promised, I'll abandon awk on this one ;-)

                  Oh well, if you speak awk fluently, I guess you can perform your magic
                  using that.

                  > I learned a lot.

                  Great :-)

                  > If any of you also know how to inhibit status messages during function
                  > execution, I'd be most happy.

                  Depends on the kind of messages and vim version. My usual suspect is
                  :substitute, for which you can set the 'report' option to a huge
                  number.

                  Vim 6 introduces the :silent command. You can even use it with :redir
                  to capture output without displaying it.

                  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
                • Erik Janssen
                  ... 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: The
                  Message 8 of 11 , Jul 31, 2001
                    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:

                    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 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)

                    --- Example IN ---
                    D 1.13.1.1 00/07/13 13:26:57 jbaauw 19 17 00675/00534/00803<CR>
                    MRs:<CR>
                    multiline<CR>
                    garbage<CR>
                    COMMENTS:<CR>
                    multi<CR>
                    line comment<CR>
                    <CR>
                    --- Example OUT ----
                    more of these entries may follow......

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

                    " 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/

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

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

                    " Repeat it
                    g/.\+/j

                    " Remove remaining empty lines
                    g/^$/d

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


                    So I did not do anything usefull today except creating some nice
                    functions to
                    compare the current buffer with the last delta in SCCS, or with a delta
                    selectable from a list (that's what the discussion was for), or compare
                    two user selectable delta's which each other. What a day.

                    Erik.
                  • 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 9 of 11 , Aug 1, 2001
                      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 10 of 11 , Aug 2, 2001
                        > 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 11 of 11 , Aug 2, 2001
                          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.