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

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

Re: emacs: indent automatically on c, c++, php comments


From: Alan Mackenzie
Subject: Re: emacs: indent automatically on c, c++, php comments
Date: Sat, 6 Sep 2003 10:37:40 +0000
User-agent: tin/1.4.5-20010409 ("One More Nightmare") (UNIX) (Linux/2.0.35 (i686))

Alex Braumann <ab@msedv.at> wrote on Sat, 06 Sep 2003 09:30:47 GMT:
> Hi,

> I am not familiar with all the functions provided by this wonderful
> editor, also the configuration is not a task for 5 minutes :).

> I have a simple need:
>  If I type a '//' in my emacs, the cursor should jump to column number 30.

You're using C++ Mode, right?

> Is this practicable via the .emacs file in my home dir?

In essence, yes.  Instead of typing '//', use M-;  (that is, press the
semicolon key whilst holding the Meta key (probably the <alt> or <window>
key).  This will then insert the '//' at comment-column, which is by
default 32.  (if there's room on the line, that is.  If you've already
got a long statement on the line, M-; does the Right Thing).  You can
also use M-; to tidy up existing comments which have got ragged.

If you really, truly, absolutely want your comments at column 30 and not
32, change the value of comment-column in your C++ Mode hook.  If your
reaction to that is "My WHAT??", then the C++ Mode hook is that bit of
code, written by you, which gets executed each time a C++ buffer is
loaded.  Put the following into your .emacs:

(defun my-c++-mode-hook ()
  (setq comment-column 30))
(add-hook 'c++-mode-hook 'my-c++-mode-hook)

Hook functions (like my-c++-mode-hook) typically contain personal
settings for indentation style, tab width, and so on.  You can read all
about this in the CC Mode manual:  C-h i, select CC Mode, then select the
page "Sample .emacs File".

> thanks! :)

> tc,
> alex.

-- 
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]