On Wed, Nov 21, 2012 at 3:39 AM, Andy Wokula <[email protected]> wrote:
> Am 21.11.2012 09:05, schrieb Ingo Karkat: > > On 20-Nov-12 20:14:08 +0100, Nate Soares wrote: >> >> In that case I'd like to make a feature request for a way to handle >>> functions with ranges without moving the cursor. My suggestion would >>> be adding a [save] argument to :function which calls winsaveview() >>> before entering and winrestview() after exiting the function, as this >>> has potential applications beyond just [range] functions. >>> >> > Compared to the invocation of user commands with a range: > > Alright, when one defines a user command with `-range', the cursor > doesn't move: > > :com! -bar -range TestRangeCursor :echo "Range: <line1>,<line2>" > :%TestRangeCursor > > There are also several Ex-commands that don't move: > :foldopen, :=, :z, :yank, ... > > Others move although they don't operate on the range: > :list, :print, ... > > > Thoughts on the proposed api? >>> >> > That might be a good compromise. Even though nobody has so far come up >> with a use case for the current, impractical behavior, Bram is >> (rightly) very concerned about preserving behavior. >> >> Though I have no experience with this, I guess this argument (I'd call >> it [keepview]) could be implemented without many lines of code and >> effort. >> >> -- regards, ingo >> >> PS: Please bottom-post on this list. >> > > Somehow I don't like `keepview', it does too much. > > What about a function modifier (next to `range') that just prevents > cursor movement? No idea for a good name yet: > dontmove > keeppos > stay > > func! MyFunc() range stay > echo a:firstline a:lastline > endfunc > > (for the uninitiated, this is about unwanted cursor movement with > :func! MyFunc() range > :endfunc > :10,20call MyFunc() > ) > > -- > 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<http://www.vim.org/maillist.php> > +1 for stay. @Andy, it's quite a bit harder to pass line numbers than it is to use the built in range functionality. Compare -5,+3call MyFunction('foo', 'bar', 'baz') to call MyFunction('foo', 'bar', 'baz', line('.') - 5, line('.') + 3) It's quite a bit more typing, it's error-prone, it pollutes the argument space, it subverts perfectly good built in functionality, and it's inconsistent. It makes functions strictly less powerful than mappings and commands: they fundamentally can't do something that the others can! This should be uncomfortable. Here's a patch that adds the "stay" argument to the :function command. Thoughts? -- 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
stay.diff
Description: Binary data
