Am 09.04.2011 13:29, schrieb ZyX:
Reply to message «Re: Wish:<range>»,
sent 15:22:29 09 April 2011, Saturday
by Tony Mechelynck:

Could you give a use case which would not work just as well with either
-range or -range=% ? You'd have to use that range somewhere.

Maybe you could use :0command for your special case? That range is
allowed, but for some commands it is not meaningful.
If I understood him correctly, he wants to write `<range>' where now you write
`<line1>,<line2>', like this:
     command -range Foo<range>call s:Foo()
instead of
     command -range Foo<line1>,<line2>call s:Foo()
.

Yep, that's what I meant.

For example, I have a command :InFunc .  It's quite a trivial command,
it takes an argument Ex-command and executes it within a function.
Purpose is to automatically restore the highlighting state and the last
search pattern.
    :h function-search-undo

Thus, mostly the Ex-command will be :global or :substitute .

Problem: :global has the default range "1,$" whereas :substitute has the
default range ".".  For :InFunc, I'm urged to specify a default range
(e.g. either -range (current line) or -range=% (whole buffer)).  I don't
want that, instead I want the default range of the argument command to
be in effect.  But at the moment, it's not possible to check for an
empty range.


" What I use now:
    :[range]InFunc {cmd}        " execute :[range]{cmd}, for :subst
    :[range]InFunc! {cmd}       " execute :{cmd}, for :global

com! -bang -range -nargs=+  InFunc <line1>,<line2>call InFunc(<bang>0, <q-args>)

func! InFunc(bang, cmd) range
    if a:bang
        exec a:cmd
    else
        exec a:firstline.",".a:lastline. a:cmd
    endif
endfunc


" I'd like to write the above this way:

com! -range=NoDefault -nargs=+  InFunc <range>call InFunc(<q-args>)

func! InFunc(cmd) range
    exec a:range. a:cmd
endfunc


Oops, we would also need a new variable  a:range !

Maybe, actually, <range> and a:range are not needed, I just want to be
able to check for an empty range:


com! -range -nargs=+  InFunc <line1>,<line2>call InFunc(<q-args>)

func! InFunc(cmd) range
    if range_is_empty()
        exec a:cmd
    else
        exec a:firstline.",".a:lastline. a:cmd
    endif
endfunc


This would just a require a new function range_is_empty().

--
Andy

--
You received this message from the "vim_dev" 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

Raspunde prin e-mail lui