docs/developing-rufo

Rufo Development

Tips for editor plugin implementors

It is especially convenient if your code is automatically formatted on save.
For example, surrounding a piece of code with if ... end will automatically indent
the code when you save. Likewise, it will be automatically unindented should you remove it.

For this to work best, the cursor position must be preserved, otherwise it becomes
pretty annoying if the cursor is reset to the top of the editor.

You should compute a diff between the old content and new content
and apply the necessary changes. You can check out how this is done in the
Sublime Text plugin for Rufo:

  • diff_match_patch.py contains the diff algorithm (you can port it to other languages or try to search for a similar algorithm online)
  • rufo_format.py consumes the diff result and applies it chunk by chunk in the editor’s view