Hi Marc,

On Sat, Dec 06, at 03:46 Marc Weber wrote:
> 
> Hi Tony,
> 
> I know about source. That's why I've implemented this:
>       " FIXME: Is there a better way to execute multi line strings?
>       function! library#Exec(cmd)
>         let lines = split(a:cmd,"\n")
>         if (len(lines) > 1)
>           " is there a better way? (TODO! try to not use temp files!)
>           let file = tempname()
>           call writefile(lines, file)
>           exec 'source '.file
>           call delete(file)
>         elseif !empty(lines)
>           exec lines[0]
>         endif
>       endfunction
> 
> But that is ugly!
> In my use case the script doesn't really exist on disk (or better to say
> it does, but not as vimscript but serialized vim dictionary)
> But suing Exec() You've no chance getting the s: or <sfile> context.
> 

Here is function (to parse external scipts, so and serialized vim
dictionaries), that is trying to workaround the limitation of execute.

"   Function: lib#source(file)
"Description: create a list, so we can loop over it by using execute
"       Args: script to parse
"     Return: list
"      Notes: (limited usage)
function! lib#source(file)
    let list = []
    let file = readfile(a:file)
    while !empty(file)
        let string = remove(file, 0)
        if (!empty(file) && match(file[0], '^\s*\') == -1)
            call add(list, string)
        else
            while (!empty(file) && match(file[0], '^\s*\') != -1)
                let string .= ' '.substitute(remove(file, 0), '^\s*\', '', '')
            endwhile
            call add(list, string)
        endif
    endwhile
    return list
endfunction

> Marc

Regards,
Ag.

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Raspunde prin e-mail lui