Tuesday, September 18, 2007

GNU Source-highlight 2.8

Apart from the usual bug fixes, the main novelties of this release are:

  • Language definition for S-Lang (thanks to John E. Davis)
  • Perl and Javascript highlighting was improved
  • C-style comments are not defined as nested (I swear I never knew this, though I've been programming in C++ and Java for years... shame on me :-)
  • The padding character of line numbers can be specified (it does not have to be 0, e.g., it could be a blank space), thanks to Roger Nilsson.
Furthermore, I extended the language definition syntax a little bit, in order to handle, what I called, dynamic backreferences (to distinguish them from the backreferences of standard regular expressions).

With dynamic backreferences you can refer to a string matched by the regular expression of the first element of a delim specification. This is crucial in cases when the rigth delimiter depends on a subexpression matched by the left delimiter; for instance, Lua comments can be of the shape --[[ comment ]] or --[=[ comment ]=], but not --[=[ comment ]] neither --[[ comment ]=] (furthermore, they can be nested). Thus, the regular expression of the right element depends on the one of the left element.

A dynamic backreference is similar to a variable, but there's no declaration, and have the shape of


where number is the number of the marked subexpression in the left delimiter (source-highlight will actually check that such a marked subexpression exists in the left delimiter).

For instance, this is the definition of Lua comments (see also lua.lang):

     environment comment delim `--\[(=*)\[` "]" + @{1} + "]"
multiline nested begin
include "url.lang"

Notice how the left delimiter can match an optional =, as a marked subexpression, and the right delimiter refers to that with @{1}.

Source-highlight will take care of escaping possible special characters during dynamic backreference substitutions. For instance, suppose that you must substitute | for @{1}, because we matched | with the subexpression [^[:alnum:]] in a delim element like the following one:

     comment delim `([^[:alnum:]])` @{1}

Since | is a special character in regular expression syntax source-highlight will actually replace @{1} with \|.

Finally, although this is not related to this new release of source-highlight, Roger Nilsson wrote a frontend for source-highlight that is used in a popular webdesign app for OSX called RapidWeaver. The frontend is called High-Light and allows users to easily add syntax-colored code inside RapidWeaver.


Monday, September 17, 2007

Italian Hyphenation in OpenOffice (Debian)

I'm using LaTeX for most of the time for my writings, but for simple and small documents (e.g., letters) I prefer to rely on OpenOffice. I'm actually Italian, but I write most of my documents in English... sometimes, though, I have to go back to my mother tongue ;-) Thus, I wanted to use hyphenation in OpenOffice, under Debian, and so I installed the related packages, in particular, openoffice.org-hyphenation-it.

Unfortunately, hyphenation still did not work... Then, Kent West, in the debian-user mailing list, told me to install hyphenation packages directly from OpenOffice, and it worked! (Thank you Kent!)

I had never used such functionalities in OpenOffice, and they work great! I used the menu File->Wizards->Install Dictionaries and it does most of the work automatically, you just need to retrieve the list of available dictionaries and choose the one you want. Then, you'll find the corresponding dictionary in Options->Language Settings->Writing Aids.