Simplest example of extmark usage?

As you mentioned extmarks are updated if the text changes. Snippet plugins can use this to figure out how the placeholders shifted.

For example, if you’ve a snippet like this:

for ${1:target_list} in ${2:expression_list}:
  ${3:pass}

The plugin can add extmarks to the placeholder regions:

for ${1:target_list} in ${2:expression_list}:
    ^^^^^^^^^^^^^^^^    ^^^^^^^^^^^^^^^^^^^^
  ${3:pass}
  ^^^^^^^^^

Now if the user replaces the first placeholder with some text, the second placeholder moves:

for foo in ${2:expression_list}:
    ^^^    ^^^^^^^^^^^^^^^^^^^^
  ${3:pass}
  ^^^^^^^^^

The extmarks shifted too and the plugin can use this to figure out the updated position of the placeholders

There’s another example how they can be used here: Need advice on how separate render the UI on lua plugin development - #2 by mfussenegger

1 Like