0

I have an expression in java:

str.trim() 

and I would like to "transform" it to:

myFunction(str.trim())

The only things I would like physically do are:

  1. Select the initial expression
  2. Press the magic key
  3. just write "myFunction" (I would not type the parenthesis, or move the caret at all, and ideally I would get a suggestion upon ctrl+space for myFunction).

Is it possible? (live templates did not help)

EDIT: This question was marked as a duplicate of Custom surround template which is not the case, since the specific question describes how to create a live template for a a specific surround, eg console.log($SELECTION$). My question is more generic, as I do not want to define a live template for each and every case, but something the will work anywhere, anytime, within of course the editing context.

Community
  • 1
  • 1
yannisf
  • 6,016
  • 9
  • 39
  • 61
  • Live templates do actually help; see linked question for more information. – yole Dec 03 '16 at 08:35
  • @yole Please review the last edit, where I explain why I do not consider live templates and the referred question as a solution. – yannisf Dec 03 '16 at 10:19
  • Live templates can contain variables. You can define a variable in your live template that will hold the name of the function to call. – yole Dec 03 '16 at 10:38
  • Yes, but the variable will be the $SELECTION. What will be around the selection should be statically defined in the template. I do not want to statically define that. I want to be able to use anything valid within the context there. This is the reason I do not consider the question duplicate. – yannisf Dec 03 '16 at 10:43
  • No. You can define multiple variables - one for $SELECTION$ and the other for the function name. – yole Dec 03 '16 at 11:22
  • @yole I honestly cannot see how this could work. Somebody could have answered the question if it was not marked as duplicate. Perhaps you can provide a concrete example? – yannisf Dec 03 '16 at 18:31
  • Concrete example: define a live template as $FUNCTION$($SELECTION$), press "Edit variables", enter "complete()" as expression for $FUNCTION$, select your piece of code, press "Surround with live template", select your template. – yole Dec 04 '16 at 10:21

0 Answers0