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.

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

-tim



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