Using Nano (Syntax Highlight) for Drupal Module development

Submitted by Janak on Thu, 08/06/2009 - 12:10

I mostly use Eclipse IDE as my main development environment for Drupal, but have got into the habit of using nano (in emergency situations) to patch and edit my Drupal modules. Often I find it frustrating to with with nano without any kind of syntax highlighting, specially when trying to scan through a big module. A little googling around and I found a way to enable PHP syntax highlighting for nano (rather simple):

PHP syntax highlighting for nano:

Create a nano config file in your home folder

nano ~/.nanorc

add the following lines to .nanorc file

include "/usr/share/nano/php.nanorc"
include "/usr/share/nano/sh.nanorc"
include "/usr/share/nano/java.nanorc"
include "/usr/share/nano/patch.nanorc"
include "/usr/share/nano/python.nanorc"
include "/usr/share/nano/html.nanorc"
include "/usr/share/nano/perl.nanorc"
include "/usr/share/nano/ruby.nanorc"
include "/usr/share/nano/js.nanorc"

Note:
If you cannot find any of the included files in your /usr/share/nano/ folder, you can download/copy-paste the code from nanosyntax google code project and create a new syntax file like this:

sudo nano /usr/share/nano/php.nanorc

Paste the syntax code you copied from google project (link above)

OK, done. Now you have basic PHP Syntax Highlighting, but it still doesnt work for:
*.engine, *.theme, *.install, *.inc and *.module files...

Drupal specific syntax highlighting for nano:

We need to edit the php.nanorc file and add our additional drupal specific extensions so these are identified as PHP files:

sudo nano /usr/share/nano/php.nanorc

Add in additional file extensions like this:

syntax "php" "\.php[2345s~]?$" "\.module?$" "\.inc?$" "\.theme?$" "\.engine?$" "\.install?$"

Done, now PHP Syntax Formatting will work for all Drupal specific files, makes life a little easier.

Update: Custom Color Highlight for core Drupal functions

After a quick brainstorm with my friend and colleague Nick Thompson, we figured its possible to add custom color highlighting for core Drupal functions. Add a new color rule followed by functions names to your php.nanorc file, like so:

## Drupal functions
## change to a color of your choice and add pipe seperated function names
color red "(drupal_bootstrap|drupal_goto|bootstrap_invoke_all|drupal_load)"

To get a list of all Drupal functions, you can run a command like this (thanks Nick):

grep "^function" * -hR | gawk '{ sub(/\(.+/, "", $2); print $2 }' | tr '\n' '|'

Add the pipe seperated list of function names to the file above and its good to go.