unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* movement bindings in c-mode
@ 2008-06-23  8:37 Miles Bader
  2008-06-23 14:13 ` Alan Mackenzie
  0 siblings, 1 reply; 12+ messages in thread
From: Miles Bader @ 2008-06-23  8:37 UTC (permalink / raw)
  To: emacs-devel; +Cc: bug-cc-mode

In c-mode, I notice that C-M-a is bound to `c-beginning-of-defun',
overriding the global binding to `beginning-of-defun'.

The generic `beginning-of-defun' function offers some additional
functionality (in particular, it sets the mark before jumping), and
seems to work just as well.  We should generally try to avoid gratuitous
mode-specific rebinding of generic bindings that work properly.

I suppose this rebinding made sense in the past when the generic
mechanism was less capable, but does it make sense any more?

Any comments?

[A similar argument applies to other commands like c-end-of-defun]

Thanks,

-Miles

-- 
`There are more things in heaven and earth, Horatio,
 Than are dreamt of in your philosophy.'




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

* Re: movement bindings in c-mode
  2008-06-23 14:13 ` Alan Mackenzie
@ 2008-06-23 13:57   ` Miles Bader
  2008-06-23 14:09   ` Miles Bader
  1 sibling, 0 replies; 12+ messages in thread
From: Miles Bader @ 2008-06-23 13:57 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: bug-cc-mode, emacs-devel

Alan Mackenzie <acm@muc.de> writes:
> I think beginning-of-defun-function should be passed the repeat count
> (naturally doing the right thing when that function can't take it).  But
> we've had this discussion several times before on this list without
> reaching a consensus.

Were there significant problems, with doing so, or did the discussion
just peter out?

-Miles

-- 
`The suburb is an obsolete and contradictory form of human settlement'




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

* Re: movement bindings in c-mode
  2008-06-23 14:13 ` Alan Mackenzie
  2008-06-23 13:57   ` Miles Bader
@ 2008-06-23 14:09   ` Miles Bader
  2008-06-23 17:05     ` Alan Mackenzie
  1 sibling, 1 reply; 12+ messages in thread
From: Miles Bader @ 2008-06-23 14:09 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: bug-cc-mode, emacs-devel

Alan Mackenzie <acm@muc.de> writes:
> I think beginning-of-defun-function should be passed the repeat count
> (naturally doing the right thing when that function can't take it).

Actually, I just looked at the place where beginning-of-defun-function
is called (in `beginning-of-defun-raw'), and it _does_ pass the repeat
count (with appropriate handling for old-style callees that don't expect
it).

So then this should be simple, right?

-Miles

-- 
Conservative, n. A statesman enamored of existing evils, as opposed to a
Liberal, who wants to replace them with new ones.




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

* Re: movement bindings in c-mode
  2008-06-23  8:37 movement bindings in c-mode Miles Bader
@ 2008-06-23 14:13 ` Alan Mackenzie
  2008-06-23 13:57   ` Miles Bader
  2008-06-23 14:09   ` Miles Bader
  0 siblings, 2 replies; 12+ messages in thread
From: Alan Mackenzie @ 2008-06-23 14:13 UTC (permalink / raw)
  To: Miles Bader; +Cc: bug-cc-mode, emacs-devel

Hi, Miles!

On Mon, Jun 23, 2008 at 05:37:39PM +0900, Miles Bader wrote:
> In c-mode, I notice that C-M-a is bound to `c-beginning-of-defun',
> overriding the global binding to `beginning-of-defun'.

Yes.  This is deliberate.

> The generic `beginning-of-defun' function offers some additional
> functionality (in particular, it sets the mark before jumping), and
> seems to work just as well.

`beginning-of-defun' sets the mark?  This is something new, isn't it?  It
seems like a good idea, though.

> We should generally try to avoid gratuitous mode-specific rebinding of
> generic bindings that work properly.

I don't agree that `beginning-of-defun', in particular
`beginning-of-defun-function' works properly.

> I suppose this rebinding made sense in the past when the generic
> mechanism was less capable, but does it make sense any more?

The problem is that c-beginning-of-defun is S    L    O    W.  It spends
nearly all its time locating the pertinent top-level {, and then
grappling its way to the start of the defun header from there, including
the tortuous analysis of a possible (but usually absent) k&r parameter
block of unbounded length.  This latter is what caused such pain whilst
doing C-x 4 a in C files several weeks ago.  However, when given a repeat
count, it only needs to do this tortuous analysis once., rapidly zapping
back by sexps n-1 times.

b-o-d is currently incapable of passing the repeat count to
b-o-d-function, which means that the tortuous analysis would have to be
repeated n times for an argument of n, were this mechanism to be used by
CC Mode.

I did some timings some while ago (on my now deceased 166 MHz box) on
..../src/keyboard.c.  (c-beginning-of-defun 100) took 4 seconds.  Looping
(c-beginning-of-defun) 100 times took 44 seconds.

> Any comments?

I think beginning-of-defun-function should be passed the repeat count
(naturally doing the right thing when that function can't take it).  But
we've had this discussion several times before on this list without
reaching a consensus.

> [A similar argument applies to other commands like c-end-of-defun]

> Thanks,

> -Miles

-- 
Alan Mackenzie (Nuremberg, Germany).




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

* Re: movement bindings in c-mode
  2008-06-23 14:09   ` Miles Bader
@ 2008-06-23 17:05     ` Alan Mackenzie
  2008-06-23 18:36       ` David Hansen
                         ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Alan Mackenzie @ 2008-06-23 17:05 UTC (permalink / raw)
  To: Miles Bader, Stefan Monnier; +Cc: bug-cc-mode, emacs-devel

Hi, Miles and Stefan,

On Mon, Jun 23, 2008 at 11:09:56PM +0900, Miles Bader wrote:
> Alan Mackenzie <acm@muc.de> writes:
> > I think beginning-of-defun-function should be passed the repeat count
> > (naturally doing the right thing when that function can't take it).

> Actually, I just looked at the place where beginning-of-defun-function
> is called (in `beginning-of-defun-raw'), and it _does_ pass the repeat
> count (with appropriate handling for old-style callees that don't expect
> it).

Well, so it does.  I missed that change.  Thanks, Stefan!

> So then this should be simple, right?

Right.  I'll change it.

Just one small point, though.  The doc-string for
beginning-of-defun-function recommends putting point at the { rather
than the function header.  I think this is unright.  Stefan?

> -Miles

-- 
Alan Mackenzie (Nuremberg, Germany).




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

* Re: movement bindings in c-mode
  2008-06-23 17:05     ` Alan Mackenzie
@ 2008-06-23 18:36       ` David Hansen
  2008-06-23 18:40         ` Lennart Borgman (gmail)
  2008-06-27 21:49         ` Alan Mackenzie
  2008-06-23 18:45       ` Stefan Monnier
                         ` (2 subsequent siblings)
  3 siblings, 2 replies; 12+ messages in thread
From: David Hansen @ 2008-06-23 18:36 UTC (permalink / raw)
  To: emacs-devel

On Mon, 23 Jun 2008 17:05:53 +0000 Alan Mackenzie wrote:

> Just one small point, though.  The doc-string for
> beginning-of-defun-function recommends putting point at the { rather
> than the function header.  I think this is unright.  Stefan?

Actually I would prefer to have it in front of the `{'.  If you just
want to read something around the b-o-d it doesn't matter.

But if you want to edit something it's far more likely that it is within
the body, e.g. adding a variable, than the header.

David





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

* Re: movement bindings in c-mode
  2008-06-23 18:36       ` David Hansen
@ 2008-06-23 18:40         ` Lennart Borgman (gmail)
  2008-06-27 21:50           ` Alan Mackenzie
  2008-06-27 21:49         ` Alan Mackenzie
  1 sibling, 1 reply; 12+ messages in thread
From: Lennart Borgman (gmail) @ 2008-06-23 18:40 UTC (permalink / raw)
  To: emacs-devel

David Hansen wrote:
> On Mon, 23 Jun 2008 17:05:53 +0000 Alan Mackenzie wrote:
> 
>> Just one small point, though.  The doc-string for
>> beginning-of-defun-function recommends putting point at the { rather
>> than the function header.  I think this is unright.  Stefan?
> 
> Actually I would prefer to have it in front of the `{'.  If you just
> want to read something around the b-o-d it doesn't matter.


Does narrow-to-defun use beginning-of-defun-function?




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

* Re: movement bindings in c-mode
  2008-06-23 17:05     ` Alan Mackenzie
  2008-06-23 18:36       ` David Hansen
@ 2008-06-23 18:45       ` Stefan Monnier
  2008-06-24  2:32       ` Miles Bader
  2008-06-27 21:41       ` Alan Mackenzie
  3 siblings, 0 replies; 12+ messages in thread
From: Stefan Monnier @ 2008-06-23 18:45 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: bug-cc-mode, emacs-devel, Miles Bader

>> > I think beginning-of-defun-function should be passed the repeat count
>> > (naturally doing the right thing when that function can't take it).

>> Actually, I just looked at the place where beginning-of-defun-function
>> is called (in `beginning-of-defun-raw'), and it _does_ pass the repeat
>> count (with appropriate handling for old-style callees that don't expect
>> it).

> Well, so it does.  I missed that change.  Thanks, Stefan!

>> So then this should be simple, right?

> Right.  I'll change it.

> Just one small point, though.  The doc-string for
> beginning-of-defun-function recommends putting point at the { rather
> than the function header.  I think this is unright.  Stefan?

It's just a recommendation.  It makes it unnecessary to define
end-of-defun-function.  But in your case you probably don't want to
follow that recommendation, and define an appropriate
end-of-defun-function to find the end of the body.


        Stefan




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

* Re: movement bindings in c-mode
  2008-06-23 17:05     ` Alan Mackenzie
  2008-06-23 18:36       ` David Hansen
  2008-06-23 18:45       ` Stefan Monnier
@ 2008-06-24  2:32       ` Miles Bader
  2008-06-27 21:41       ` Alan Mackenzie
  3 siblings, 0 replies; 12+ messages in thread
From: Miles Bader @ 2008-06-24  2:32 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: bug-cc-mode, Stefan Monnier, emacs-devel

Alan Mackenzie <acm@muc.de> writes:
> Just one small point, though.  The doc-string for
> beginning-of-defun-function recommends putting point at the { rather
> than the function header.  I think this is unright.  Stefan?

I think for consistency with mark-defun it should probably go to the
"true" beginning of the function, not the brace.

[When this was changed a while back (it used to go to the brace), I found
the new behavior fairly disconcerting, but that was mostly because I was
very used to the old behavior.  I can't say that either way is actually
more useful (sort of six-of-one-half-dozen-of-the-other); it might be
useful to have a separate go-to-beginning-of-outermost-function-block
command though...]

-Miles

-- 
Joy, n. An emotion variously excited, but in its highest degree arising from
the contemplation of grief in another.

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php


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

* Re: movement bindings in c-mode
  2008-06-23 17:05     ` Alan Mackenzie
                         ` (2 preceding siblings ...)
  2008-06-24  2:32       ` Miles Bader
@ 2008-06-27 21:41       ` Alan Mackenzie
  3 siblings, 0 replies; 12+ messages in thread
From: Alan Mackenzie @ 2008-06-27 21:41 UTC (permalink / raw)
  To: Miles Bader, Stefan Monnier; +Cc: bug-cc-mode, emacs-devel

Hi, Miles and Stefan,

On Mon, Jun 23, 2008 at 05:05:53PM +0000, Alan Mackenzie wrote:
> Hi, Miles and Stefan,

> On Mon, Jun 23, 2008 at 11:09:56PM +0900, Miles Bader wrote:
> > Alan Mackenzie <acm@muc.de> writes:
> > > I think beginning-of-defun-function should be passed the repeat
> > > count (naturally doing the right thing when that function can't
> > > take it).

> > Actually, I just looked at the place where
> > beginning-of-defun-function is called (in `beginning-of-defun-raw'),
> > and it _does_ pass the repeat count (with appropriate handling for
> > old-style callees that don't expect it).

> Well, so it does.  I missed that change.  Thanks, Stefan!

> > So then this should be simple, right?

> Right.  I'll change it.

Done.

-- 
Alan Mackenzie (Nuremberg, Germany).




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

* Re: movement bindings in c-mode
  2008-06-23 18:36       ` David Hansen
  2008-06-23 18:40         ` Lennart Borgman (gmail)
@ 2008-06-27 21:49         ` Alan Mackenzie
  1 sibling, 0 replies; 12+ messages in thread
From: Alan Mackenzie @ 2008-06-27 21:49 UTC (permalink / raw)
  To: emacs-devel

Hi, David!

On Mon, Jun 23, 2008 at 08:36:14PM +0200, David Hansen wrote:
> On Mon, 23 Jun 2008 17:05:53 +0000 Alan Mackenzie wrote:

> > Just one small point, though.  The doc-string for
> > beginning-of-defun-function recommends putting point at the { rather
> > than the function header.  I think this is unright.  Stefan?

> Actually I would prefer to have it in front of the `{'.  If you just
> want to read something around the b-o-d it doesn't matter.

It matters, I think, when you do C-x n d.  Then you can see what
function you're within.

> But if you want to edit something it's far more likely that it is within
> the body, e.g. adding a variable, than the header.

I'd conjecture that any line within a defun is as likely to be edited as
any other.  That you've got an extra 3 or 4 lines to move forward to
that point doesn't seem that critical.

But I think the critical reason is that the command is called
beginning-of-defun, not beginning-of-defun-block, and commands should do
what they say.  It would be possible to modify b-o-d so that a bare
prefix (C-u) would go to the block rather than the header.  But I don't
think it would be worth the extra complication.

> David

-- 
Alan Mackenzie (Nuremberg, Germany).




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

* Re: movement bindings in c-mode
  2008-06-23 18:40         ` Lennart Borgman (gmail)
@ 2008-06-27 21:50           ` Alan Mackenzie
  0 siblings, 0 replies; 12+ messages in thread
From: Alan Mackenzie @ 2008-06-27 21:50 UTC (permalink / raw)
  To: Lennart Borgman (gmail); +Cc: emacs-devel

On Mon, Jun 23, 2008 at 08:40:34PM +0200, Lennart Borgman (gmail) wrote:
> David Hansen wrote:
> >On Mon, 23 Jun 2008 17:05:53 +0000 Alan Mackenzie wrote:

> >>Just one small point, though.  The doc-string for
> >>beginning-of-defun-function recommends putting point at the { rather
> >>than the function header.  I think this is unright.  Stefan?

> >Actually I would prefer to have it in front of the `{'.  If you just
> >want to read something around the b-o-d it doesn't matter.

> Does narrow-to-defun use beginning-of-defun-function?

Yes.  Try C-x n d in a CC Mode mode file.

-- 
Alan Mackenzie (Nuremberg, Germany).




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

end of thread, other threads:[~2008-06-27 21:50 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-23  8:37 movement bindings in c-mode Miles Bader
2008-06-23 14:13 ` Alan Mackenzie
2008-06-23 13:57   ` Miles Bader
2008-06-23 14:09   ` Miles Bader
2008-06-23 17:05     ` Alan Mackenzie
2008-06-23 18:36       ` David Hansen
2008-06-23 18:40         ` Lennart Borgman (gmail)
2008-06-27 21:50           ` Alan Mackenzie
2008-06-27 21:49         ` Alan Mackenzie
2008-06-23 18:45       ` Stefan Monnier
2008-06-24  2:32       ` Miles Bader
2008-06-27 21:41       ` Alan Mackenzie

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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