C/C++ Live Template "Edit Variables" dialog doesn't show an editable Expression field (unlike other languages)
Hi,
I'm trying to create a custom Live Template in CLion for C/C++ that generates an adaptive comment separator line, where the number of dashes is computed dynamically from a groovyScript() macro depending on the current line's indentation and the length of a typed variable.
The template body is:
// $LEFT$ $TEXT$ $RIGHT$
expected result : a line of 80 chars with the number of dash computed automagically.
// ----------- the text -----------LEFT and RIGHT are meant to hold an expression like:
groovyScript("def d=_editor.getDocument(); def l=_editor.getCaretModel().getLogicalPosition().line; def s=d.getLineStartOffset(l); def e=d.getLineEndOffset(l); def t=d.getText(new com.intellij.openapi.util.TextRange(s,e)); def i=0; while(i<t.length()&&Character.isWhitespace(t.charAt(i))) i++; def tl=_1==null?0:_1.length(); def budget=80-i-3-2-tl; def n=(int)(budget/2); if(n<1) n=1; return '-'*n", TEXT)The problem: when the template's applicable context is set to C/C++, the "Edit Variables" dialog does not give me any editable field to type this expression into — I only get a list of predefined macros to pick from, with no way to enter free text/a custom expression.
When I set the applicable context to another language instead, the Expression field behaves as expected (a normal editable text field with autocomplete, where I can type a custom groovyScript(...) expression).
Is this a known limitation of Live Templates scoped to C/C++, or a bug? Is there a workaround to define a custom expression-based variable for a C/C++-scoped Live Template?
For context: I asked an AI coding assistant for help configuring this, and it proposed the setup above, but we couldn't get the Expression field to become editable in the C/C++ context specifically — everything works as described for other languages.
CLion version: [precise ta version, ex. 2026.2.1]
OS: [fedora 43]
Thanks!
请先登录再写评论。
Hello!
I'm asking, because for C/C++, the Nova engine uses the templates from Settings | Editor | Live Templates | C/C++, and they should be created there.
Hi Anna and thank you very much for your answer
I first tried in live templates c++ and I could not find a way to get what I want.
Then, I just tried, out of curiosity, in other languages, but I saw and understood that this was not the right place !
Olivier Lemaire, thank you for the clarification!
The current implementation of C/C++ live templates in CLion (Settings | Editor | Live Templates | C/C++) does not expose an equivalent of
groovyScript()function for live template variables.Feel free to create a feature request in the Rider tracker (https://youtrack.jetbrains.com/issues/RIDER), since this functionality (C/C++ live templates) comes to CLion from Rider.