ideavim icon indicating copy to clipboard operation
ideavim copied to clipboard

Introduce 'operatorfunc' option for custom operators

Open citizenmatt opened this issue 1 year ago • 4 comments

This PR introduces the 'operatorfunc' option. This option contains the name of a function that can act like a custom operator, and is called by the g@ command, such as in this example from the #702 discussion:

nnoremap gx :set opfunc=Redact<cr>g@
function! Redact(type)
    execute "normal `[v`]rx"
endfunction

Using a command such as gxiw, this map will invoke the custom operator function on a given word, and replace it with x characters.

The 'opfunc' option can be the name of a function, a reference from function('…') or funcref('…') or a lambda.

This PR also allows an extension to export a script function that can be called from the VimScript executor, which is a simple wrapper function that invokes extension code. A helper function has been added to create a script function with the right signature for operator functions. All extensions have been updated to export a function, and to use the 'operatorfunc' option.

citizenmatt avatar Dec 27 '23 13:12 citizenmatt

Oh, wow

AlexPl292 avatar Jan 04 '24 13:01 AlexPl292

Rebased onto current master, fixing conflict.

citizenmatt avatar Jan 05 '24 14:01 citizenmatt

Rebased onto current master and force pushed.

Also fixes SetCommandTests and friends by being more consistent with the temporary/hidden flag. Options that are feature flags for work-in-progress or diagnostic behaviour are hidden from normal use and unit tests. They are always visible for internal mode.

@AlexPl292 @lippfi are we happy to merge this?

citizenmatt avatar Feb 03 '24 16:02 citizenmatt

Hi, yes, sorry for the delays. We haven't yet reviewed this, but the plan is to first merge the changes about the regex, then make a release, and then handle your changes to avoid too many refactorings in one release.

AlexPl292 avatar Feb 05 '24 07:02 AlexPl292

Merged! Thank you!

AlexPl292 avatar Feb 23 '24 08:02 AlexPl292