6. Customising Bluefish

6.1. Modifying shortcut keys
6.2. Showing hidden files and folders
6.3. Showing backup files
6.4. Editor appearance
6.5. Customizing the bookmarks path
6.6. Customizing the html tags style
6.7. Changing the author meta tag on the fly
6.8. Customizing files handling and browsing
6.8.1. Setting the encoding meta tag on save
6.8.2. Setting the default base directory
6.8.3. Merging file browser views
6.8.4. Backup files
6.8.5. Using multiple instances of a file
6.9. Customizing the user interface
6.10. Modifying file types
6.11. Modifying the files filters
6.12. Modifying the highlighting patterns

We have already seen how to customize the quick bar, the Custom menu, and the External menu. Here are some other possibilities, most of them being made through the Edit preferences panel, accessible from the Preferences... icon in the main tool bar or from the EditPreferences menu item.

6.1. 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.

To add or change a shortcut, move the mouse over the desired 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.

Here's a shortcut added to the FileOpen URL... menu item:

Figure III.110. Adding a shortcut to a menu item

A screen shot showing how to add a shortcut to a menu item

To remove a shortcut, 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 EditSave Shortcut Keys. This will store the settings in the ~/.bluefish/menudump_2.

[Note]

If you want to restore the default combinations simply remove this file and restart Bluefish.

[Warning]

Be aware that if you give a menu entry the same shortcut as another one, the shortcut of the latter will be lost.

6.2. Showing hidden files and folders

By default, invisible files and folders are not shown in the file browser tab of the side panel.

If you want to see them at a given level of the files system hierarchy, right click on the desired folder name in the file browser within the side panel and toggle Show hidden files in the contextual menu.

Here is how to view all visible files and folders in the whole system:

Figure III.111. Turning files and folders visibility on

A screen shot showing how to turn files and folders' visibility on the whole system
[Tip]

This feature is very convenient for Mac users when used with caution, since combined with the Delete contextual menu in the file browser, it allows you, for example, to get rid of files generated by cvs on conflicts within bluefish.

6.3. Showing backup files

By default, backup files are not shown in the file browser tab of the side panel.

You may turn on their visibility at a given level of the file system by right clicking on the desired folder name in the file browser within the side panel and toggle Show backup files in the contextual menu.

6.4. Editor appearance

Most of the editor appearance depends on your GKT theme, which may be customized through the ~/.gtkrc-2.0 resource file.

Parts that you may want to customize through that resource file are among others:

  • the background color of the editor

  • the colors of GUI elements

  • the position of arrows in a drop down list

You will find examples of themes resource files while searching for a gtkrc file in a gtk-2.0 folder within the various directories under $prefix/share/themes/, where $prefix is your installation prefix (it may be /usr, /usr/local, /sw, /opt, etc.).

[Warning]

You should not customize those files, instead customize ~/.gtkrc-2.0. If the file does not already exist in your home directory, just create it with: touch ~/.gtkrc-2.0

Here is an example made on a Crux theme:

style "bluefish"
{
 # For up and down arrows grouped together at right side
 GtkNotebook::has_secondary_forward_stepper = 1
 GtkNotebook::has_secondary_backward_stepper = 1
 
 # Editor background color 
 # (background of editor view)
 base[NORMAL]="#fcfff5"
 
 # GUI normal background color
 # (most of the GUI)
 bg[NORMAL]="#dbe9e9"
 
 # GUI highlighted background color
 #(GUI when mouse over elements)
 bg[PRELIGHT]="#c6e9e9"
 
 # GUI unactive background color
 #(GUI disabled elements)
 bg[INSENSITIVE]="#9fb2b2"

 # GUI active background color
 #(GUI enabled elements)
 bg[ACTIVE]="#c7d4d4"
}
class "GtkWidget" style "bluefish"
[Note]

You may give any name to the style on the first line, provided that you use the same on the last line.

The customization applies to any Gtk application.

It will give this appearance to bluefish:

Figure III.112. Bluefish with a customized Gtk theme

A screen shot of Bluefish with a customized Gtk theme

Other options for the Editor are available in the Editor tab of the Edit preferences panel accessible via the Edit preferences... button in the main tool bar. In particular you may want to customize the font of the editor, the end of line wrapping, and the undo history size:

Figure III.113. The Editor tab in Preferences

A screen shot of the Editor tab in Preferences

6.5. Customizing the bookmarks path

When you add bookmarks to document, the name of the file it refers to is displayed from the base directory. You can choice another path from the Bookmarks filename display pop up menu in the Editor tab of the Edit preferences panel:

Figure III.114. The Bookmarks path pop up menu in Preferences

A screen shot of the Bookmarks path pop up menu in Preferences

6.6. Customizing the html tags style

The HTML tab of the Edit preferences panel provides you with some options to change the style of the html tags:

Figure III.115. The HTML tab in Preferences

A screen shot of the HTML tab in Preferences

6.7. Changing the author meta tag on the fly

One interesting feature in the HTML tab of the Edit preferences panel is that you can let bluefish update the author meta tag on save.

Let's say you created an html file with an author meta tag while you were logged in as user foo. On save bluefish will fill up the contents attribute of the author meta tag with the full name associated with the foo user:

Figure III.116. The author meta tag filled in on save

A screen shot of the author meta tag filled in on save

You share this html file with another user bar or you change the owner of the file to bar. When you modify the html file while logged in as user bar, the author meta tag is updated to reflect the new author on save, providing that the user bar has write permission on the file:

Figure III.117. Update of the author meta tag on save

A screen shot of the author meta tag updated on save
[Warning]

If you do not want that the author meta tag be changed while editing the file under another user's login, uncheck the box.

6.8. Customizing files handling and browsing

The Files tab of the Edit preferences panel allows you to set some options related to the way files are handled and displayed in the file browser.

Figure III.118. The Files preference panel

A screen shot of the Files preferences panel

6.8.1. Setting the encoding meta tag on save

Apart from setting the default character encoding in the Files tab of the Edit preferences panel, you may also instruct bluefish to set the encoding meta tag when you modify the document character set encoding.

Note that, if the encoding meta tag does not exist, it is inserted in the file, otherwise it is changed. Either modification occurs immediately.

6.8.2. Setting the default base directory

You can set a default base directory in the Files tab of the Edit preferences panel.

This directory will serve as the initial point for the file browser.

6.8.3. Merging file browser views

By default, the file browser uses separate views for files and directories.

You can have a single view by unchecking the Use separate file and directory view option in the Files tab of the Edit preferences panel.

6.8.4. Backup files

By default, a backup file is created on save in the same directory as the original file based on the same filename with the exception that a ~ suffix is added. This backup file is deleted on closing the file.

You can change this behaviour in the Files tab of the Edit preferences panel.

When the backup fails to be created, you can choose what to do:

Figure III.119. Choosing an action on backup failure

A screen shot of the action on backup failure pop up menu

6.8.5. Using multiple instances of a file

A nice feature of bluefish is it allows you to open multiple instances of a file. Combined with either launching two instances of bluefish or opening the same file in two windows, it eases the modification of a file in one window while browsing it in another one.

This feature can be disabled in the Files tab of the Edit preferences panel.

[Warning]

Be aware that the last closed instance of the file wins. Hence it is important that you remember which instance is the modified one. You can, for example, always open the file to be modified on the left side of your screen, the file to be browsed on the right side.

6.9. Customizing the user interface

The User interface tab of the Edit preferences panel allows you to customize most part of the user interface:

Figure III.120. The User interface preference panel

A screen shot of the User Interface preferences panel

6.10. Modifying file types

In the Filetypes tab of the Edit preferences panel you can define all file types that should be recognized by bluefish.

The file types consist of:

  1. a label (this label is also used in the file filters, and in the highlighting patterns).

  2. a list of extensions, separated by a colon (:).

  3. 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 \\.

  4. the icon location for this file type.

  5. whether this file type is editable by Bluefish (whether or not Bluefish should try to open it after a double click).

  6. a regular expression that can be used to detect the file type if a file without extension is loaded.

  7. 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.

You add, modify, delete, or move file types the same way it is described in Section 5.8.1, “Customizing browsers”.

Example III.5. Adding a file type

Let's say you use DocBook xsl stylesheets. Those files are recognized by bluefish as xml files, but they do not appear with the xml icon in the file browser as their extension (.xsl) is not listed in the Extensions field of the Filetypes tab of the Edit preferences panel.

On the other hand, adding them to the xml file type would impede to group them into a stylesheet filter, where they belong from a semantical point of view. And you cannot add them to the provided stylesheet filetype made for css stylesheet, since the highlighting patterns are different.

To add an xsl stylesheet file type, execute the following steps:

  1. Click on the Preferences... icon in the main tool bar to access the Edit preferences panel.

  2. Click on the Filetypes tab to display the Filetypes panel.

  3. Click on the Add button in the Filetypes part. A new line will be shown, with an Untitled label.

  4. Double-click on the label to allow editing, and enter the string you want to appear in the Label field. Here enter xsl stylesheet.

  5. Click in the Extensions zone and enter the extension: .xsl.

  6. Click in the Update chars field of the xml filetype line to copy and paste this field into the corresponding field of the xsl stylesheet filetype line. Once the field is highlighted, use Ctrl-C to copy the field. Click again in the Update chars field of the xsl stylesheet filetype line and use Ctrl-V to paste the field.

  7. For the icon field, you can either use the xml icon path used in the Icon field of the xml filetype line or better create a new icon based on the xml one by changing its colors with the Colormap Rotation filter of gimp, located under the FiltersColorsMap... menu.

    To do it, first copy the xml icon on your Desktop, apply the filter on it, and save it under bluefish_icon_xsl.png in a dedicated folder in your home directory, for example ~/Pictures for Mac users.

    Whichever icon you decided to use, click on the Icon field to enter its path.

  8. Check the Editable box, if it is not already checked.

  9. Copy and paste Content regex field of the xml filetype line into the corresponding field of the xsl stylesheet filetype line.

  10. Set the Auto close tags mode to 1.

  11. Click on the OK button to save and close the panel.

[Note]

If you want to enter more than one extension in the Extensions field, you should separate them with a colon.

When you define a new filetype, you should also provide new highlighting patterns.

6.11. Modifying the files filters

The files filters allow you to group files types from the usage point of view. Once a file filter is created, you can view, hide, or open files based on a filter in the File browser contextual menu.

The file filters consist of:

  1. a label.

  2. whether or not the filter as defined in the Filetypes in filter hides the retrieved files or shows them.

  3. a list of filetypes, as defined in the Filetypes part, separated by a colon.

You add, modify, delete, or move file types the same way it is described in Section 5.8.1, “Customizing browsers”.

Example III.6. Adding a file filter

Following with our example in Section 6.10, “Modifying file types”, we can add a stylesheet filter to group css and xsl stylesheets together.

To add a stylesheet filter, execute the following steps:

  1. Click on the Preferences... icon in the main tool bar to access the Edit preferences panel.

  2. Click on the Filetypes tab to display the Filetypes panel.

  3. Click on the Add button in the Filefilters part at the bottom. A new line will be shown, with an Untitled label.

  4. Double-click on the label to allow editing, and enter the string you want to appear in the Label field. Here enter All stylesheets.

  5. Check the Inverse filter box.

  6. Click in the Filetypes in filter field and enter the filetypes you want to group together, separated with a colon. Here it is stylesheet:xsl stylesheet.

  7. Click on the OK button to save and close the panel.

[Important]

The file types used in the Filetypes in filter match those defined in the Filetypes part. Do not confuse them with the file extensions. For example the C programming file filter matches c and image filetypes, i.e. files whose extensions are .c, .h, etc...

6.12. Modifying the highlighting patterns

The highlight patterns are build from Perl compatible regular expressions. A pattern has options for coloring and styling 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. Start pattern and end pattern: that is two distinct patterns, match from the start pattern to the end pattern

  2. Only start pattern: that is a unique pattern that matches from start to end

  3. Subpattern from parent: that is a subpattern from the parent pattern, specified by the range in 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:

Figure III.121. The HTML pattern

A screen shot of the HTML pattern

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 a type 2 pattern. Again, the lowest match will count. The pattern named <html> Tags:

Figure III.122. The <html> Tags pattern

A screen shot of the <html> Tags pattern

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> Tags 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 Attributes:

Figure III.123. The HTML Attributes pattern

A screen shot of the HTML Attributes pattern

has the lowest match:

align="center"

This pattern does have a child pattern, again a type 3 pattern called HTML Attribute Contents:

Figure III.124. The HTML Attribute Contents pattern

A screen shot of the HTML Attribute Contents pattern

matching:

"center"

The pattern HTML Attribute Contents does not have any child patterns, and subpatterns of HTML Attributes 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 Block:

Figure III.125. The PHP Block pattern

A screen shot of the PHP Block pattern

has the lowest match. This is a type 1 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 Block, but it will also ue it for the end pattern of PHP Block. The lowest match in this example is a pattern named Comment (C++/single line):

Figure III.126. The Comment (C++/single line) pattern

A screen shot of the Comment (C++/single line) pattern

As you can see the ?> within the comment does not end the php pattern, because it lies within a subpattern of PHP Block:

// this is a comment ?>

The pattern Comment (C++/single line) 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 III.127. 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.

As an exercise you may want to add the highlighting patterns for the xsl stylesheet file type created previously. They will be based on the xml patterns with just small changes.

[Note]

If you check the force bold weight check box, you should also check that the font you use has a bold variant in the Editor tab of the Preferences panel.