emacs-devel
[Top][All Lists]
Advanced

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

Re: Why isn't C-m listed here?


From: Eric Lilja
Subject: Re: Why isn't C-m listed here?
Date: Mon, 16 Apr 2007 21:38:12 +0200
User-agent: Thunderbird 1.5.0.10 (Windows/20070221)

Alan Mackenzie wrote:
'Evening, Eric!

On Mon, Apr 16, 2007 at 04:43:17PM +0200, Eric Lilja wrote:
Miles Bader wrote:
Eric Lilja [snip quoted raw email address] writes:
As the topic says: Why isn't C-m listed here:

and if it was, what would its description be? Alias for <RET>?

It's not an alias for RET, it _is_ RET.

RET == C-m

Ok, thanks for the quick reply. So, C-m is RET which means newline. C-j is newline-and-indent (C-m + <TAB>) so if I wanted a newline-and-indent when I press <RET> in cc mode I could do:
(global-set-key "\C-m" "\C-j")
in my c mode common hook? Proper way to do it?

You could do this, but better might be this:

(defun my-c-initialization-hook ()
  (define-key c-mode-base-map "\C-m" 'c-context-line-break))
(add-hook 'c-initialization-hook 'my-c-initialization-hook)

, as suggested by the (current) CC Mode manual (page "Sample .emacs
File").
This gives you proper continuation of comments and macros as well as
indentation of ordinary statements.  Note also that you don't need to use
c-mode-common-hook here - it wouldn't do any harm, but you only need to
bind the key once, not every time you open a fresh CC Mode buffer.


Thanks for your reply, Alan! Actually, this is my c-mode-common-hook right now (edited today but before I saw this reply):

(defun my-c-mode-common-hook ()
  ;; my customizations for all of c-mode and related modes
  (message "Running my-c-mode-common-hook")
  (setq c-basic-offset 3)
  ; Use spaces, not tabs, for indentation.
  (setq-default indent-tabs-mode nil)
  ; Replace C-m (C-m == <RET> == newline) with C-j (newline-and-indent).
  (define-key c-mode-base-map "\C-m" 'newline-and-indent)
  ; Maybe on by default on windows and off by default on solaris?
  (delete-selection-mode 1)
  ; Since this is run for php-mode we want to be able to toggle to html
  ; mode while editing a .php-file with both php and html blocks.
  ; html-mode contains a key binding to toggle to php mode.
  (define-key c-mode-base-map "\C-c\C-h" 'html-mode)
  )
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)

I will try c-context-line-break and also think about which of these I can move into the initialization hook.

- Eric





reply via email to

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