Saturday, December 14, 2013

Re: getline(-1) returns 0

mvxxc wrote:

> Can someone explain the following behavior?
>
> The command
>
> :echo getline(-1)
>
> returns zero instead of an empty string. The corresponding help page states the
> following.
>
> > When {lnum} is a String that doesn't start with a digit, line() is called to
> > translate the String into a Number.
>
> > When {lnum} is smaller than 1 or bigger than the number of lines in the
> > buffer, an empty string is returned.
>
> Perhaps negative numbers are treated as strings and translated to zero by
> line():
>
> :echo line("-1")
>
> returns zero. Using zero as an argument for getline(), the result should be an
> empty string, as
>
> :echo getline(0)
>
> returns an empty string.

Yeah, that doesn't look right. It's easier for the caller to handle the
error situation by returning an empty string (or an empty list, if a
list is requested). I'll make a patch.

--
ERROR 047: Keyboard not found. Press RETURN to continue.

/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: