0

How do you set g.vimwiki_diary_months in lua?

According to :h g.vimwiki_diary_months:

*g:vimwiki_diary_months*

It is a |Dictionary| with the numbers of months and corresponding names. Diary
uses it.

Redefine it in your .vimrc to get localized months in your diary:
let g:vimwiki_diary_months = {
      \ 1: 'Январь', 2: 'Февраль', 3: 'Март',
      \ 4: 'Апрель', 5: 'Май', 6: 'Июнь',
      \ 7: 'Июль', 8: 'Август', 9: 'Сентябрь',
      \ 10: 'Октябрь', 11: 'Ноябрь', 12: 'Декабрь'
      \ }

Default:
let g:vimwiki_diary_months = {
      \ 1: 'January', 2: 'February', 3: 'March',
      \ 4: 'April', 5: 'May', 6: 'June',
      \ 7: 'July', 8: 'August', 9: 'September',
      \ 10: 'October', 11: 'November', 12: 'December'
      \ }

So far, I wrote the following code:

dict = {}
dict[1] = 'Enero'
dict[2] = 'Febrero'
dict[3] = 'Marzo'
dict[4] = 'Abril'
dict[5] = 'Mayo'
dict[6] = 'Junio'
dict[7] = 'Julio'
dict[8] = 'Agosto'
dict[9] = 'Septiembre'
dict[10] = 'Octubre'
dict[11] = 'Noviembre'
dict[12] = 'Diciembre'
vim.g.vimwiki_diary_months =  { dict }

But reports as error:

Vimwiki: Error: The provided value of the option 'g:vimwiki_diary_months' is a list, but expected is a dictionary. See ':h g:vimwiki_diary_months'

Where is the mistake?

1 Answer 1

1

I would do:

dict = {
  ['1'] = 'Enero',
  ['2'] = 'Febrero',
  ['3'] = 'Marzo',
  ['4'] = 'Abril',
  ['5'] = 'Mayo',
  ['6'] = 'Junio',
  ['7'] = 'Julio',
  ['8'] = 'Agosto',
  ['9'] = 'Septiembre',
  ['10'] = 'Octubre',
  ['11'] = 'Noviembre',
  ['12'] = 'Diciembre',
}

vim.g.vimwiki_diary_months =  dict

The lua syntax for dictionary with non identifier keys is somehow uncommon.

You have an example in the lua doc about tables:

-- That syntax is more cumbersome, but more flexible too: Both the list-style and the record-style forms are special cases of this more general one. The constructor 
{x=0, y=0}
-- is equivalent to
{["x"]=0, ["y"]=0}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.