[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4. Supplied Submode Classes

This chapter describes the submode classes that are supplied with MMM Mode.

4.1 Mason: Perl in HTML  Mason server-side Perl in HTML.
4.2 Elisp in a Local Variables List  Elisp code in File Variables.
4.3 Here-documents  Code in shell and Perl here-documents.
4.4 Javascript in HTML  Javascript embedded in HTML.
4.5 CSS embedded in HTML  CSS Styles embedded in HTML.
4.6 Embperl: More Perl in HTML  Another syntax for Perl in HTML.
4.7 ePerl: General Perl Embedding  A general Perl-embedding syntax.
4.8 JSP: Java Embedded in HTML  Java code embedded in HTML.
4.9 RPM Spec Files  Shell scripts in RPM Spec Files.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.1 Mason: Perl in HTML

Mason is a syntax to embed Perl code in HTML and other documents. See http://www.masonhq.com for more information. The submode class for Mason components is called `mason' and is loaded on demand from `mmm-mason.el'. The current Mason class is intended to correctly recognize all syntax valid in Mason 0.896. There are insertion keys for most of the available syntax; use mmm-insertion-help (C-c % h by default) with Mason on to get a list.

If you want to have mason submodes automatically in all Mason files, you can use automatic mode and filename associations; the details depend on what you call your Mason components and what major mode you use. See section 2.3.2 Submode Classes Associated with Modes and Extensions. If you use an extension for your Mason files that emacs does not automatically place in your preferred HTML Mode, you will probably want to associate that extension with your HTML Mode as well; section `Choosing Modes' in The Emacs Manual. This also goes for "special" Mason files such as autohandlers and dhandlers.

The Perl mode used is controlled by the user: See section 3.2 Preferred Major Modes. The default is to use CPerl mode, if present. Unfortunately, there are also certain problems with CPerl mode in submode regions. (Not to say that the original perl-mode would do any better--it hasn't been much tried.) First of all, the first line of a Perl section is usually indented as if it were a continuation line. A fix for this is to start with a semicolon on the first line. The insertion key commands do this whenever the Mason syntax allows it.

 
<%perl>;
print $var;
</%perl>

In addition, some users have reported that the CPerl indentation sometimes does not work. This problem has not yet been tracked down, however, and more data about when it happens would be helpful.

Michael Alan Dorman has reported problems using PSGML with Mason. He suggests adding these lines to `.emacs' to turn it off.

 
(delete '("\\.html$" . sgml-html-mode) auto-mode-alist)
(delete '("\\.shtml$" . sgml-html-mode) auto-mode-alist)

Other users report using PSGML with Mason and MMM Mode without difficulty. If you don't have problems and want to use PSGML, simply replace html-mode everywhere in the suggested code with sgml-html-mode or sgml-mode. Similarly, if you are using XEmacs and want to use the alternate HTML mode hm--html-mode, replace html-mode with that symbol.

One problem that crops up when using PSGML with Mason is that even ignoring the special tags and Perl code (which, as I've said, haven't caused me any problems), Mason components often are not a complete SGML document. For instance, my autohandlers often say

 
<body>
  <% $m->call_next %>
</body>

in which case the actual components contain no doctype declaration, <html>, <head>, or <body>, confusing PSGML. One solution I've found is to use the variable sgml-parent-document in such incomplete components; try, for example, these lines at the end of a component.

 
%# Local Variables:
%# sgml-parent-document: ("autohandler" "body" nil ("body"))
%# sgml-doctype: "/top/level/autohandler"
%# End:

This tells PSGML that the current file is a sub-document of the file `autohandler' and is included inside a <body> tag, thus alleviating its confusion.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.2 Elisp in a Local Variables List

Emacs allows the author of a file to specify major and minor modes to be used while editing that file, as well as specifying values for other local Elisp variables, with a File Variables list. See section `File Variables' in The Emacs Manual. Since file variables values are Elisp objects (and with the eval special "variable", they are forms to be evaluated), one might want to edit them in emacs-lisp-mode. The submode class file-variables allows this, and is suitable for turning on in a given file with mmm-classes, or in all files with mmm-global-classes.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.3 Here-documents

One of the long-time standard syntaxes for outputting large amounts of code (or text, or HTML, or whatever) from a script (notably shell scripts and Perl scripts) is the here-document syntax:

 
print <<END_HTML;
<html>
  <head>
    <title>Test Page</title>
  </head>
  <body>
END_HTML

The here-doc submode class recognizes this syntax, and can even guess the correct submode to use in many cases. For instance, it would put the above example in html-mode, noticing the string `HTML' in the name of the here-document. If you use less than evocative here-document names, or if the submode is recognized incorrectly for any other reason, you can tell it explicitly what submode to use.

User Option: mmm-here-doc-mode-alist
The value of this variable should be an alist, each element a cons pair associating a regular expression to a submode symbol. Whenever a here-document name matches one of these regexps, the corresponding submode is applied. For example, if this variable contains the element ("CODE" . cc-mode), then any here-document whose name contains the string `CODE' will be put in cc-mode. The value of this variable overrides any guessing that the here-doc submode class would do otherwise.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.4 Javascript in HTML

The submode class html-js allows for embedding Javascript code in HTML documents. It recognizes both this syntax:

 
<script language="Javascript">
function foo(...) {
   ...
}
</script>

and this syntax:

 
<input type="button" onClick="validate();">

The mode used for Javascript regions is controlled by the user; See section 3.2 Preferred Major Modes.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.5 CSS embedded in HTML

CSS (Cascading Style Sheets) can also be embedded in HTML. The embedded-css submode class recognizes this syntax:

 
<style>
h1 {
   ...
}
</style>

It uses css-mode if present, c++-mode otherwise. This can be customized: See section 3.2 Preferred Major Modes.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.6 Embperl: More Perl in HTML

Embperl is another syntax for embedding Perl in HTML. See http://perl.apache.org/embperl for more information. The embperl submode class recognizes most if not all of the Embperl embedding syntax. Its Perl mode is also controllable by the user; See section 3.2 Preferred Major Modes.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.7 ePerl: General Perl Embedding

Yet another syntax for embedding Perl is called ePerl. See http://www.engelschall.com/sw/eperl/ for more information. The eperl submode class handles this syntax, using the Perl mode specified by the user; See section 3.2 Preferred Major Modes.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.8 JSP: Java Embedded in HTML

JSP (Java Server Pages) is a syntax for embedding Java code in HTML. The submode class jsp handles this syntax, using a Java mode specified by the user; See section 3.2 Preferred Major Modes. The default is jde-mode if present, otherwise java-mode.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.9 RPM Spec Files

`mmm-rpm.el' contains the definition of an MMM Mode submode class for editing shell script sections within RPM (Redhat Package Manager) spec files. It is recommended for use in combination with `rpm-spec-mode.el' by Stig Bjørlykke <stigb@tihlde.hist.no> and Steve Sanbeg <sanbeg@dset.com> (http://www.xemacs.org/~stigb/rpm-spec-mode.el).

Suggested setup code:

 
(add-to-list 'mmm-mode-ext-classes-alist
             '(rpm-spec-mode "\\.spec\\'" rpm-sh))

Thanks to Marcus Harnisch <Marcus.Harnisch@gmx.net> for contributing this submode class.


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by XEmacs Webmaster on October, 2 2007 using texi2html