APP-C>

In order to write Mason components, you don't need anything fancy. You can do just fine with any old ramshackle text editors> components;writing> components;editing> Mason;text editors for> text;editing> text editor -- even (horrors!) a word processor that can save as plain text will do.

However, an editor that helps you manage the details of the document you're creating can be a nice mini-luxury. Several different editors can easily be trained to understand the structure of Mason components, with varying degrees of assistance (or interference, depending on how much help you're looking for). In most cases, this is due to the work of Mason developers who created syntax definitions and offered them to the general public. If you find shortcomings, the polite thing to do is to drop a note to the developer, offering a fix if possible.


Emacs

APP-C-SECT-1>

Both authors of this book are enthusiastic users of Emacs (text editor)> Emacs and its wonderful cperl-mode for editing plain Perl code;editing> Perl code, courtesy of Ilya Zakharevich, Ilya> Zakharevich. However, while one can just turn cperl-mode on for an entire Mason component and get some basic syntax highlighting, brace matching, and indentation, the result is necessarily clumsy, since large parts of the component aren't Perl code.

Michael Abraham Shulman, Michael Abraham> Shulman, a Mason contributor from way back, developed a much nicer solution. His Multiple-Major-Mode Mode (mmm-mode) is a way to combine cperl-mode and html-mode (or sgml-mode, if you prefer), each in the correct region of the component. Of course, like a true hubristic programmer, Michael addressed the larger problem: mmm-mode is actually a framework for allowing several major modes to coexist in a single buffer. Mason syntax definitions are provided, but there are also definitions for embedding JavaScript in HTML documents, embedding HTML code in Perl here-docs, embedding Perl in HTML using Embperl, and more.

Note that since this is a book on Mason and not a book on Emacs and Lisp, we're just going to give you installation and configuration instructions as if they were magical incantations. If you know alternate ways to achieve the same ends, you'll probably be fine using them.

To use mmm-mode's mason-mode, you'll need to download mmm-mode from U<http://mmm-mode.sourceforge.net/> and install the .el files as described in the README file.N<Debian users can find an mmm-mode package in Woody and Sid.> Create a file called .emacs in your home directory if it doesn't already exist, and add the statement (require 'mmm-auto) to it. Then you can manually invoke mason-mode while editing a component by first turning on html-mode (type Meta-x N<If you don't know what the Meta key is, you can probably use your keyboard's Escape key instead. html-mode> and press Return) for the outer region, then turning on mason-mode for the Mason sections (type Meta-x mmm-ify-by-class, press Return, type mason, and press Return). mmm-mode will then scan your component to figure out which sections are which, turning on cperl-mode in the sections that contain Perl code.

If you want mason-mode to start up automatically whenever you edit files with a certain suffix, say .mas, you can add a few lines to your .emacs file after the (require 'mmm-auto) line, as in A<APP-C-EX-1>Example C-1.