[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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. | |
4.10 Noweb literate programming | Noweb literate programs. |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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.
Some people have reported problems using PSGML with Mason. Adding the following line to a `.emacs' file should suffice to turn PSGML off and cause emacs to use a simpler HTML mode:
(autoload 'html-mode "sgml-mode" "HTML Mode" t) |
Earlier versions of PSGML may require instead the following fix:
(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, you may
need to replace html-mode
in the suggested code with
sgml-html-mode
. (Depending on your version of PSGML, this may
not be necessary.) 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] | [ ? ] |
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] | [ ? ] |
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.
("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] | [ ? ] |
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] | [ ? ] |
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] | [ ? ] |
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] | [ ? ] |
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] | [ ? ] |
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] | [ ? ] |
`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.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
`mmm-noweb.el' contains the definition of an MMM Mode submode class for editing Noweb documents. Most Noweb documents use \LaTeX for the documentation chunks. Code chunks in Noweb are document-specific, and the mode may be set with a local variable setting in the document. The variable mmm-noweb-code-mode controls the global code chunk mode. Since Noweb files may have many languages in their code chunks, this mode also allows setting the mode by specifying a mode in the first line or two of a code chunk, using the normal Emacs first-line mode setting syntax. Note that this first-line mode setting only matches a single word for the mode name, and does not support the variable name setting of the generalized first file line syntax.
@verbatim % -*- mode: latex; mmm-noweb-code-mode: c++; -*- % First chunk delimiter! \noweboptions{smallcode}
\title{Sample Noweb File} \author{Joe Kelsey\\ \nwanchorto{mailto:bozo@bozo.bozo}{\tt bozo@bozo.bozo}} \maketitle
\section{Introduction} Normal noweb documentation for the required [[*]] chunk. <<*>>= // C++ mode here! // We might list the program here, or simply included chunks. <<myfile.cc>> %def myfile.cc
\section{[[myfile.cc]]} This is [[myfile.cc]]. MMM noweb-mode understands code quotes in documentation. <<myfile.cc>>= // This section is indented separately from previous.
\section{A Perl Chunk} We need a Perl chunk. <<myfile.pl>>= #!/usr/bin/perl # -*- perl -*- # Each differently named chunk is flowed separately.
\section{Finish [[myfile.cc]]} When we resume a previously defined chunk, they are indented together. <<myfile.cc>>= // Pick up where we left off...
The quoted code chunks inside documentation chunks are given the mode found in the variable mmm-noweb-quote-mode, if set, or the value in mmm-noweb-code-mode otherwise. Also, each quoted chunk is set to have a unique name to prevent them from being indented as a unit.
Suggested setup code:
(mmm-add-mode-ext-class 'latex-mode "\\.nw\\'" 'noweb) (add-to-list 'auto-mode-alist '("\\.nw\\'" . latex-mode)) |
In mmm-noweb buffers, each differently-named code chunk has a
different :name
, allowing all chunks with the same name to get
indented together.
This mode also supplies special paragraph filling operations for use
in documentation areas of the buffer. From a primary-mode
(latex-mode, , emacs
) region, pressing C-c % C-q will mark all
submode regions with word syntax (mmm-word-other-regions
), fill
the current paragraph ((fill-paragraph justify)
), and remove the
syntax markings (mmm-undo-syntax-other-regions
).
Thanks to Joe Kelsey <joe@zircon.seattle.wa.us> for contributing this class.
[ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated by XEmacs shared group account on December, 19 2009
using texi2html 1.65.