How to autocomplete and insert a code block from a standard function

In KomodoEdit 9.2, how can I enable insertion of code blocks for standard PHP functions?
For example: typing switc and being able to autocomplete and insert a blank switch code block like this:

 switch (variable) {
    case 'value':
       # code...
       break;
           
    default:
       # code...
       break;
}

I have enabled PHP as the file language, turned on autocomplete and even tried the ‘fill-up’ feature, but currently the PHP functions will only autocomplete the spelling of the function itself (no block code) and add corresponding closures like () or {}. But I would very much like to add those empty code blocks somehow.

You could use a macro and have the trigger set to whatever word you want.

Does that mean I have to manually define a macro and write the generic block code to display for EVERY php function?

Have a look in the panel on the right under examples then abbreviations and consult the help file,

Thanks @pacav69. Ill have a look in there to see if it is a setting I have missed to enable these standard code blocks. I have been looking in the help files, YouTube videos, and SO for this but so far no luck. My PHP is not very strong, so having the ability to tab complete blank functions is a must-have.
Hate to be the comparison guy, but some other editors have this working out-of-the-box - no macros or manual definitions needed.

Here is the text from the help file

Abbreviations

Snippets saved in a toolbox folder called
“Abbreviations” (or a language-specific sub-directory) can be inserted
by typing the snippet name in the buffer. See Abbreviations.

Auto-Abbreviations
If a snippet is marked as an “Auto Abbreviation”, then typing its
name at the end of a line, followed by a valid trigger character
(e.g. a space), will replace the name and trigger with the
contents of the snippet.

The trigger characters are defined in Preferences / Editor / Smart
Editing/ Auto-Abbreviations. Use the standard JavaScript “” escaping
to describe tabs, newlines and carriage returns (both work the same), and any
non-printable characters using standard “\x” and “\u” notation. Note that
auto-abbreviation can be controlled globally or per-snippet. Also, it’s
usually convenient to include Space as a trigger character, but this isn’t
always desired. Pressing
Shift-Space after an abbreviation suppresses its expansion.

1 Like

I think what you want is autocomplete.

Goto preferences, do a search for php, then under php directories add the directory where the php doc files are located.

@pacav69. Thank you for your patience, I have tried all of those settings and key combinations. The only thing I can guess is there are no snippets available for php standard functions.

If we use the switch example again, in a .php file (language is defined as php), and the file is properly opened with <?php : if I type switc I see a tooltip under the cursor with (info icon)‘Switch’ and (F icon)‘Switch’.

Both of these when selected only adds the ‘h’ to complete the switch word. I have tried all the keyboard combos but nothing will produce a blank syntax block.
In your pervious post, I looked in that section and tried those auto-abbreviations characters (! \t@#$%^&*()+[]{}\|/?:;<,"’), none of them will produce it either.
As per the right hand panel samples under PHP, I looked online to see if there are any packages I might be missing with those macros, but a search yields no macro or abbreviations packages for php.
In the help files, under Snippets, it says to use ctrlT, but when using that combo I get an error saying “No abbreviation for ‘switc’” (I tried with a full typed switch, but still no luck)
I added the full path to the PHP directory that has 2 help doc files in .chm and .html formats, that too does not help.

Again, thanks for any help. (really liking KomodoEdit so far)

I tested macros/snippets and it works like this

  • First goto preferences and check to see if autocomplete is ticked then

  • open the right panel of komodo

  • create a directory named "Abbreviations’

  • under this create a sub directory named “PHP”

  • right click under PHP directory and select add --> snippet

  • name it switch

  • paste in the text above

  • click on the check box ‘Auto-abbreviation’

  • save

  • create a new file and save it
    for example test.php

  • then type in the <?php ?>

after the php type switch followed by a space and it will insert the switch code.

The php docs is the api docs located here http://php.net/download-docs.php

1 Like

@pacav69. Thank you. I can now also get it working like that too.
I guess the short answer is I will have to define all those standard PHP functions manually (hundreds… :expressionless: )

Last question:
In the toolbox to the right, there is the samples folder with a few PHP abbreviations, is there a folder somewhere that has a complete PHP abbreviation set in it? I have looked online and in the packages manager, but somehow still not finding it…
I will continue looking in SO or some other forums, I am pretty sure someone else has required this kind of solution.

I’m not sure. If you didn’t find it under Packages - then you won’t find it anywhere. You can create your own set of PHP abbreviations and then share it with us :smile:

1 Like

@Defman maybe I will :blush:
I have to continue using the other hamstrung editor for now (that has these abbreviations built-in) to finish the current project, but after that I may write some json to automate this in KE. If it works nicely I will share it back to the community.

Cheers

P.S. Would you by chance know if this is included in KomodoIDE?

Nope.

There are no specific snippets for komodo but there is one on github for sublime


that can be used for a basis, just need to modify/edit each of the snippets to be used in komodo
just copy and paste between the dashed lines <![CDATA[ // ========================= switch (${1:expression}) { case ${2:expression}: ${3:// code...} break; $0 default: ${4:// code...} break; }

// ============================================
]]>
switch
language_construct
source.php - comment - constant.other.class - entity.name - meta.catch - meta.class - meta.function.arguments - meta.use - string - variable.other
PHP: switch …