unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Minor bug in c-beginning-of-defun.  May I fix it?
@ 2007-04-17 18:21 Alan Mackenzie
  2007-04-17 19:07 ` Chong Yidong
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Mackenzie @ 2007-04-17 18:21 UTC (permalink / raw)
  To: Chong Yidong, emacs-devel

Hi, Chong and Emacs!

Open (for example) ..../src/cmds.c and move point to within the braces
of the last function, `keys_of_cmds'.  Do M-- C-M-a.

Since there is no next defun, point should be left at EOB.  It is,
sadly, erroneously left after the last closing brace.

The fix is straightforward: The third argument NOERROR to a
`c-syntactic-re-search-forward' should not be t; it should be something
else non-nil.  So, when a search fails, point will be left at EOB rather
than unmoved.  The argument `NOERROR' here has the same meaning it does
in the Emacs core function `search-forward-regexp'.

I believe this patch is safe and trouble free.  Please tell me to commit
it!



2007-04-17  Alan Mackenzie  <acm@muc.de>

	* progmodes/cc-cmds.el (c-beginning-of-defun): With -ve arg and
	point too close to EOB, leave point at EOB rather than last `}'.


Index: cc-cmds.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/progmodes/cc-cmds.el,v
retrieving revision 1.58
diff -c -r1.58 cc-cmds.el
*** cc-cmds.el	9 Apr 2007 10:51:29 -0000	1.58
--- cc-cmds.el	17 Apr 2007 18:04:26 -0000
***************
*** 1531,1537 ****
  	      (setq arg (c-forward-to-nth-EOF-} (- arg) where)))
  	  ;; Move forward to the next opening brace....
  	  (when (and (= arg 0)
! 		     (c-syntactic-re-search-forward "{" nil t))
  	    (backward-char)
  	    ;; ... and backward to the function header.
  	    (c-beginning-of-decl-1)
--- 1531,1537 ----
  	      (setq arg (c-forward-to-nth-EOF-} (- arg) where)))
  	  ;; Move forward to the next opening brace....
  	  (when (and (= arg 0)
! 		     (c-syntactic-re-search-forward "{" nil 'eob))
  	    (backward-char)
  	    ;; ... and backward to the function header.
  	    (c-beginning-of-decl-1)


-- 
Alan Mackenzie (Ittersbach, Germany).

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

* Re: Minor bug in c-beginning-of-defun.  May I fix it?
  2007-04-17 18:21 Minor bug in c-beginning-of-defun. May I fix it? Alan Mackenzie
@ 2007-04-17 19:07 ` Chong Yidong
  2007-04-17 19:47   ` Alan Mackenzie
  0 siblings, 1 reply; 5+ messages in thread
From: Chong Yidong @ 2007-04-17 19:07 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: emacs-devel

Alan Mackenzie <acm@muc.de> writes:

> The fix is straightforward: The third argument NOERROR to a
> `c-syntactic-re-search-forward' should not be t; it should be something
> else non-nil.  So, when a search fails, point will be left at EOB rather
> than unmoved.  The argument `NOERROR' here has the same meaning it does
> in the Emacs core function `search-forward-regexp'.
>
> ! 		     (c-syntactic-re-search-forward "{" nil t))
> --- 1531,1537 ----
> ! 		     (c-syntactic-re-search-forward "{" nil 'eob))

Hi Alan,

I played around with your patch a little, and noticed that it
introduces a slight difference in the behavior of
c-beginning-of-defun.  Consider the following file (not including the
"----" characters, and including the final "\n\n"):

-------------------
int foo ()
{
  asdf;
  
  if (asdf)
    {
      bar;
    }
}

-------------------

With point at bob, do C-u -1 M-x c-beginning-of-defun RET.

Before the change, point moves to the newline just after the last }
character, and on the same line.  After the change, it moves one
additional line down.

I guess this is harmless, but could you double-check?  (Otherwise, the
change looks OK to me, assuming you've tested it out thoroughly.)

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

* Re: Minor bug in c-beginning-of-defun.  May I fix it?
  2007-04-17 19:07 ` Chong Yidong
@ 2007-04-17 19:47   ` Alan Mackenzie
  2007-04-17 20:04     ` Chong Yidong
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Mackenzie @ 2007-04-17 19:47 UTC (permalink / raw)
  To: Chong Yidong; +Cc: emacs-devel

Hi, Chong!

On Tue, Apr 17, 2007 at 03:07:36PM -0400, Chong Yidong wrote:
> Alan Mackenzie <acm@muc.de> writes:

> > ! 		     (c-syntactic-re-search-forward "{" nil t))
> > --- 1531,1537 ----
> > ! 		     (c-syntactic-re-search-forward "{" nil 'eob))

> Hi Alan,

> I played around with your patch a little, and noticed that it
> introduces a slight difference in the behavior of
> c-beginning-of-defun.  Consider the following file (not including the
> "----" characters, and including the final "\n\n"):

> -------------------
> int foo ()
> {
>   asdf;

>   if (asdf)
>     {
>       bar;
>     }
> }

> -------------------

> With point at bob, do C-u -1 M-x c-beginning-of-defun RET.

> Before the change, point moves to the newline just after the last }
> character, and on the same line.

This was the bug.  Just after the } is NOT a beginning-of-defun.

> After the change, it moves one additional line down.

> I guess this is harmless, but could you double-check?  

The new behaviour is correct: c-beginning-of-defun should emulate the
standard b-o-d; the only places point should end up at are a BOD or
[BE]OB.

> (Otherwise, the change looks OK to me, assuming you've tested it out
> thoroughly.)

I've tested it thoroughly.

-- 
Alan.

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

* Re: Minor bug in c-beginning-of-defun.  May I fix it?
  2007-04-17 19:47   ` Alan Mackenzie
@ 2007-04-17 20:04     ` Chong Yidong
  2007-04-17 20:50       ` Alan Mackenzie
  0 siblings, 1 reply; 5+ messages in thread
From: Chong Yidong @ 2007-04-17 20:04 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: emacs-devel

Alan Mackenzie <acm@muc.de> writes:

>> Before the change, point moves to the newline just after the last }
>> character, and on the same line.
>
> This was the bug.  Just after the } is NOT a beginning-of-defun.

Ah, OK then.

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

* Re: Minor bug in c-beginning-of-defun.  May I fix it?
  2007-04-17 20:04     ` Chong Yidong
@ 2007-04-17 20:50       ` Alan Mackenzie
  0 siblings, 0 replies; 5+ messages in thread
From: Alan Mackenzie @ 2007-04-17 20:50 UTC (permalink / raw)
  To: Chong Yidong; +Cc: emacs-devel

Hi, Chong!

On Tue, Apr 17, 2007 at 04:04:25PM -0400, Chong Yidong wrote:
> Alan Mackenzie <acm@muc.de> writes:
> 
> >> Before the change, point moves to the newline just after the last }
> >> character, and on the same line.
> >
> > This was the bug.  Just after the } is NOT a beginning-of-defun.
> 
> Ah, OK then.

I've committed it.

-- 
Alan.

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

end of thread, other threads:[~2007-04-17 20:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-17 18:21 Minor bug in c-beginning-of-defun. May I fix it? Alan Mackenzie
2007-04-17 19:07 ` Chong Yidong
2007-04-17 19:47   ` Alan Mackenzie
2007-04-17 20:04     ` Chong Yidong
2007-04-17 20:50       ` 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).