On Aug 25, 12:54 pm, Tim Chase <v...@tim.thechases.com> wrote:
> On 08/25/2011 06:17 AM, John Beckett wrote:
> > lessthanideal wrote:
> >> function RangeTest() range
> >>    echo a:firstline . " " . a:lastline
> >> endfunction
> >> command -range=% CallRT<line1>,<line2>call RangeTest()
>
> >> These two commands give the same output
> >> :CallRT
> >> :%CallRt
>
> >> Could the function distinguish between the two?
>
> > I don't think the two cases can be distinguished. A possible
> > workaround would be to omit '=%' so the default range is the
> > current line. We would assume that no one wants to sort just
> > one line, so in the function a test could say if first and last
> > lines are equal, use the default wanted by the function.
>
> I like the "omit the =%" suggestion, but might be tempted to check
>
>    if a:firstline == 1 && a:lastline == line('$')
>
> instead, because the range can be more than just "%".  E.g.
> something like
>
>    :1,$CallRT
>    :2-1,$CallRT
>    :1,18CallRT  "assuming the last line is 18
>    :?SomethingOnFirstLine?,/OnLastLine/CallRT
>
> all of which are effectively passing a full-file range.

Actually that is the check I've used in the CSV code, but
I just suggested % to simplify the question.  But have I
missed your point?  Doesn't that check also get the
full-file range for

:CallRT

Omitting =% works at first cut, rejigging the code
to check firstline==lastline as John suggests.  Need to do
a bit more testing next week though in case I've missed something
else, just tried it very hurriedly now.

>
> > Hmmm. I just remembered something. You can use this trick:
> >    let cmd = histget(':', -1)
>
> > If cmd is just 'CallRT' then no range was used.
>
> Though expecting particular sequences in the history can break in
> fragile ways when you have things like
>
>    :g/pattern/;+5CallRT

In this case it would also break if the function is called
directly instead of via the command.  (I don't know why that
would ever be done?)  But a useful trick in general I've now
noted for future reference.

thanks,
Geoff

-- 
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

Reply via email to