Configuring jEdit

Last updated on
September 30, 2016 - 16:11

jEdit "is a mature programmer's text editor" with support for lots of programming language and text file formats, and many plugins to extend its capabilities. It is written in Java, making it available across various platforms.

Out of the box it supports editing Drupal-related files including PHP, HTML and XML.

To meet the Drupal coding guidelines make the following settings in Global Options 1) Click on Editing, 2) Under "PHP": Click 'Default Settings' (to turn that off), set tab width and indent width to '2', and to use soft tabs. Do the same for Javascript and HTML.

I find it helpful to turn on line numbering in the gutter. While having the Global Options menu open, click on 'Gutter' and select line numbering.

In the Global Options section, 'General', an important option is the default line separator. It should probably be set to Unix (using '\n').

There are some useful plugins to install. From the Plugin Manager (Plugins menu) click on the Install section. It shows you the list of available plugins and you can select them as desired.

FTP lets you treat files on FTP or SFTP servers as if they were part of the file system. Once this is installed, choose Open File and under plugins see FTP and that it has two choices Connect to FTP server and Connect to SFTP server. Fill in your user name and password as appropriate and away you go.

The plugins include jEditCVS and SVNplugin for interfacing with source code repositories.

Two plugins interface with database servers, DBTerminal and SQL.

PHPParser adds additional PHP editing features beyond syntax coloring.

Drupal syntax highlighting

Note this information is adapted from the Übercart web site with permission.

With all of Drupal's myriad functions, it can be nice to be able to differentiate between them and PHP's functions. jEdit allows users to write and modify the XML files that define its syntax highlighting to achieve this.

First off, download one for Drupal 5.x or generate (see below) the XML file and put it in jEdit's 'modes' directory. Next tell jEdit about it. Open up the 'catalog' file in the 'modes' directory. Between any two <MODE> tags insert the following:


<MODE NAME="drupal" FILE="drupal.xml" /> 

You can put it after "doxygen" to maintain alphabetical order.

Next open up php.xml from the same directory (preferably in jEdit, it'll catch mistakes with ErrorList). In it you'll find a section that is a list of all the keywords in the PHP language. Right before that section, before the <KEYWORDS> tag, insert the following code:


<IMPORT DELEGATE="drupal::MAIN"/> 

With all the files saved, jEdit should highlight Drupal functions like theme() and db_query() as KEYWORD4. The appearance of KEYWORD4 can be changed under Utilities >> Global Options >> Syntax Highlighting. By default PHP mode doesn't use KEYWORD4, so there should be no conflicts.

Updated XML files for Drupal can be generated in several ways. One is to enable all the core Drupal modules on a clean install and execute the following code in a PHP-format node:


if ($file = fopen("files/drupal.xml", 'w')){ fwrite($file, "<?xml version=\"1.0\"?> <!DOCTYPE MODE SYSTEM \"xmode.dtd\"> <MODE> <RULES> <KEYWORDS> <!-- Drupal functions --> "); $functions = get_defined_functions(); foreach($functions['user'] as $func){ fwrite($file, ' <KEYWORD4>'. $func. "</KEYWORD4>\n"); } fwrite($file, " </KEYWORDS> </RULES> </MODE>"); fclose($file); } 

One thing users might want to do is add the FILE_NAME_GLOB attribute to the catalog entry, like this:


<MODE NAME="drupal" FILE="drupal.xml" FILE_NAME_GLOB="*.{module,inc,info}"/> 

so Jedit can apply the syntax highlighting to files with Drupal extensions only.

Configuring the PHP Parser plugin

If you use the PHPParser plugin, there are a few configuration options that you might want to change to make it work better with Drupal's coding standards. Go to Plugins > Plugin Options... > PHP Parser and make the following changes:

  • Enable PHP 5 support
  • Enable the warning when <? is used instead of <?php
  • Disable the warning when the final closing ?> is omitted

You would also like to enable most of the other optional warnings, with the exception of 'unused parameters' which are quite common with Drupal's hook and theme systems and don't warrant a warning.

Configuring the TextFilter plugin

The Coder module includes a standalone script named coder_format.php which you can run on your code files to format them according to the Drupal coding standards. You can use this to reformat code directly from within jEdit. There's a plugin called Text Filter which allows you to pass the contents of an edit buffer through any command, and capture the output. The coder_format script doesn't handle its input and output in the way Text Filter expects, but this is easily solved by creating a tiny wrapper script:

  require_once realpath(dirname($_SERVER['PHP_SELF'])) .'/coder_format.php';
  echo coder_format_string_all(file_get_contents('php://stdin'));

Save this script in the coder/scripts/coder_format directory. Then in jEdit, select Plugins > Text Filter > Create new filter from the menu. Enter an action name for the filter (e.g. "Coder"), and in the Command box, enter the full path to your PHP executable followed by the full path to the wrapper script above. I also prefer to change the Destination to "Replace", but that's up to you. Click "Create" to create the filter.

Now you should have a new menu item, Plugins > Text Filter > Coder, which will attempt to format the current buffer according to the Drupal coding standards.