Ag. D. Hatzimanikas:
> > I could also use readfile(), which would probably suffice, but is this
> > more or less efficient than loading a file into a vim buffer. I will
> > still need to read the whole file either way since I don't know how
> > far through the file I will need to look.
> >
> > Now if there was a searchfile() function, that would be handy :-)
>
> Here is a result of your thoughts.
>
> function! Searchfile(file, pattern, ...)
> if exists("a:1")
> let matchlimit = a:1
> else
> let matchlimit = 1
> endif
> let list = []
> let matches = 0
> for line in readfile(a:file)
> if match(line, a:pattern) != -1
> call add(list, line)
> let matches += 1
> if matches == matchlimit
> break
> endif
> endif
> endfor
> return list
> endfunction
Oh, that's interesting, particularly the "for line in readfile()" construct.
I would be scared that readfile() is then carried out every time around the
loop! Or maybe vim is optimised to only read one line at a time this way.
Anyone know? If it just reads the file once at the start of the loop then this
Searchfile() function isn't any more efficient than readfile(). My point was
that it would be nice to have a function that doesn't read the whole file if it
doesn't have to, but then maybe that's what this for-construct does?
Thanks,
Rob.
--
Robert Webb <[EMAIL PROTECTED]>,
Want to make polyhedra?
http://www.software3d.com/Stella.php
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---