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

ragged right detection for visual-block selection

Expand Messages
  • Charles E. Campbell
    Hello! I ve been experimenting (sounds so much better than fooling , you know) with attempting to detect ragged-right visual-block selection. OK, I flunked --
    Message 1 of 4 , May 1, 2002
      Hello!

      I've been experimenting (sounds so much better than "fooling", you know)
      with attempting to detect ragged-right visual-block selection.

      OK, I flunked -- how may I tell whether or not "ragged-right"
      visual-block selection has been used?

      For purposes of discussion, I have a small test script which I source in:

      ---------------------------------------------------------------------
      com! -ra -nargs=0 -com=command T call <SID>Test()
      fu! <SID>Test() range
      echo "'>=".virtcol("'>")." $=".virtcol("$")
      endf
      ---------------------------------------------------------------------

      and a test file: (no tabs, assume we'll use retab so virtcol==col)

      ---------------------------------------------------------------------
      aa bb cc
      aaa bbb ccc
      a b c
      aaa bbb ccc
      aaa bbb ccc
      aaa bbb ccc
      ---------------------------------------------------------------------

      Using On_Lines

      1: V 1-3: '>=6 $=9 ragged
      2: ctrl-v 1-3, columns 1-5 ( use $): '>=6 $=9 ragged
      3: ctrl-v 1-3, columns 1-5 (*don't* use $): '>=5 $=9

      4: V 4-6: '>=12 $=12 ragged
      5: ctrl-v 4-6, columns 1-11( use $): '>=12 $=12 ragged
      6: ctrl-v 4-6, columns 1-11(*don't* use $): '>=11 $=12

      Doesn't seem to me that I can use virtcol and '>, $ to figure this
      out. Of course I can use visualmode() to determine if ctrl-v was used
      instead of V (the latter always being "ragged right"), so my question
      really involved visual-block mode.

      Regards,
      Charles Campbell

      --
      Charles E Campbell, Jr, PhD _ __ __
      Goddard Space Flight Center / /_/\_\_/ /
      cec@... /_/ \/_//_/
      PGP public key: http://www.erols.com/astronaut/pgp.html
    • Benji Fisher
      ... If I understand correctly, you are trying to distinguish between experiments 2 and 3, and between 5 and 6. Experiments 2 and 5 are ragged right. In the
      Message 2 of 4 , May 1, 2002
        On Wednesday, May 1, 2002, at 04:43 PM, Charles E. Campbell wrote:

        > Hello!
        >
        > I've been experimenting (sounds so much better than "fooling", you know)
        > with attempting to detect ragged-right visual-block selection.
        >
        > OK, I flunked -- how may I tell whether or not "ragged-right"
        > visual-block selection has been used?
        >
        > For purposes of discussion, I have a small test script which I source
        > in:
        >
        > ---------------------------------------------------------------------
        > com! -ra -nargs=0 -com=command T call <SID>Test()
        > fu! <SID>Test() range
        > echo "'>=".virtcol("'>")." $=".virtcol("$")
        > endf
        > ---------------------------------------------------------------------
        >
        > and a test file: (no tabs, assume we'll use retab so virtcol==col)
        >
        > ---------------------------------------------------------------------
        > aa bb cc
        > aaa bbb ccc
        > a b c
        > aaa bbb ccc
        > aaa bbb ccc
        > aaa bbb ccc
        > ---------------------------------------------------------------------
        >
        > Using On_Lines
        >
        > 1: V 1-3: '>=6 $=9 ragged
        > 2: ctrl-v 1-3, columns 1-5 ( use $): '>=6 $=9 ragged
        > 3: ctrl-v 1-3, columns 1-5 (*don't* use $): '>=5 $=9
        >
        > 4: V 4-6: '>=12 $=12 ragged
        > 5: ctrl-v 4-6, columns 1-11( use $): '>=12 $=12 ragged
        > 6: ctrl-v 4-6, columns 1-11(*don't* use $): '>=11 $=12
        >
        > Doesn't seem to me that I can use virtcol and '>, $ to figure this
        > out. Of course I can use visualmode() to determine if ctrl-v was used
        > instead of V (the latter always being "ragged right"), so my question
        > really involved visual-block mode.

        If I understand correctly, you are trying to distinguish between
        experiments 2 and 3, and between 5 and 6. Experiments 2 and 5 are
        "ragged right."

        In the ragged cases, the '> mark seems to be one beyond the end of
        the last line of the Visual selection. However, virtcol("$") is
        evaluated on the first line of the Visual selection. So try using
        strlen(getline("'>")) instead of virtcol("$"). (And use col("'>")
        instead of virtcol()--then it should work even with tabs, I think.)

        HTH --Benji Fisher
      • Benji Fisher
        ... I just did another experiment, and realized that a block can be marked either by its upper-left and lower-right corners, or by its upper-right and
        Message 3 of 4 , May 2, 2002
          On Wednesday, May 1, 2002, at 05:10 PM, Benji Fisher wrote:

          > [snip]
          > If I understand correctly, you are trying to distinguish between
          > experiments 2 and 3, and between 5 and 6. Experiments 2 and 5 are
          > "ragged right."
          >
          > In the ragged cases, the '> mark seems to be one beyond the end of
          > the last line of the Visual selection. However, virtcol("$") is
          > evaluated on the first line of the Visual selection. So try using
          > strlen(getline("'>")) instead of virtcol("$"). (And use col("'>")
          > instead of virtcol()--then it should work even with tabs, I think.)
          >
          > HTH --Benji Fisher

          I just did another experiment, and realized that a block can be
          marked either by its upper-left and lower-right corners, or by its
          upper-right and lower-left corners. To test for ragged-right,

          if col("'>") > strlen(getline("'>")) || col("'<") > strlen(getline("'<"))

          should do.

          HTH --Benji Fisher
        • Charles E. Campbell
          ... Thank you, Benji! I ll be trying that out. Regards, Chip Campbell -- Charles E Campbell, Jr, PhD _ __ __ Goddard Space Flight Center
          Message 4 of 4 , May 2, 2002
            Thus saith Benji Fisher:
            > On Wednesday, May 1, 2002, at 05:10 PM, Benji Fisher wrote:
            > To test for ragged-right,
            >
            > if col("'>") > strlen(getline("'>")) || col("'<") > strlen(getline("'<"))


            Thank you, Benji! I'll be trying that out.

            Regards,
            Chip Campbell

            --
            Charles E Campbell, Jr, PhD _ __ __
            Goddard Space Flight Center / /_/\_\_/ /
            cec@... /_/ \/_//_/
            PGP public key: http://www.erols.com/astronaut/pgp.html
          Your message has been successfully submitted and would be delivered to recipients shortly.