Skip to content

Conversation

mcepl
Copy link
Contributor

@mcepl mcepl commented Oct 16, 2021

Problem: Cannot define a function for thesaurus completion.
Solution: Add 'thesaurusfunc'. (Yegappan Lakshmanan, closes vim/vim#8987,
closes 8950)
vim/vim@160e994

@github-actions github-actions bot added the vim-patch See https://neovim.io/doc/user/dev_vimpatch.html label Oct 16, 2021
Copy link
Member

@zeertzjq zeertzjq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgot to add BV_THSFU to option_defs.h.

Copy link
Member

@seandewar seandewar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zeertzjq
Copy link
Member

zeertzjq commented Oct 17, 2021

I think you also need to port patch 8.2.3521 and 8.2.3525.

@clason
Copy link
Member

clason commented Oct 17, 2021

I think you also need to port patch 8.2.3521 and 8.2.3525.

...and 8.2.3528

@mcepl
Copy link
Contributor Author

mcepl commented Oct 17, 2021

all 8.2.3521, 8.2.3525, and 8.2.3528 should be included.

@seandewar
Copy link
Member

This isn't compiling and lint still needs addressing

@mcepl
Copy link
Contributor Author

mcepl commented Oct 17, 2021

@seandewar and I would need a help with that definition in src/nvim/options.lua. Any idea what could be the right options? I have just copied from tsr, but not sure whether it is right.

Copy link
Member

@seandewar seandewar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style comments to help appease the linter

@mcepl
Copy link
Contributor Author

mcepl commented Oct 18, 2021

Not sure, what's the deal with the Windows build.

@zeertzjq
Copy link
Member

zeertzjq commented Oct 18, 2021

Not sure, what's the deal with the Windows build.

The MSVC_32 test also fails on master, so I think you can ignore it.

@zeertzjq
Copy link
Member

This PR now has merge conflicts and needs a rebase.

@mcepl
Copy link
Contributor Author

mcepl commented Oct 19, 2021

Fixed.

Copy link
Member

@seandewar seandewar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many of these comments are probably nit-picks, but functionally I think this PR looks good.
We'll have to see what janlazo thinks 👍

mcepl added 3 commits October 23, 2021 22:30
Problem:    Cannot define a function for thesaurus completion.
Solution:   Add 'thesaurusfunc'. (Yegappan Lakshmanan, closes vim/vim#8987,
            closes 8950)
vim/vim@160e994
Problem:    Options completion test fails.
Solution:   Add 'thesaurusfunc' to the results.
vim/vim@abdcfd1
Problem:    Option variable name does not match option name. (Christ van
            Willigen)
Solution:   Rename the variable.
vim/vim@d4c4bfa
@zeertzjq zeertzjq requested a review from janlazo October 29, 2021 04:01
Copy link
Contributor

@janlazo janlazo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, ignoring style changes.
Fix the code style, address thesaurus_func_complete(), and I'll merge.

…ame scope

Problem:    'thesaurus' and 'thesaurusfunc' do not have the same scope.
Solution:   Make 'thesaurusfunc' global-local.
vim/vim@f4d8b76
@seandewar seandewar requested a review from janlazo November 7, 2021 23:30
@janlazo janlazo merged commit 8f984dc into neovim:master Nov 15, 2021
@mcepl mcepl deleted the vim-8.2.3520 branch November 15, 2021 10:47
@mcepl
Copy link
Contributor Author

mcepl commented Nov 15, 2021

Thank you very much, @janlazo.

@janlazo
Copy link
Contributor

janlazo commented Nov 18, 2021

@mcepl Thanks for your contribution.
@seandewar @zeertzjq Thanks for your continued assistance and your attention to detail. You both made it a lot easier to review this MR.

@David-Else
Copy link

How can I use this in my init.lua? I used to have in init.vim:

func Thesaur(findstart, base)
    if a:findstart
	let line = getline('.')
	let start = col('.') - 1
	while start > 0 && line[start - 1] =~ '\a'
	   let start -= 1
	endwhile
	return start
    else
	let res = []
	let h = ''
	for l in split(system('aiksaurus '.shellescape(a:base)), '\n')
	    if l[:3] == '=== '
	    	let h = substitute(l[4:], ' =*$', '', '')
	    elseif l[0] =~ '\a'
		call extend(res, map(split(l, ', '), {_, val -> {'word': val, 'menu': '('.h.')'}}))
	    endif
	endfor
	return res
    endif
endfunc

set thesaurusfunc=Thesaur   " use the 'thesaurusfunc' for external thesaurus

But I can't seem to work out the synax for vim.opt.thesaurusfunc in Neovim 0.7. Cheers!

@mcepl
Copy link
Contributor Author

mcepl commented May 20, 2022

I have this:

func Thesaur(findstart, base)
    if a:findstart
        return searchpos('\<', 'bnW', line('.'))[1] - 1
    endif
    let res = []
    let h = ''
    for l in systemlist('aiksaurus '.shellescape(a:base))
        if l[:3] == '=== '
        let h = '('.substitute(l[4:], ' =*$', ')', '')
        elseif l ==# 'Alphabetically similar known words are: '
        let h = "\U0001f52e"
        elseif l[0] =~ '\a' || (h ==# "\U0001f52e" && l[0] ==# "\t")
        call extend(res, map(split(substitute(l, '^\t', '', ''), ', '),
        \                    {_, val -> {'word': val, 'menu': h}}))
        endif
    endfor
    return res
endfunc

set thesaurusfunc=Thesaur

@David-Else
Copy link

@mcepl Can you re-create that in an init.lua file, how can I define a vimscript user function and reference it?

@mcepl
Copy link
Contributor Author

mcepl commented May 20, 2022

I probably could, but it is just a waste of time. Put this into ~/.config/nvim/plugin/mythesaurus.vim and be done with it. If you can persuade me with reasonable arguments this has any disadvantages against your Lua solution, I may try to rewrite it.

@David-Else
Copy link

@mcepl I did the following and it worked, thanks for answering. Lua solution is optimal, but I can't be bothered myself :)

vim.cmd [[
func Thesaur(findstart, base)
    if a:findstart
	let line = getline('.')
	let start = col('.') - 1
	while start > 0 && line[start - 1] =~ '\a'
	   let start -= 1
	endwhile
	return start
    else
	let res = []
	let h = ''
	for l in split(system('aiksaurus '.shellescape(a:base)), '\n')
	    if l[:3] == '=== '
	    	let h = substitute(l[4:], ' =*$', '', '')
	    elseif l[0] =~ '\a'
		call extend(res, map(split(l, ', '), {_, val -> {'word': val, 'menu': '('.h.')'}}))
	    endif
	endfor
	return res
    endif
endfunc
]]

vim.opt.thesaurusfunc = 'Thesaur'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vim-patch See https://neovim.io/doc/user/dev_vimpatch.html
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants