Thursday, August 25, 2011

RE: Can a function tell if % range was explicitly passed?

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 noticed your change at http://vim.wikia.com/wiki/csv

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. In the
case of the changed CSV tip, that would be from after the
heading line to line('$').

Hmmm. I just remembered something. You can use this trick:
let cmd = histget(':', -1)

If cmd is just 'CallRT' then no range was used.

John

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

No comments: