Here are the instructions I wrote up at work for installing a PHP Beautifier macro on Komodo Edit (a free code editor):
The following describes a method for adding a macro to Komodo Edit (free, open-source programming editor) that will automatically format PHP code (indents, consistent placement of braces, etc.). The basic process consists of installing PEAR, then using PEAR to install the necessary PHP packages, and creating the Komodo macro to fire everything off.
Install PEAR
Go to pear.php.net and download the go-pear.phar installer file to your PHP directory, then from a cmd window run:
php go-pear.phar
I just accepted the default options for everything, IIRC.
Install PHP_Beautifier
Once PEAR is installed, from you cmd window run:
pear install –a PHP_Beautifier-beta
To fix some deprecated code that throws warnings in PHP 5.3.x, edit C:\PHP\pear\PEAR\Config.php and C:\PHP\pear\PEAR\Registry.php (change path to fit your installation), changing all occurrences of = & to just = in both files, and in the latter file change the one remaining instance of &new to just new.
Create the Macro
In Komodo Edit, open the Toolbox if not already open (View > Toolbar > Tools). Click the Toolbox’s options icon, and select New Macro. In the new macro editor window, make sure the JavaScript option is selected, then copy and paste this code into it:
komodo.assertMacroVersion(3);
if (komodo.view.scintilla) { komodo.view.scintilla.focus(); } // bug 67103
var formatter;
var language = komodo.document.language;
var cannot_tidy_selection = false;
switch (language) {
case 'C':
formatter = 'astyle --style=linux';
break;
case 'C++':
formatter = 'astyle --style=kr';
break;
case 'C#':
formatter = 'astyle --style=ansi';
break;
case 'HTML':
cannot_tidy_selection = true;
formatter = 'tidy -q -utf8 -asxhtml -i -w 80';
break;
case 'Java':
formatter = 'astyle --style=java';
break;
case 'Perl':
formatter = 'perltidy';
break;
case 'PHP':
formatter = 'php_beautifier.bat -t1 -l"Pear()" -l"ArrayNested()"';
break;
case 'XLST':
case 'XML':
case 'XUL':
cannot_tidy_selection = true;
formatter = 'tidy -q -utf8 -xml -i -w 80';
break;
default:
alert("I don't know how to tidy " + language);
exit(1);
}
//save current cursor position
var currentPos = komodo.editor.currentPos;
try {
// Save the file. After the operation you can check what changes where made by
// File -> Show Unsaved Changes
komodo.doCommand('cmd_save');
// Group operations into a single undo
komodo.editor.beginUndoAction();
// Select entire buffer & pipe it into formatter.
//komodo.doCommand('cmd_selectAll');
//Run_RunEncodedCommand(window, formatter + " {'insertOutput': True, 'operateOnSelection': True}");
//var text_not_selected = komodo.editor.selText == "";
var text_not_selected = cannot_tidy_selection
|| komodo.editor.selText == "";
if (text_not_selected) {
komodo.doCommand('cmd_selectAll');
}
Run_RunEncodedCommand(window, formatter + " {'insertOutput': True, 'operateOnSelection': True}");
if (text_not_selected) {
komodo.editor.gotoPos(currentPos);
}
// Restore cursor. It will be close to the where it started depending on how the text was modified.
komodo.editor.gotoPos(currentPos);
// On windows, when the output of a command is inserted into an edit buffer it has unix line ends.
komodo.doCommand('cmd_cleanLineEndings');
} catch (e) {
alert(e);
} finally {
// Must end undo action or may corrupt edit buffer
komodo.editor.endUndoAction();
}
I have my PHP directory in my Windows path environment variable, but if you don’t, you may need to edit the line that calls php_beautifier.bat to use the full path. Save it with the desired macro name (e.g.: “phpBeautifer”). Then whenever you double click that item in your Komodo Edit toolbox, it will format the active file in the editor (I hope).