Monday, February 21, 2011

Re: Including into the current buffer from an external source

Reply to message «Re: Including into the current buffer from an external
source»,
sent 20:37:57 21 February 2011, Monday
by Christian Brabandt:

> and won't even work if you haven't set 'shell' correctly.
'shell' option is set to $SHELL by default. No need to change it explicitely
anywhere in vim configuration files if you have already changed login shell.

By the way, here is corrected command:

function! s:Read(args) range
let args=a:args
let match=match(args, '\v \zs(\d+) +(\d+)$')
let firstline=a:lastline
if match!=-1
let lrange=map(split(args[(match):]), '+v:val')
if lrange[0]==0
let lrange[0]=1
endif
if lrange[1]!=0 && lrange[1]<lrange[0]
call add(lrange, remove(lrange, 0))
endif
let args=args[:(match-1)]
endif
let oldlen=line('$')
silent execute firstline.'read'.args
let newlen=line('$')
let diff=newlen-oldlen
if exists('lrange') && !empty(lrange)
if lrange[1]==0
let lrange[1]=diff
endif
if lrange[1]<diff
silent execute (firstline+lrange[1]+1).','.(firstline+diff).
\'delete _'
endif
if lrange[0]>1
silent execute (firstline+1).','.(firstline+lrange[0]-1).
\'delete _'
endif
endif
endfunction
command! -nargs=? -bang -range Read <line2>call s:Read('<bang>'.<q-args>)

Looks like I can't write not too much code.

Usage: same as ``read'', but if last two arguments contain only digits then they
are consumed and mean range of lines that should be kept. If you put `0' as last
but one argument it will be transformed to 1. If you put `0' as a last argument,
it will be transformed to number of lines read, so ``Read{read_arguments} 0 0''
means just the same as ``read{read_arguments}''.

Original message:
> Hi ZyX!
>
> (Please don't top post!)
>
> On Mo, 21 Feb 2011, ZyX wrote:
> > Your emulation is incorrect: try to get the same output as ``read!
> > echo $'\0'''. In case of reading file my suggestion works just as well
>
> You are not only Unix specific, but Shell specific. That is not portable
> and won't even work if you haven't set 'shell' correctly.
>
> regards,
> Christian

No comments: