unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* C-M-a
@ 2008-01-25 21:13 Michael D. Vose
  2008-01-26 13:28 ` C-M-a Alan Mackenzie
  0 siblings, 1 reply; 4+ messages in thread
From: Michael D. Vose @ 2008-01-25 21:13 UTC (permalink / raw)
  To: help-gnu-emacs


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

int main(int argc, char *argv[])
{
  short a,b,bit,i;  short mask = 0x80;

  a = atoi(argv[1]); 
  b = atoi(argv[2]);

  printf("a = %d, b = %d, a|b = %d, a&b = %d\n",a,b,a|b,a&b);

  return 0;
}

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

(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.  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.

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

Thanks.

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

* Re: C-M-a
  2008-01-25 21:13 C-M-a Michael D. Vose
@ 2008-01-26 13:28 ` Alan Mackenzie
  2008-01-28 16:16   ` C-M-a Michael D. Vose
  0 siblings, 1 reply; 4+ messages in thread
From: Alan Mackenzie @ 2008-01-26 13:28 UTC (permalink / raw)
  To: Michael D. Vose; +Cc: help-gnu-emacs

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

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

* Re: C-M-a
  2008-01-26 13:28 ` C-M-a Alan Mackenzie
@ 2008-01-28 16:16   ` Michael D. Vose
  2008-01-28 20:34     ` C-M-a Alan Mackenzie
  0 siblings, 1 reply; 4+ messages in thread
From: Michael D. Vose @ 2008-01-28 16:16 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: help-gnu-emacs


Many thanks!

I added your code -- beginning with (defun mdv-reset-c-cmae ... -- and
now all is right again!

Michael

P.S. When C-M-a puts the cursor at the opening brace, that positions
     the cursor properly for additional useful commands (like C-M-q,
     C-M-f, ...). It is the function's body that is subject to
     modification much more so than the functions name/signature,
     and therefore moving to the beginning of that body is a more
     useful thing for C-M-a to do (IMHO).

>From: Alan Mackenzie <acm@muc.de>
>
>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).

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

* Re: C-M-a
  2008-01-28 16:16   ` C-M-a Michael D. Vose
@ 2008-01-28 20:34     ` Alan Mackenzie
  0 siblings, 0 replies; 4+ messages in thread
From: Alan Mackenzie @ 2008-01-28 20:34 UTC (permalink / raw)
  To: Michael D. Vose; +Cc: help-gnu-emacs

Hi, again!

On Mon, Jan 28, 2008 at 11:16:33AM -0500, Michael D. Vose wrote:

> Many thanks!

> I added your code -- beginning with (defun mdv-reset-c-cmae ... -- and
> now all is right again!

Excellent!

> Michael

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

>      When C-M-a puts the cursor at the opening brace, that positions
>      the cursor properly for additional useful commands (like C-M-q,
>      C-M-f, ...). It is the function's body that is subject to
>      modification much more so than the functions name/signature, and
>      therefore moving to the beginning of that body is a more useful
>      thing for C-M-a to do (IMHO).

Ah.  OK!  The reason I changed the action of C-M-a/e was because of the
annoyance it sometimes causes when you do some other function-releated
things which use beginning/end-of-defun-function, like C-x n d
(`narrow-to-defun') when the "inside-the-braces" narrowing cut off your
parameter list, and in the case of "struct { .... } foo ;", it cut off
the struct's name too.  The change has been popular on balance.  ;-) 

It hadn't occurred to me that there might be positive reasons to want to
move to the braces.

Perhaps I could point out that in place of C-M-q (`c-indent-exp') you
can use C-c C-q (`c-indent-defun') from anywhere inside the function, and
instead of C-M-f, you could use C-M-e (c-end-of-defun) which takes you
_almost_ to the same place.

Still, it's your Emacs, and it's up to you how you set it up.  ;-)  Have
fun with it!

-- 
Alan Mackenzie (Nuremberg, Germany).

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

end of thread, other threads:[~2008-01-28 20:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-25 21:13 C-M-a Michael D. Vose
2008-01-26 13:28 ` C-M-a Alan Mackenzie
2008-01-28 16:16   ` C-M-a Michael D. Vose
2008-01-28 20:34     ` C-M-a 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).