help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Is it possible to set a "goal column" for 'beginning-of-line'?


From: Herbert Euler
Subject: Re: Is it possible to set a "goal column" for 'beginning-of-line'?
Date: Wed, 23 Nov 2005 16:51:12 +0800

From: Stefan Monnier <monnier@iro.umontreal.ca>
To: help-gnu-emacs@gnu.org
Subject: Re: Is it possible to set a "goal column" for 'beginning-of-line'?
Date: Wed, 23 Nov 2005 02:25:14 -0500

I have trouble understanding your description, but it seems the best
approach is to hack the indentation code directly.

I'll try to explain it more clearly as follows.

Typically a php file contains content like this:

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

 </body>
</html>

There are lots of elements in such files,
e.g. HTML tags, PHP codes, and many other
things (they are not shown here). We can
provide a major mode to handle this well,
but it means lots of existing work on each
major mode could not help. Fortunately,
mmm minor mode can glue several major modes
together. With mmm minor mode, Emacs behaves
like in HTML mode when point is between
<html> and <h1> or between </h1> and </html>
in the above example, and behaves like in
PHP mode when point is between <?php and ?>.
If there are more elements in this file e.g.
C code, Emacs can behave like in C mode as
well. So it can be very useful of mmm mode.

As you see, code between '<?php' and '?>'
should be idented more than <h1>. But if
you really put point before 'if (something)'
and press <TAB>, it will be idented to
column 0. That's why I said it's poor. This
is because ident commands first go to
column 0 with 'beginning-of-line' and then
count columns starting from there.

To solve this, we must modify mmm-mode itself,
since it's the responsibility of mmm-mode
to provide information of which column one line
should be idented to. But either progmodes
or Emacs itself must be modified as well if
there is no vertical narrowing, because as far
as I know all progmodes use 'beginning-of-line'
to address the first location of a line.
Options:

1. Modify all progmodes, so that each of them
uses another function instead of 'beginning-
of-line' to go to the beginning of a line,
and then count columns. This function would
read a variable specifies which column is
the beginning of a line (but actually that's
not necessary since the same information
of which column is the starting column would
be shared by several lines in practice).

2. Modify 'beginning-of-line' so that it reads
the variable in option 1.

Both could be difficult tasks, but option 1
seems to be more diffcult than option 2. But
before doing that, I'd like to ask whether
Emacs has provided such a feature so that
only mmm-mode itself is needed to be modified.

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]