I am currently building a plug-in which will, in response to some specific user actions and in specific circumstances, insert code snippets into an open source file (ie, the currently selected file in the open project). I am now at the point where things actually work, with one snag: I would like to format the inserted code snippet using the user's style/format (rather than "hardcode" a series of tabs etc in the template itself).
Have been searching around for an example of how to to do this, but that has proven more elusive :-) than usual. Would appreciate any pointers on the matter - I can find references to FormattingModel etc, but at a complete loss on how to do something like
- Acquire FormattingModel for current open file (ie, the one that I have just inserted the snippet into), I can't use a specific formatter even if I knew how because my plug-in will insert language-specific code snippets (ie, if you're using Java, a java code snippet will be inserted, if Kotlin, then a Kotlin one, etc), and the formatting rules might be language-dependent/specific
- Requesting the formatting operation to be performed
- Committing the changes to the open file
Any help/pointers gratefully received.