unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* c and java indentation
@ 2004-02-10  1:14 Lowell Kirsh
  2004-02-10  1:20 ` Stefan Monnier
  2004-02-10 19:43 ` Alan Mackenzie
  0 siblings, 2 replies; 4+ messages in thread
From: Lowell Kirsh @ 2004-02-10  1:14 UTC (permalink / raw)


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?

Lowell

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: c and java indentation
  2004-02-10  1:14 c and java indentation Lowell Kirsh
@ 2004-02-10  1:20 ` Stefan Monnier
  2004-02-10  1:30   ` Lowell Kirsh
  2004-02-10 19:43 ` Alan Mackenzie
  1 sibling, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2004-02-10  1:20 UTC (permalink / raw)


>              (global-set-key [ return ] 'newline-and-indent)))

              (local-set-key [(control ?m)] 'newline-and-indent)

or for something a bit more obvious

              (local-set-key (kbd "RET") 'newline-and-indent)

Why use `global-set-key' if you only want it in java-mode?
Or alternatively, why put it in java-mode-hook if you want it everywhere.


        Stefan

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: c and java indentation
  2004-02-10  1:20 ` Stefan Monnier
@ 2004-02-10  1:30   ` Lowell Kirsh
  0 siblings, 0 replies; 4+ messages in thread
From: Lowell Kirsh @ 2004-02-10  1:30 UTC (permalink / raw)


d'oh, I meant 'local'. Thanks.

lowell

Stefan Monnier wrote:
>>             (global-set-key [ return ] 'newline-and-indent)))
> 
> 
>               (local-set-key [(control ?m)] 'newline-and-indent)
> 
> or for something a bit more obvious
> 
>               (local-set-key (kbd "RET") 'newline-and-indent)
> 
> Why use `global-set-key' if you only want it in java-mode?
> Or alternatively, why put it in java-mode-hook if you want it everywhere.
> 
> 
>         Stefan

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: c and java indentation
  2004-02-10  1:14 c and java indentation Lowell Kirsh
  2004-02-10  1:20 ` Stefan Monnier
@ 2004-02-10 19:43 ` Alan Mackenzie
  1 sibling, 0 replies; 4+ messages in thread
From: Alan Mackenzie @ 2004-02-10 19:43 UTC (permalink / raw)


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").

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-02-10 19:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-02-10  1:14 c and java indentation Lowell Kirsh
2004-02-10  1:20 ` Stefan Monnier
2004-02-10  1:30   ` Lowell Kirsh
2004-02-10 19:43 ` Alan Mackenzie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).