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

indentexpr - nasyy side-effects?

Expand Messages
  • Neil Bird
    Should not indentexpr be evaluated in the sandbox? I only ask as I ve been having a spurious problem with . & I ve narrowed it down to my ada indent.vim -
    Message 1 of 8 , Nov 1, 2001
    View Source
    • 0 Attachment
      Should not indentexpr be evaluated in the sandbox? I only
      ask as I've been having a spurious problem with '.' & I've
      narrowed it down to my ada indent.vim - but I can't see why or how.

      I'll attach my latest as I don't know what version was
      released with 6.0. Could someone else with vim6 try this out
      for me & see if they get the same thing? I've tried this up to
      & including my 6.0.61 build.


      vim -u NONE -U NONE
      :set nocp
      :so indent-ada.vim " attached version


      Right, now have the following three lines in the buffer:

      a : b.c;
      a : b.c;
      a : b.c;


      Position the cursor on the end of the first line, and insert
      (excluding the bounding "s):

      " := (others => ' ');"

      ... in one go.

      Do <Down> then issue '.' to insert it again. I get a beep,
      the colon & then left in insert mode!? That can't be right, can it?

      --
      [neil@fnx ~]# rm -f .signature
      [neil@fnx ~]# ls -l .signature
      ls: .signature: No such file or directory
      [neil@fnx ~]# exit
    • Zdenek Sekera
      ... ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Neil, I tried, but unfortunately :-) had no problems at all. Here is how my buffer looks after your manip above: a :
      Message 2 of 8 , Nov 1, 2001
      View Source
      • 0 Attachment
        Neil Bird wrote:
        >
        > Should not indentexpr be evaluated in the sandbox? I only
        > ask as I've been having a spurious problem with '.' & I've
        > narrowed it down to my ada indent.vim - but I can't see why or how.
        >
        > I'll attach my latest as I don't know what version was
        > released with 6.0. Could someone else with vim6 try this out
        > for me & see if they get the same thing? I've tried this up to
        > & including my 6.0.61 build.
        >
        > vim -u NONE -U NONE
        > :set nocp
        > :so indent-ada.vim " attached version
        >
        > Right, now have the following three lines in the buffer:
        >
        > a : b.c;
        > a : b.c;
        > a : b.c;
        >
        > Position the cursor on the end of the first line, and insert
        > (excluding the bounding "s):
        >
        > " := (others => ' ');"
        >
        > ... in one go.
        >
        > Do <Down> then issue '.' to insert it again. I get a beep,
        > the colon & then left in insert mode!? That can't be right, can it?
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

        Neil, I tried, but unfortunately :-) had no problems at all.

        Here is how my buffer looks after your manip above:

        a : b.c := (others => ' ');;
        a : b.c := (others => ' ');;
        a : b.c := (others => ' ');;

        Is that what it should be?

        ---Zdenek
      • Neil Bird
        ... Piddle. No, my bad: don t type an extra ; as part of the insert. *That* works fine for me too! -- [neil@fnx ~]# rm -f .signature [neil@fnx ~]# ls -l
        Message 3 of 8 , Nov 1, 2001
        View Source
        • 0 Attachment
          Zdenek Sekera wrote:

          > Neil, I tried, but unfortunately :-) had no problems at all.
          >
          > a : b.c := (others => ' ');;
          >
          > Is that what it should be?

          Piddle. No, my bad: don't type an extra ';' as part of the
          insert. *That* works fine for me too!

          --
          [neil@fnx ~]# rm -f .signature
          [neil@fnx ~]# ls -l .signature
          ls: .signature: No such file or directory
          [neil@fnx ~]# exit
        • Bram Moolenaar
          ... It is. ... Apparently the indentexpr is evaluated and causes an error. This causes the beep and the typeahead to be flushed. I would suspect the :normal
          Message 4 of 8 , Nov 1, 2001
          View Source
          • 0 Attachment
            Neil Bird wrote:

            > Should not indentexpr be evaluated in the sandbox?

            It is.

            > I only ask as I've been having a spurious problem with '.' & I've
            > narrowed it down to my ada indent.vim - but I can't see why or how.
            >
            > I'll attach my latest as I don't know what version was
            > released with 6.0. Could someone else with vim6 try this out
            > for me & see if they get the same thing? I've tried this up to
            > & including my 6.0.61 build.
            >
            >
            > vim -u NONE -U NONE
            > :set nocp
            > :so indent-ada.vim " attached version
            >
            >
            > Right, now have the following three lines in the buffer:
            >
            > a : b.c;
            > a : b.c;
            > a : b.c;
            >
            >
            > Position the cursor on the end of the first line, and insert
            > (excluding the bounding "s):
            >
            > " := (others => ' ');"
            >
            > ... in one go.
            >
            > Do <Down> then issue '.' to insert it again. I get a beep,
            > the colon & then left in insert mode!? That can't be right, can it?

            Apparently the indentexpr is evaluated and causes an error. This causes
            the beep and the typeahead to be flushed.

            I would suspect the ":normal" commands. Try putting ":silent!" before
            them, so that errors are ignored.

            --
            If you don't get everything you want, think of
            everything you didn't get and don't want.

            /// Bram Moolenaar -- Bram@... -- http://www.moolenaar.net \\\
            ((( Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim )))
            \\\ Help me helping AIDS orphans in Uganda - http://iccf-holland.org ///
          • Neil Bird
            ... Well, I can kind of see where things are happening now, but ... I ve :debug d though GetAdaIndent() which is the indentexpr, and don t get any errors (even
            Message 5 of 8 , Nov 2, 2001
            View Source
            • 0 Attachment
              Bram Moolenaar wrote:

              > Apparently the indentexpr is evaluated and causes an error. This causes
              > the beep and the typeahead to be flushed.


              Well, I can kind of see where things are happening now, but ...

              I've :debug'd though GetAdaIndent() which is the indentexpr,
              and don't get any errors (even without 'silent!'). The lines in
              question would seem to be (simplified):

              " Get default indent (from prev. line)
              let ind = indent(lnum)

              " Now check what's on the previous line
              ...
              elseif line =~ ')\s*[;,]\s*$'
              " Revert to indent of line that started this ()
              let b:jobby = 'normal! ' . lnum . 'G$F)%'
              exe 'normal! ' . lnum . 'G$F)%'
              let b:last_error = v:errmsg
              let ind = indent('.')
              exe 'normal! ' . v:lnum . 'G'


              The variables are my debug, not having those statements
              doesn't change things.

              All this does is, if the previous line effectively ends with
              a ')', go to the line, get to the ), do a *raw* % (normal!) and
              find the indent of the line found.

              I can see this being triggered in this case (as the last line
              *does* end ");"), but the match should be on the same line. And
              using normal! shouldn't be triggering any funny mappings: just
              the lnum.'G$)F%'.


              Further: if I comment out that last 'normal!' (which returns
              to the 'crrent' line, v:lnum) I don't see the problem. I only
              put that in for safety's sake, in case something later assumed
              that the cursor was correctly located. I may take that out for now.


              a) *How* can a v:lnum . 'G' cause an error? Esp. when
              v:lnum def. exists and is a valid line.
              b) Why does it not cause an error if I :debug echo
              GetAdaIndent() at the right point - isn't that all indentexpr does?
              c) OT: is there something I can replace the G's with so that
              I don't affect the last-pos (``) history, which I seem to be
              doing looking at it?


              > I would suspect the ":normal" commands. Try putting ":silent!" before
              > them, so that errors are ignored.

              That stops the beep - but it still won't insert all the text,
              stopping in insert mode after the ':'.

              --
              [neil@fnx ~]# rm -f .signature
              [neil@fnx ~]# ls -l .signature
              ls: .signature: No such file or directory
              [neil@fnx ~]# exit
            • Bram Moolenaar
              ... Using :debug only steps through : commands. If you use :normal it s executed as one command. Then the error flag is cleared, thus the behavior when
              Message 6 of 8 , Nov 2, 2001
              View Source
              • 0 Attachment
                Neil Bird wrote:

                > Well, I can kind of see where things are happening now, but ...
                >
                > I've :debug'd though GetAdaIndent() which is the indentexpr,
                > and don't get any errors (even without 'silent!'). The lines in
                > question would seem to be (simplified):

                Using ":debug" only steps through ":" commands. If you use ":normal"
                it's executed as one command. Then the error flag is cleared, thus the
                behavior when debugging might be a bit different. That's the problem of
                debugging Vim using the program itself.

                > " Get default indent (from prev. line)
                > let ind = indent(lnum)
                >
                > " Now check what's on the previous line
                > ...
                > elseif line =~ ')\s*[;,]\s*$'
                > " Revert to indent of line that started this ()
                > let b:jobby = 'normal! ' . lnum . 'G$F)%'
                > exe 'normal! ' . lnum . 'G$F)%'
                > let b:last_error = v:errmsg
                > let ind = indent('.')
                > exe 'normal! ' . v:lnum . 'G'
                >
                >
                > The variables are my debug, not having those statements
                > doesn't change things.
                >
                > All this does is, if the previous line effectively ends with
                > a ')', go to the line, get to the ), do a *raw* % (normal!) and
                > find the indent of the line found.

                If there is no matching "(" you will get an error here. Isn't that the
                problem? Although, the insert stops after inserting the ":", thus I
                would expect a problem with that, not with the ")".

                > Further: if I comment out that last 'normal!' (which returns
                > to the 'crrent' line, v:lnum) I don't see the problem. I only
                > put that in for safety's sake, in case something later assumed
                > that the cursor was correctly located. I may take that out for now.

                Strange, I would not suspect that line to cause a problem.

                > c) OT: is there something I can replace the G's with so that
                > I don't affect the last-pos (``) history, which I seem to be
                > doing looking at it?

                Use ":{linenr}".

                > > I would suspect the ":normal" commands. Try putting ":silent!" before
                > > them, so that errors are ignored.
                >
                > That stops the beep - but it still won't insert all the text,
                > stopping in insert mode after the ':'.

                Perhaps you need another ":silent!".

                --
                Westheimer's Discovery:
                A couple of months in the laboratory can
                frequently save a couple of hours in the library.

                /// Bram Moolenaar -- Bram@... -- http://www.moolenaar.net \\\
                ((( Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim )))
                \\\ Help me helping AIDS orphans in Uganda - http://iccf-holland.org ///
              • Neil Bird
                ... I must ve deluded myself with that one; taking it out now doesn t seem to fix it after all. I really don t understand this. I ve whittled it down, and it
                Message 7 of 8 , Nov 2, 2001
                View Source
                • 0 Attachment
                  On 11/02/01 11:38, Bram Moolenaar wrote:

                  >> Further: if I comment out that last 'normal!' (which returns
                  >>to the 'curent' line, v:lnum) I don't see the problem.
                  >
                  > Strange, I would not suspect that line to cause a problem.


                  I must've deluded myself with that one; taking it out now
                  doesn't seem to fix it after all.

                  I really don't understand this. I've whittled it down, and
                  it /does/ appear to be the 1st. normal!. It *still* causes an
                  error even if I only do 'normal! $', with no line jumping!

                  Hang on ...

                  Right, here's a rock-bottom cut-down case; looks like
                  indentexpr (sandbox?) can't cope with 'normal $' [maybe as it's
                  called from 'insert' mode?].



                  Load the attached file:

                  vim -u NONE -U NONE indent-test
                  :so %


                  Then @a and finally . (to repeat the insertion).


                  --
                  =================- http://www.thalesgroup.com/ -================
                  Neil Bird Principal Engineer |
                  work - mailto:neil.bird@... | $> cd /pub
                  personal - mailto:neil@... | $> more beer

                  --
                  [neil@fnx ~]# rm -f .signature
                  [neil@fnx ~]# ls -l .signature
                  ls: .signature: No such file or directory
                  [neil@fnx ~]# exit
                • Bram Moolenaar
                  ... Thanks for the clear example. I now see what goes wrong: The redone text is put in the stuff buffer, which the :normal command reads before getting to
                  Message 8 of 8 , Nov 2, 2001
                  View Source
                  • 0 Attachment
                    Neil Bird wrote:

                    > I really don't understand this. I've whittled it down, and
                    > it /does/ appear to be the 1st. normal!. It *still* causes an
                    > error even if I only do 'normal! $', with no line jumping!
                    >
                    > Hang on ...
                    >
                    > Right, here's a rock-bottom cut-down case; looks like
                    > indentexpr (sandbox?) can't cope with 'normal $' [maybe as it's
                    > called from 'insert' mode?].
                    >
                    >
                    >
                    > Load the attached file:
                    >
                    > vim -u NONE -U NONE indent-test
                    > :so %
                    >
                    >
                    > Then @a and finally . (to repeat the insertion).

                    Thanks for the clear example. I now see what goes wrong: The redone
                    text is put in the stuff buffer, which the ":normal" command reads
                    before getting to the "$".

                    This requires saving and restoring the stuff buffer inside the ":normal"
                    command. I'll make a patch for it.

                    --
                    It is too bad that the speed of light hasn't kept pace with the
                    changes in CPU speed and network bandwidth. -- <wietse@...>

                    /// Bram Moolenaar -- Bram@... -- http://www.moolenaar.net \\\
                    ((( Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim )))
                    \\\ Help me helping AIDS orphans in Uganda - http://iccf-holland.org ///
                  Your message has been successfully submitted and would be delivered to recipients shortly.