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

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

Re: c and java indentation


From: Alan Mackenzie
Subject: Re: c and java indentation
Date: Tue, 10 Feb 2004 19:43:10 +0000
User-agent: tin/1.4.5-20010409 ("One More Nightmare") (UNIX) (Linux/2.0.35 (i686))

Lowell Kirsh <lkirsh@cs.ubc.ca> wrote on Mon, 09 Feb 2004 17:14:10 -0800:
> I would like that in C and Java modes, pressing enter will go to the
> next line and indent to the right column. How can I do this?

> I have tried putting the following in my .emacs:

> (add-hook 'java-mode-hook
>            (lambda ()
>              (global-set-key [ return ] 'newline-and-indent)))

> which does the right thing, BUT, when I am entering text in the 
> minibuffer, when I press enter, it goes to the next line, rather than 
> executing what's in the minibuffer. Why does it do that?

As Stephan said, you're setting the global binding rather than the local
one.

A better function for doing what you want is `c-context-line-break' (I
think this was new with CC Mode 5.30).  This function also does the Right
Thing inside comments.

The best way of setting this is:

(define-key c-mode-base-map "\C-m" 'c-context-line-break)

at the top level of your .emacs.  [or, if you're not sure whether or not
CC Mode is going to have been loaded, this:

(eval-after-load "cc-mode"
  '(define-key c-mode-base-map "\C-m" 'c-context-line-break))

.]

If you haven't already got CC Mode 5.30, the place to get it is
<http://www.sourceforge.org/release.php>.

Have fun!

> Lowell

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