a bug ? virtualedit and visual block paste replace

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

a bug ? virtualedit and visual block paste replace

Sylvain Viart
Hi,

I'm programming a script which use virtualedit mode
   set ve=all
   set paste is also actived

and I do the following :

Select a visual block area verticaly with :

   exe "norm j\<c-v>".(a:height-1)."jr|"

The visual area is well replaced with pipe character

After I go back to the bottom of my selection (visual block) with :
   exe "norm `>j"

And here is my problem:

If the next line under the visual block (with the j, the cursor is on
the line)  is an empty line, if I paste the content of my register @l
with the followiing command :

   exe "norm \<c-v>".(a:width+1).'l"lP'

The output string the one character right of the column I want, it
doesn't happen if the line was not empty.

The result :

    " copy the result in register @v
    exe 'no+----------+
           |           |
    " goto |o the left |ottom corner
    exe "no|m `>j"     |
            +----------+


The expected result :
   " copy the result in register @v
    exe 'no+----------+
           |          |
    " goto |o the left|bottom corner
    exe "no|m `>j"    |
           +----------+

It can be easyly fixed by checking the emptyline, but I would like to
know if it's a bug or not ?

Regards,
Sylvain.

Reply | Threaded
Open this post in threaded view
|

Re: a bug ? virtualedit and visual block paste replace

Bram Moolenaar

Sylvain Viart wrote:

> I'm programming a script which use virtualedit mode
>    set ve=all
>    set paste is also actived
>
> and I do the following :
>
> Select a visual block area verticaly with :
>
>    exe "norm j\<c-v>".(a:height-1)."jr|"
>
> The visual area is well replaced with pipe character
>
> After I go back to the bottom of my selection (visual block) with :
>    exe "norm `>j"
>
> And here is my problem:
>
> If the next line under the visual block (with the j, the cursor is on
> the line)  is an empty line, if I paste the content of my register @l
> with the followiing command :
>
>    exe "norm \<c-v>".(a:width+1).'l"lP'
>
> The output string the one character right of the column I want, it
> doesn't happen if the line was not empty.
>
> The result :
>
>     " copy the result in register @v
>     exe 'no+----------+
>            |           |
>     " goto |o the left |ottom corner
>     exe "no|m `>j"     |
>             +----------+
>
>
> The expected result :
>    " copy the result in register @v
>     exe 'no+----------+
>            |          |
>     " goto |o the left|bottom corner
>     exe "no|m `>j"    |
>            +----------+
>
> It can be easyly fixed by checking the emptyline, but I would like to
> know if it's a bug or not ?

I'm missing a few things, such as the contents of the l register and the
text you started with.  I could try guessing, but it's a lot simpler if
you provide us with the example text and a script that shows the
problem.

--
(letter from Mark to Mike, about the film's probable certificate)
      For an 'A' we would have to: Lose as many shits as possible; Take Jesus
      Christ out, if possible; Loose "I fart in your general direction"; Lose
      "the oral sex"; Lose "oh, fuck off"; Lose "We make castanets out of your
      testicles"
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\              Project leader for A-A-P -- http://www.A-A-P.org        ///
 \\\     Buy LOTR 3 and help AIDS victims -- http://ICCF.nl/lotr.html   ///
Reply | Threaded
Open this post in threaded view
|

Re: a bug ? virtualedit and visual block paste replace

Sylvain Viart
Hi,

Sorry for missing information.

>I'm missing a few things, such as the contents of the l register and the
>text you started with.  I could try guessing, but it's a lot simpler if
>you provide us with the example text and a script that shows the
>problem.
>
>  
>

You can fetch the script from here  :
http://dev.easyrencontre.com/~sylvain/popup_box.vim

Function goal's is to draw a box above any text in the buffer, this
function suppose there's some text in the buffer.

The register @l containt the text of the top line something like :
+-------------+

You call the function with

   :call DrawPopUpBox(40,12, 3,10)

The script will draw a small box line 40 throught 44, the line 44 is empty.

I've commented  lines 47, 48, 49, which patch the problem for me.

Regards,
Sylvain.

Reply | Threaded
Open this post in threaded view
|

Re: a bug ? virtualedit and visual block paste replace

Bram Moolenaar

Sylvain Viart wrote:

> You can fetch the script from here  :
> http://dev.easyrencontre.com/~sylvain/popup_box.vim
>
> Function goal's is to draw a box above any text in the buffer, this
> function suppose there's some text in the buffer.
>
> The register @l containt the text of the top line something like :
> +-------------+
>
> You call the function with
>
>    :call DrawPopUpBox(40,12, 3,10)
>
> The script will draw a small box line 40 throught 44, the line 44 is empty.
>
> I've commented  lines 47, 48, 49, which patch the problem for me.

OK, now I can reproduce the problem.  After quite a bit of debugging the
problem appears to be that when deleting text that doesn't exist the '[
and '] are not set.  The "P" command then thinks it should put after the
cursor instead of before.  Complicated, isn't it?

This patch will fix it.  I only did this for Vim 7 now, first need to
check for any undesired side effects.

*** ops.c~ Wed Jul 27 17:50:28 2005
--- ops.c Wed Jul 27 17:57:00 2005
***************
*** 1583,1588 ****
--- 1583,1594 ----
  * It's an error to operate on an empty region, when 'E' included in
  * 'cpoptions' (Vi compatible).
  */
+ #ifdef FEAT_VIRTUALEDIT
+ if (virtual_op)
+    /* Virtual editing: Nothing gets deleted, but we set the '[ and ']
+     * marks as if it happened. */
+    goto setmarks;
+ #endif
  if (vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL)
     beep_flush();
  return OK;
***************
*** 1858,1863 ****
--- 1864,1872 ----
 
      msgmore(curbuf->b_ml.ml_line_count - old_lcount);
 
+ #ifdef FEAT_VIRTUALEDIT
+ setmarks:
+ #endif
  #ifdef FEAT_VISUAL
      if (oap->block_mode)
      {

--
Wi n0t trei a h0liday in Sweden thi yer?
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\              Project leader for A-A-P -- http://www.A-A-P.org        ///
 \\\     Buy LOTR 3 and help AIDS victims -- http://ICCF.nl/lotr.html   ///