To: Ralf Schandl <[email protected]>
In-Reply-To: <[email protected]>
Subject: patch 5.4n.9 (was: VIM: moving cursor to negative line numbers)
Fcc: outbox
From: Bram Moolenaar <[email protected]>
------------

Ralf Schandl wrote:

> I just managed to move the cursor to negativ line numbers. A patch is
> included.
>
> Just do the following:
>
> Start vim
> vim -u NONE -U NONE .profile
>
> and enter
>
> :-2
>
> then <C-G> outputs:
> ".profile" line -1 of 155 --0%-- col 1
>
> The cursor stays in window-line 1, and  you can return to file-line 1
> with 'j'.

Indeed.  Easy to reproduce.

> Fix:
> Check that that the line number is not smaller or equal to 0 in
> function do_one_cmd just after the mark "doend:". See patch below.

Good, that fixes the problem.  Hmm, I think that an error message is
appropriate in this situation.  Vi does so too.  Not for ":0" though, that is
silently interpreted as ":1".  Vim did that already.


Patch 5.4n.9
Problem:    ":-2" moved the cursor to a negative line number. (Ralf Schandl)
Solution:   Give an error message for a negative line number.
Files:      src/ex_docmd.c


*** ../vim-5.4n/src/ex_docmd.c  Sun Jul  4 20:35:46 1999
--- src/ex_docmd.c      Tue Jul  6 21:23:25 1999
***************
*** 840,846 ****
       }
       else if (ea.addr_count != 0)
       {
!           if (ea.line2 == 0)
               curwin->w_cursor.lnum = 1;
           else if (ea.line2 > curbuf->b_ml.ml_line_count)
               curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
--- 840,848 ----
       }
       else if (ea.addr_count != 0)
       {
!           if (ea.line2 < 0)
!               errormsg = invalid_range(&ea);
!           else if (ea.line2 == 0)
               curwin->w_cursor.lnum = 1;
           else if (ea.line2 > curbuf->b_ml.ml_line_count)
               curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;

--
You can be stopped by the police for biking over 65 miles per hour.
You are not allowed to walk across a street on your hands.
               [real standing laws in Connecticut, United States of America]

--/-/---- Bram Moolenaar ---- [email protected] ---- [email protected] ---\-\--
 \ \    www.vim.org/iccf      www.moolenaar.net       www.vim.org    / /