User Tools

Site Tools


Sidebar

Index

ide:netbeans-8-no-completion-on-php-code-template

Netbeans 8 no completion on php code template

This problem is about custom code template for PHP and JS and it's bug that has been there for many years.

Problem

You write a code template for PHP or Javascript, but in the editor you have to type it in full and press tab or nothing happens.

Thanks to user markiewb who replied to me on this thread on the Netbeans forum
http://forums.netbeans.org/viewtopic.php?t=64517
the cause is clear: the Netbeans php component doesn't set the code scope in the xml file with the custom templates.

E.g. a template named ech is written down this way

<codetemplate abbreviation="ech" xml:space="preserve">

but should be this other way

<codetemplate abbreviation="ech" xml:space="preserve" contexts="php-code">


Solution

Set the file by hand or, after any change you make in the Netbeans code templates editor, run this simple script I've done right now, and restart Netbeans. No problem running it more than once: it only makes changes where the option is missing.

#!/bin/bash
# set the contexts php on every template that hasn't yet
 
FILEPHP=~/.netbeans/8.0.2/config/Editors/text/x-php5/CodeTemplates/org-netbeans-modules-editor-settings-CustomCodeTemplates.xml
FILEJS=~/.netbeans/8.0.2/config/Editors/text/javascript/CodeTemplates/org-netbeans-modules-editor-settings-CustomCodeTemplates.xml
FILEHTM=~/.netbeans/8.0.2/config/Editors/text/html/CodeTemplates/org-netbeans-modules-editor-settings-CustomCodeTemplates.xml
 
sed -i -e 's/xml:space="preserve">/xml:space="preserve" contexts="php-code">/g' $FILEPHP
sed -i -e 's/xml:space="preserve">/xml:space="preserve" contexts="javascript">/g' $FILEJS
sed -i -e 's/xml:space="preserve">/xml:space="preserve" contexts="html">/g' $FILEHTM

Remember to change the var FILE with the proper path. You'll probably have to change only the version number.

Quite obvious but… if Netbeans is open when you run the script, remember to restart Netbeans or it won't see the changes.

ide/netbeans-8-no-completion-on-php-code-template.txt · Last modified: 2015/11/03 17:18 by rik