def tq_generate_thesaurus_buffer(candidates):
    '''
    generate a buffer showing all found synonyms in the candidate list from
    query
    '''
#    tq_current_buffer = vim.current.buffer.name
    vim.command("silent! let l:thesaurus_window = bufwinnr('^thesaurus: ')")
    if int(vim.eval("l:thesaurus_window")) > -1:
        vim.command('exec l:thesaurus_window . "wincmd w"')
    else:
        vim.command('exec ":silent keepalt belowright split thesaurus:\\\\ " . l:word_fname')
    vim.command('exec ":silent file thesaurus:\\\\ " . l:word_fname . "\\\\ (press\\\\ q\\\\ to\\\\ close\\\\ this\\\\ split.)"')

    vim.command('setlocal noswapfile nobuflisted nospell nowrap modifiable')
    vim.command('setlocal buftype=nofile')

    tq_thesaurus_buffer = vim.current.buffer
    del tq_thesaurus_buffer[:]
    line_count=0
    tq_thesaurus_buffer.append([""])
    tq_thesaurus_buffer[line_count]="Result for word \"{}\" (press \"q\" to close this split)".format(vim.eval('l:word'))
    line_count+=1
    for case in candidates:
        tq_thesaurus_buffer.append([""])
        if not case[0]:
            tq_thesaurus_buffer[line_count]='Synonyms: {}'.format(", ".join(encode_utf_8(case[1])))
            line_count+=1
            continue
        tq_thesaurus_buffer[line_count:line_count+2]=['Found_as: {}'.format(encode_utf_8(case[0])), 'Synonyms: {}'.format(encode_utf_8(", ".join(case[1])))]
        line_count+=2
    vim.command("setlocal bufhidden=")
    vim.command("silent g/^Synonyms:/ normal! 0Vgq")
    vim.command("exec 'resize ' . (line('$'))")
    vim.command("nnoremap <silent> <buffer> q :q<CR>")
    vim.command("setlocal filetype=thesaurus")
    vim.command("normal! gg")
    vim.command("setlocal nomodifiable")
#    tq_current_buffer_goto = vim.eval('bufwinnr("{}")'.format(tq_current_buffer))
#    vim.command('exec {} . "wincmd w"'.format(tq_current_buffer_goto))
dataset/ETHPy150Open Ron89/thesaurus_query.vim/autoload/thesaurus_query/thesaurus_query.py/tq_generate_thesaurus_buffer/original