include variable in function autocompleted

It is possible that when I write an autompleted function beside a variable, that variable will be included in the parentheses of that function that has been generated.

Example:


Writing ucfirst beside the $text variable, and then generate ucfirst($text) instead of ucfirst()$text

8 comments
Comment actions Permalink

Hi there,

If I understand you correctly, you may create Live Template of surround kind and use it for that: https://www.jetbrains.com/help/phpstorm/using-live-templates.html

1. Create such Live Template first

2. Once ready to use it: select your variable

3. Invoke "Code | Surround with Live Template" and choose right template.

You can configure such live template to automatically invoke code completion popup in the right place (for function name).

0
Comment actions Permalink

Hello Andriy,

Live template is not valid for me, this does it for a specific function/method and I want it for all the autocompleted functions of (PHP/Custom Method around the project) that require a parameter and the variable is next to it, I think this did some editor but now I do not remember that editor exactly to this.

 

thanks

0
Comment actions Permalink

>Live template is not valid for me, this does it for a specific function/method and I want it for all the autocompleted functions

So .. what is the problem? Why Live Template cannot be used here? You do not need to hardcode function/method name here -- allow IDE to autocomplete it (use Live Template variable)

0
Comment actions Permalink

Then I don't know how to do it with live template

0
Comment actions Permalink

Thank you very much really, I did not know the power of Live Template until you gave me the example and the truth that works, but I have to select the text and then remember the abbreviation. Well in general fine, but I would like you to consider it as an option to be able to choose in PHP options without having to select.

Thanks again.

0
Comment actions Permalink

Well ... it's not available .. and from what I remember the exact or similar solution was offered in similar cases.

Anyway, lets assume you have this code:

$abc = "aaa";

echo $abc;

Now you want to strtoupper the $abc in echo statement.

1. Place caret before $abc

2. Start typing / complete desired function (with Enter not Tab, so it's just insert it there). You will end up with

echo strtoupper([CARET_HERE])$abc;

3. Delete closing bracket ) and invoke Complete Statement shortcut (Ctrl+Shift + Enter). You will end up with

echo strtoupper($abc);

 

If you have more complex statement (e.g. "echo $abc . $moo;") and you want to upper case only first variable, it will work differently as you are joining strings here so IDE will apply that to both variables ("echo strtoupper($abc . $moo);")

1
Comment actions Permalink

That works very well too, thank you very much for your support.

0

Please sign in to leave a comment.