Monday, January 23, 2012

Re: problem with user defined function using dictionary

On Jan 23, 6:07 pm, sinbad <sinbad.sin...@gmail.com> wrote:
> Basically g:CCT is dictionary of dicionary items, and each item is
> list.
>
> now the problem is, if i open a c file normally and invoke the CLadd()
> function it works.
>
> But if i open the file from cscope list and call CLadd()function, i am
> getting the following error.
>
> au BufReadPre *.[ch]
>        \ if exists('CCR')
>        \ | let g:CCT = eval(CCR)
>        \ | let g:CCKey = (keys(g:CCT))[0]
>
> au BufWritePost *.[ch]
>         \ | let g:CCR = string(g:CCT)
>
> fun! CLadd()
>     let bufn = bufname('.')
>
>     if (!has_key(g:CCT, g:CCkey))
>         echo "No keys"
>         return
>     endif
>
>     if (!has_key(g:CCT[g:CCkey], bufn))
>         let g:CCT[g:CCkey][bufn] = []
>     endif
>
>     for entry in g:CCT[g:CCkey][bufn]
>         if (entry[1] == save_cursor[1])
>             return
>         endif
> endfor
>
>     call add(g:CCT[g:CCkey][bufn], save_cursor)
> endfun
>
> Error detected while processing function CLadd:
> line   09:
> E713: Cannot use empty key for Dictionary
> line   12:
> E713: Cannot use empty key for Dictionary
> E15: Invalid expression: g:CCT[g:CCKey][bufn]
> line   18:
> E713: Cannot use empty key for Dictionary
> E116: Invalid arguments for function add
>
> i immediately printed the CCKey value, it has a valid
> key value.
>
> :echo g:CCKey
> key1
>
> what's the problem here.
>
> -sinbad

i think i found the problem.

let bufn = bufname('.')

it should be funame("%")

cheers
sinbad

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

No comments: