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

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

Re: Indenting problem


From: Alan Mackenzie
Subject: Re: Indenting problem
Date: Thu, 24 Apr 2003 08:07:18 +0000
User-agent: tin/1.4.5-20010409 ("One More Nightmare") (UNIX) (Linux/2.0.35 (i686))

M Wasilewski <mmw@srv.ualberta.ca> wrote on 23 Apr 2003 22:30:58 GMT:
> I seem to be having a problem with emacs indenting. Under solaris and 
> linux my indenting looks like so:

> Vector3 cross( const Vector3 &v ) const
> {
>  return Vector3( y * v.z - z * v.y,
>                  z * v.x - x * v.z,        <==============
>                  x * v.y - y * v.x );
> }

> No problems. But running emacs under Windows XP with the same .emacs file 
> gives me this:

> Vector3 cross( const Vector3 &v ) const
> {
>  return Vector3( y * v.z - z * v.y,
>                z * v.x - x * v.z,          <==============
>                x * v.y - y * v.x );
> }

> The z and the x are lined up with the bracket rather than the y. Does 
> anyone know why this is? Or more importantly how to fix it?
> Thanks.

You don't explicitly say so, so I'm assuming you're programming in C, or
some other language handled by cc-mode.

You need to use an "indentation function", in particular
c-lineup-arglist, rather than just straightforward indentation.

To understand this, put the cursor on the line I've marked "<====".  Type
C-c C-s.  This will tell you something like "((arglist-cont-nonempty 1268
1282))", cc-mode's syntactic analysis of the line.  (The numbers are
buffer positions of important reference points.)

To try out the new function, type C-c C-o on this line and accept the
suggested default, "arglist-cont-nonempty", with <CR>.  In place of the
suggested default, type "c-lineup-arglist"<CR>.  Now use the <tab> key in
your buffer to check that the two continuation lines do indeed indent
properly.

You'll want to put this into your .emacs to make it permanent.  You can
either attach this to "c-mode-common-hook" (when it will apply to all
cc-mode languages), or to "c-mode-hook" (if you just want it to be for
C).  The entry will look something like this:

(defun my-c-mode-common-hook ()
  (c-set-offset 'arglist-cont-nonempty 'c-lineup-arglist)
;; other customization here.
)
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)

This is all described in the CC-Mode info pages under "Customizing
indentaion".

All the best!

> Mike Wasilewski

-- 
Alan Mackenzie (Munich, Germany)
Email: aacm@muuc.dee; to decode, wherever there is a repeated letter
(like "aa"), remove half of them (leaving, say, "a").



reply via email to

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