[Top][All Lists]

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

Re: C-M-a

From: Alan Mackenzie
Subject: Re: C-M-a
Date: Sat, 26 Jan 2008 13:28:40 +0000
User-agent: Mutt/1.5.9i

Hi, Michael!

On Fri, Jan 25, 2008 at 04:13:58PM -0500, Michael D. Vose wrote:

> Before upgrading to GNU Emacs 22.1.1 (sorry I don't know what my old
> version was), C-M-a would behave in c-mode like it did and currently
> does in fundamental mode... specifically: if the cursor was below the
> closing brace of the body of main (see code below), then C-M-a would
> move the position of the cursor to the opening brace of the body of
> main

[ .... ]

> However now (in c-mode using GNU Emacs 22.1.1) C-M-a positions the
> cursor at the beginning of "int main(int argc, char *argv[])".  I have
> tried to change this new behavior back to the old behavior described
> above -- I WANT THE CURSOR AT THE OPENING BRACE just where C-M-a puts
> it in fundamental mode -- by putting the following into my .emacs file

Well, the thinking is that C-M-a should go back to "the beginning of a
top level thingy.", and that in C Mode, that's the function (or struct,
or whatever) header, not the opening brace.

> (add-hook 'c-mode-hook
>                '(lambda ()
>                   (defvar beginning-of-defun-function nil)
>                   (defvar defun-prompt-regexp         nil)
>                   (local-set-key  [?\M-\C-a] 'beginning-of-defun)))

> Unfortunately, that does not work.

I can't see why it doesn't work, either.

> What motivated the above attempt at restoring desired behavior was the
> fact when in fundamental mode M-x find-function-on-key reports that
> C-M-a invokes beginning-of-defun.

find-function-on-key is a cool function!  Thanks for telling me about it.

> What can I do to make C-M-a behave in c-mode like it does in
> fundamental mode?

For "safety"'s sake, you're probably advised to do the same to C-M-e.
Put this in your .emacs (before CC Mode gets loaded):

(defun mdv-reset-c-cmae ()
  "Restore C-M-a/e, etc., to fundamental mode defaults."
  (define-key c-mode-base-map "\C-\M-a" nil)
  (define-key c-mode-base-map "\C-\M-e" nil))
(add-hook 'c-initialization-hook 'mdv-reset-c-cmae)
(defun mdv-clear-c-beodf ()
  "Clear buffer local values of c-beginning/end-of-defun-function."
  (setq beginning-of-defun-function nil
        end-of-defun-function nil))
(add-hook 'c-mode-common-hook 'mdv-clear-c-beodf)

As a matter of interest, why do you want C-M-a to put the cursor at the
opening brace rather than the function header?  

Alan Mackenzie (Nuremberg, Germany).

reply via email to

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