Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce 'operatorfunc' option for custom operators #785

Merged
merged 3 commits into from
Feb 23, 2024

Conversation

citizenmatt
Copy link
Member

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.

@AlexPl292 AlexPl292 self-requested a review December 28, 2023 09:52
@AlexPl292
Copy link
Member

Oh, wow

@citizenmatt
Copy link
Member Author

Rebased onto current master, fixing conflict.

@citizenmatt
Copy link
Member Author

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?

@AlexPl292
Copy link
Member

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.

@citizenmatt citizenmatt force-pushed the feature/operatorfunc branch 2 times, most recently from b881abf to c3ee52c Compare February 7, 2024 09:51
Allows creating custom operators in script, as shown in JetBrains#702
Also hides more feature flags and diagnostic settings from users and unit tests. Shows them when in internal mode.
@AlexPl292 AlexPl292 merged commit f439474 into JetBrains:master Feb 23, 2024
4 checks passed
@AlexPl292
Copy link
Member

Merged! Thank you!

@citizenmatt citizenmatt deleted the feature/operatorfunc branch February 23, 2024 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants