emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Indentation problem in corporating major modes


From: Herbert Euler
Subject: Indentation problem in corporating major modes
Date: Mon, 28 Nov 2005 12:39:31 +0800

Hello everyone,

Please take a look at this to see how to solve the
indentation problem.

There are several major modes in the standard
Emacs, each of them consists of several
customizations e.g. indentation, syntax
highlighting etc.  Major modes are exclusive to
each other, so only one major mode can be active
at one time.  Indentation in one major mode works
fine in this way.

Multiple Major Mode, which is also called
mmm-mode, is a minor mode that can glue several
major modes together.  In mmm-mode, there is one
primary major mode, plus several submodes.  While
the point is in a submode region, Emacs behaves
like in the major mode of that submode.  This is
pretty useful when editing files contain content
should be identified as different kinds of text,
such as CGI scripts, since this approach make
existing work on different progmodes work
together, instead of creating new major modes.

Take the PHP file as example.  Typically, a PHP
file contains content like this:

  <html>
    <body>
      <h1><?php
        if (something) {
             action;
        } else {
             action;
        }
      ?></h1>
    </body>
  </html>

Content between "<?php" and "?>" is PHP program,
the other is HTML tags.  The advantage of mmm-mode
is that one can combine these two major modes
without creating a new major mode trying to deal
with file contains both HTML tags and PHP code.
And more major modes could be involved in with
little effort than creating new ones.

But the indentation is not fine in now. The PHP code
is better indented beyond "<h1>" in the above example
than indented to column 0.  But in the current
mmm-mode, PHP code will be indented from column 0.
So the code in the above example will be indented like
this:

  <html>
    <body>
      <h1><?php
  if (something) {
       action;
  } else {
       action;
  }
      ?></h1>
    </body>
  </html>

This is more difficult to read than the former
one.  Tracing the indentation code, I found it
might be because all progmodes use the function
'indent-to' to indent, and that command count from
column 0.  This is fine in a single major mode, but
is a bit worse when several major modes corporate
with each other in mmm-mode.

I found lots of progmodes count by using
'beginning-of-line', so I asked a question in
help-gnu-emacs about stopping 'beginning-of-line'
beyond column 0, and was told to solve this
problem with field property.  'Beginning-of-line'
indeed stops at the field boundary, but
indentation is not affected in my test of setting
field property for some text in a program. So
perhaps 'indent-to' should be modified?

Because modifying all progmodes is really so
difficult, I think it is easier and better to
modify the 'indent-to' command, so that it
supports indent from columns other than column
0.  I'm not sure whether it's a good approach, so I
post this message.

Please give me some suggestions, thanks very much.

Regards,
Guanpeng Xu

_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar - get it now! http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/





reply via email to

[Prev in Thread] Current Thread [Next in Thread]