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

Implement custom variable register api #94

Closed
wants to merge 1 commit into from
Closed

Conversation

hrsh7th
Copy link
Owner

@hrsh7th hrsh7th commented Aug 11, 2020

Fixes #93, #86

Overview

This PR aims to register a custom variable resolver that can realize some of the interpolation related functionality.
For example, we can register the below variable for vim interpolation.

function! s:EVAL_VIM(context) abort
  let l:script = join(map(copy(a:context.node.children), 'v:val.text()'), '')
  return eval(l:script)
endfunction
call vsnip#variable#register('EVAL_VIM', function('s:EVAL_VIM'))
  "changedtick": {
    "prefix": "var",
    "body": [
      "${EVAL_VIM:getbufvar('%', 'changedtick')}"
    ]
  },

Currently, custom variable context is the below structure.

let a:context = {
\   'node': s:Variable, " the resolving variable node
\   'before': string, " the forward snippet text for the resolving variable before sync
\   'after': string, " the backward snippet text for the resolving variable before sync
\ }

TODO

  • Pass $TM_SELECTED_TEXT test case
  • Docs
  • Add some tests
  • Fix potential bug of variable children

let l:script = join(map(copy(a:context.node.children), 'v:val.text()'), '')
return eval(l:script)
endfunction
call vsnip#variable#register('EVAL_VIM', function('s:EVAL_VIM'))
Copy link
Owner Author

Choose a reason for hiding this comment

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

It should be removed for built-in.

let l:option = get(a:000, 0, {})
let s:variables[a:name] = {
\ 'func': a:func,
\ 'once': get(l:option, 'once', v:false)
Copy link
Owner Author

Choose a reason for hiding this comment

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

It has to turn on as default.

@hrsh7th
Copy link
Owner Author

hrsh7th commented Aug 11, 2020

I want to provide synched text for the variable argument... but it's hard...

@hrsh7th
Copy link
Owner Author

hrsh7th commented Aug 11, 2020

Close for a moment.

@hrsh7th hrsh7th closed this Aug 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom variable resolver
1 participant