How to Add HEREDOC Syntax Highlighting for PHP in Bluefish

Bluefish is a pretty good editor for programmers and web designers which supports syntax highlighting for many languages – PHP included.  While I do like it, there is one little problem when it comes to highlighting PHP code that contains HEREDOC syntax.

I Googled around but failed to find a working solution so I decided to mess around with regular expressions to add my fix.  Guess what?  I got it working.  Here’s how you can add HEREDOC syntax highlighting for PHP In Bluefish.

  1. In Bluefish, click Edit -> Preferences.  Then select the Syntax Highlighting tab
  2. Select “php” from the filetype dropdown
  3. Type HEREDOC in “Pattern Name”.  Don’t click “Add” yet.
  4. Choose “Only Start Pattern”
  5. Type <<<([A-Z]+)\n.*?\n\1; in the “Start Pattern” field
  6. Type ^PHP Block$ in the “Parentmatch” field
  7. Type #009900 in the Foreground color field
  8. Select the “force non-bold weight” and “force non-italic style” radio buttons
  9. Click “Add”
  10. Scroll down to the bottom, click HEREDOC and click “Up” until HEREDOC is placed just above “Operators”
  11. Now, select “Operators” and change its “Start pattern” to [\+\-\*\/\.<>=`!%]+?(?!\?php)
  12. Click “Apply” then click “OK”

Bluefish should now properly apply syntax highlighting to strings defined the HEREDOC way.

 
December 15th, 2008
PHP Programming

2 Responses to “How to Add HEREDOC Syntax Highlighting for PHP in Bluefish”

  1. Dustan says:

    Thanks for this, you’re the MAN!!!! I just wish I would have read this when you first published it :(

  2. Waterbug says:

    In Bluefish 2.0.0 there is no “Syntax Highlighting” tab in Edit -> Preferences. I wonder what version of Bluefish is being discussed here? Some people might think that useful info. I will continue my search, going thru endless out of date web sites that will be stuck on the web for all eternity.