Hi eliweiq001!

On Fr, 20 Aug 2010, eliweiq001 wrote:

> 
> 
> On 8月20日, 下午4时35分, Christian Brabandt <[email protected]> wrote:
> > Hi eliweiq001!
> >
> >
> > > And besides, when I
> > > :call OpenLastModified(1)
> >
> > > there is an error:
> >
> > > Error detected while processing function OpenLastModified:
> > > Line 5:
> > > E684: list index out of range: -1
> > > E15: Invalid expression: files[-1]
> >
> > What make you think, you were supposed to call it with the parameter 1?
> > The optionally parameter to that function is supposed to be a path.
> > Therefore the command :OpenLastModified was provided, that allows for
> > tabcompleting a directory optionally.
> >
> > regards,
> > Christian
> 
> 
> Because I don't understand the function,  I just copy it and use it.
> 
> 
> When I type :call OpenL
> and press Tab, it will change to         :call OpenLastModified(
> another Tab, it will change to            :call OpenLastModified(1()
> one more Tab, it will be                    :call
> OpenLastModified(10()
> one more Tab, it will be                    :call
> OpenLastModified(100()
> one more Tab, it will be                    :call
> OpenLastModified(101(
> ......
> 
> 
> So I don't know what does it mean.
> 
> If I :call OpenLastModified()
> it will say that   Undefined variable: a:1 .........
> 
> If I put a directory to be the parameter, it will say Undefined
> variable too.
> 
> Such as :call OpenLastModified(D:\) in windows, it will say
> E121: Undefined variable: D:
> E116: Invalid arguments for function OpenLastModified
> 
> Then I try :call OpenLastModified(.\) , it will say
> E15: Invalid expression: .\)
> E116: Invalid arguments for function OpenLastModified

I see. There was 1 small problem. Use this slightly changed version 
(which only selects C-files):

fun! OpenLastModified(...)
    let path=(!empty(a:1) ? a:1 : getcwd() )
    let files=split(glob(path . '/*.c', 1), '\n')
    call filter(files, '!isdirectory(v:val)')
    call sort(files, "CompareLastModified")
    if !empty(files)
        return ":tabe " . files[-1]
    else 
        return ":echoerr 'No files found'"
    endif
endfun

func! CompareLastModified(a,b)
      return getftime(a:a) == getftime(a:b) ? 0 : getftime(a:a) > getftime 
(a:b) ? 1 : -1
endfunc

com! -complete=dir -nargs=? EditLastModified :exe OpenLastModified(<q-args>)

So please in the command prompt type :EditLastModified followed by 
Carriage Return. This will open the last modified file from the current 
working directory (basically the directory that :pwd returns). You can 
however optionally open the last modified file from a different 
directory. Therefore you type:
:EditLastModified followed by a space followed by a directory, e.g. D:\ 
followed by a return, e.g:
:EditLastModified D:\
When using the 2nd form, you can use your Tab key to complete a 
directory.

Sorry for the confusion.

regards,
Christian

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