Customising Bluefish

Most of customization can be made through the Edit preferences panel, which is divided into several tabs.

Modifying shortcut keys

Many menu entries are accessible via key combination; also called a shortcut. For example, pressing the Ctrl-S keys saves the current file to disk. If available, shortcut key combinations are shown on the right of the menu entry.

What many people do not know is that they can be changed. Move the mouse over a menu entry, and press the key combination you would like to use. Immediately this combination will show up on the right of the menu entry. An entry can also be removed, press the backspace key when you move the mouse over a menu entry to remove the shortcut.

To save the shortcut key combinations for later Bluefish sessions, use Edit->Save Shortcut Keys. This will store the settings in the ~/.bluefish/menudump_2. If you want to restore the default combinations simply remove this file and restart Bluefish.

Editor preferences

The font of the editor can be set in the preferences under Editor.

A frequently asked question is how to change the background color of the editor in Bluefish. Bluefish uses the default editor background color as set in your GTK theme. If you want to override the color of the theme, edit ~/.gtkrc-2.0 and add this section:

style "EditorStyle" {
        base[NORMAL]="#eeeeee"
}
class "GtkTextView" style "EditorStyle"

Obviously, #eeeeee should be your preferred background color.

Modifying file types

Here you can define all file types that should be recognised by Bluefish. The defaults for these file types are retrieved from a file called file types.default in ${prefix}/share/bluefish/.

The file types consist first of a name (this name is also used in the file filters, and in the highlighting patterns). Second is a list of extensions, separated by a colon (:). Third are the highlighting update characters. Upon a key press of one of these characters, the highlighting engine will refresh the highlighting around the cursor. If this field is empty, any character will force the highlighting engine to refresh. Special characters like the tab and the newline can be entered as \t and \n, the backslash itself is entered as \\. Fifth is the icon location for this file type. Sixth is whether this file type is editable by Bluefish (whether or not Bluefish should try to open it after a double click). Seventh is a regular expression that can be used to detect the file type if a file without extension is loaded. Eight is the auto-tag-closing mode. A value of 0 means that Bluefish should not close XML/HTML tags, a value of 1 means it should close the tags XML style (<br />), a value of 2 means HTML style.

Modifying the files filters

TO BE WRITTEN

Modifying the highlighting patterns

The highlight patterns are build from Perl compatible regular expressions. A pattern has options for coloring and style of the text it matches. Within a match other patterns can be used to color parts of that match. There are three types of patterns:

  • 1 Two patterns, match from the start to the end pattern

  • 2 One pattern that matches from start to end

  • 3 Match a subpattern from the parent pattern

One specific pattern can also be used within several other parent patterns. The parent-match option is a regular expression that defines all parents for a certain pattern. If empty it will default to ^top$, so basically it will be on the top level.

So how does it work? Lets take a look at a little example text, a piece of PHP code within some HTML code:

<p align="center">
<?php
// this is a comment ?>
?>

The first thing the highlighting engine does is finding the pattern that has the lowest match. Using the default patterns for PHP, the pattern named html has a match at position 0:

<p align="center">

So now the highlighting engine searches for the lowest match in all subpatterns of html, in the region matched by the type 2 html pattern. Again, the lowest match will count. The pattern named html-tag has a match at position 1. This pattern is a type 3 pattern, so it matches a subpattern of the parent:

p

the match from subpattern html-tag ends at position 2 and it does not have any child patterns, so the highlighting engine continues at position 2 with all subpatterns from html. A type 2 pattern named html-attrib has the lowest match:

align="center"

This pattern does have a child pattern, again a type 3 pattern called html-attrib-sub2 matching:

"center"

The pattern html-attrib-sub2 does not have any child patterns, and subpatterns of html-attrib do not have any more matches, and also html subpatterns do not have any more matches. So we are back on the main level, the remaining code to highlight is:

<?php
// this is a comment ?>
?>

Now a pattern named php has the lowest match. This is a type 0 pattern, so the highlight engine continues with all the remaining code, but it will not only search for the lowest match of the child patterns of php, but it will also use for the end pattern of php. The lowest match in this example is a pattern named php-comment-C++ As you can see the ?> within the comment does not end the php pattern, because it lies within a subpattern of php:

// this is a comment ?>

The pattern php-comment-C++ does not have any child patterns, so the remaining code for the php subpatterns is:

?>

It is very obvious now, the lowest match will be the end pattern of the php pattern, so we're back on the main level, and we have matched all of the code!

Figure 3.97. Syntax highlighting example

A screen shot of a syntax highlighting example

The config file for highlighting is a colon separated array with the following content:

mode:
patternname:
case_sensitive(0-on/1-off):
start reg-ex:
end reg-ex:
start & end pattern(1), only start(2), subpattern(3):
parent-match:
foreground-color:
background-color:
don't change weight(0), non-bold(1), bold(2):
don't change style(0), non-italic(1), italic(2): 

The same options are found in the syntax highlighting preferences.

SCREENSHOT BY ????