Search code examples
intellij-idealive-templates

Intellij Live Template Dynamic Text


I'm trying to create a "dynamic" Live Template for PyCharm and am hitting a road block (I'm able to create simple templates with variable insertion, no problem). I'm beginning to believe that what I'm trying to accomplish may not be possible. I'm not tied to Groovy Script, but it looks to be the most promising alternative to what I'm trying to accomplish. I'm not able to provide a minimal, reproducible example beyond a simple description. Here's what I'm trying to accomplish:

  • Whatever is typed after hitting TAB and before hitting Enter is passed to the template, formatted and written back to the Editor. My goal is to have the resulting string be a specified length, but that's less important for the time being. It's really more about how to get keyboard input to the template and back out again.

For example:

"blk" TAB "Hello world" Enter becomes
# ==================== Hello world ====================

Is this possible with Live Templates?

EDIT: To be clear, the question here is on how to reformat the typed input and return the formatted input to the output of the template. For example, using the above -- have the resulting "Hello world" line always be 80 characters long.

EDIT2: converting previous comment to an answer to close the loop on this question. Happy to reopen if new information comes to light.


Solution

  • I have confirmed with Jet Brains that the thing I'm specifically trying to accomplish--dynamically formatting typed input to a live template--is not possible within the current IDE (as of version 2020.3).

    Instead, they suggest it will require a custom plugin with specific features related to com.intellij.codeInsight.template.postfix.templates.PostfixTemplate.