unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Another small problem of CC Mode
@ 2007-01-12  1:58 Herbert Euler
  2007-01-12  2:05 ` Herbert Euler
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Herbert Euler @ 2007-01-12  1:58 UTC (permalink / raw)


Hi,

In a file that contains C program like this:

    extern void g(void);
    extern void h(void);

    int
    f(void)
    {
            do {
    #ifdef M1
            } while (g());
    #else
            } while (h());
    #endif /* M1 */
    }

Many functions in CC mode will behave incorrectly:
`c-beginning-of-defun' and `c-end-of-defun' cannot go to the right
place; `c-indent-command' cannot indent to the right column;
`c-electric-brace' tells an error, which is not, when typing the `}'
that finishes the function `f'; and so on.

Of course, this is rare.  But will making CC Mode detect this
situation and behave in a right way need much effort?

Thanks in advance.

Regards,
Guanpeng Xu

_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar - get it now! 
http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/

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

* RE: Another small problem of CC Mode
  2007-01-12  1:58 Another small problem of CC Mode Herbert Euler
@ 2007-01-12  2:05 ` Herbert Euler
  2007-01-12  3:13 ` Alfred M. Szmidt
  2007-01-12  9:03 ` Alan Mackenzie
  2 siblings, 0 replies; 6+ messages in thread
From: Herbert Euler @ 2007-01-12  2:05 UTC (permalink / raw)


This also shows the advantage of GNU style ;-)

Regards,
Guanpeng Xu


>From: "Herbert Euler" <herberteuler@hotmail.com>
>To: emacs-devel@gnu.org
>Subject: Another small problem of CC Mode
>Date: Fri, 12 Jan 2007 09:58:31 +0800
>
>Hi,
>
>In a file that contains C program like this:
>
>    extern void g(void);
>    extern void h(void);
>
>    int
>    f(void)
>    {
>            do {
>    #ifdef M1
>            } while (g());
>    #else
>            } while (h());
>    #endif /* M1 */
>    }
>
>Many functions in CC mode will behave incorrectly:
>`c-beginning-of-defun' and `c-end-of-defun' cannot go to the right
>place; `c-indent-command' cannot indent to the right column;
>`c-electric-brace' tells an error, which is not, when typing the `}'
>that finishes the function `f'; and so on.
>
>Of course, this is rare.  But will making CC Mode detect this
>situation and behave in a right way need much effort?
>
>Thanks in advance.
>
>Regards,
>Guanpeng Xu
>
>_________________________________________________________________
>FREE pop-up blocking with the new MSN Toolbar - get it now! 
>http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/
>
>
>
>_______________________________________________
>Emacs-devel mailing list
>Emacs-devel@gnu.org
>http://lists.gnu.org/mailman/listinfo/emacs-devel

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

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

* Re: Another small problem of CC Mode
  2007-01-12  1:58 Another small problem of CC Mode Herbert Euler
  2007-01-12  2:05 ` Herbert Euler
@ 2007-01-12  3:13 ` Alfred M. Szmidt
  2007-01-12  9:03 ` Alan Mackenzie
  2 siblings, 0 replies; 6+ messages in thread
From: Alfred M. Szmidt @ 2007-01-12  3:13 UTC (permalink / raw)
  Cc: emacs-devel

   Of course, this is rare.  But will making CC Mode detect this
   situation and behave in a right way need much effort?

Not exactly the answer you are looking for, but reorganising your code
in the following manner would make CC mode behave properly.

#ifdef M1
extern void g(void);
# define M g
#else 
extern void h(void);
# define M h
#endif

int
f(void)
{
  do {
  } while (M());
}

Happy hacking.

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

* Re: Another small problem of CC Mode
  2007-01-12  1:58 Another small problem of CC Mode Herbert Euler
  2007-01-12  2:05 ` Herbert Euler
  2007-01-12  3:13 ` Alfred M. Szmidt
@ 2007-01-12  9:03 ` Alan Mackenzie
  2007-01-12 10:06   ` Herbert Euler
  2 siblings, 1 reply; 6+ messages in thread
From: Alan Mackenzie @ 2007-01-12  9:03 UTC (permalink / raw)
  Cc: emacs-devel

Hi, Guanpeng!

On Fri, Jan 12, 2007 at 09:58:31AM +0800, Herbert Euler wrote:
> Hi,
> 
> In a file that contains C program like this:
> 
>    extern void g(void);
>    extern void h(void);
> 
>    int
>    f(void)
>    {
>            do {
>    #ifdef M1
>            } while (g());
>    #else
>            } while (h());
>    #endif /* M1 */
>    }

> Many functions in CC mode will behave incorrectly:
> `c-beginning-of-defun' and `c-end-of-defun' cannot go to the right
> place; `c-indent-command' cannot indent to the right column;
> `c-electric-brace' tells an error, which is not, when typing the `}'
> that finishes the function `f'; and so on.

Yes.  C is a ghastly language.  ;-)

> Of course, this is rare.  But will making CC Mode detect this
> situation and behave in a right way need much effort?

It's difficult to make Emacs's syntax stuff only see one of the "}"s.
Not impossible, just difficult.  I've been thinking about it, off and on,
for about two years now.  Fixing it would probably take more effort than
it's worth - but a mention in the "Limitation and Known Bugs" section of
the manual might be sensible.

> Thanks in advance.
 
> Regards,
> Guanpeng Xu

-- 
Alan Mackenzie (Ittersbach, Germany)

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

* Re: Another small problem of CC Mode
  2007-01-12  9:03 ` Alan Mackenzie
@ 2007-01-12 10:06   ` Herbert Euler
  2007-01-13  2:12     ` Miles Bader
  0 siblings, 1 reply; 6+ messages in thread
From: Herbert Euler @ 2007-01-12 10:06 UTC (permalink / raw)
  Cc: ams, emacs-devel

> > Of course, this is rare.  But will making CC Mode detect this
> > situation and behave in a right way need much effort?
>
>It's difficult to make Emacs's syntax stuff only see one of the "}"s.
>Not impossible, just difficult.  I've been thinking about it, off and on,
>for about two years now.  Fixing it would probably take more effort than
>it's worth - but a mention in the "Limitation and Known Bugs" section of
>the manual might be sensible.

Sure.  And I think Alfred's solution is a true alternative
to avoid these problems.  If there are something in
the "Limitation and Known Bugs", I think his solution
should be there too.

Thanks.

Regards,
Guanpeng Xu

_________________________________________________________________
Don't just search. Find. Check out the new MSN Search! 
http://search.msn.com/

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

* Re: Another small problem of CC Mode
  2007-01-12 10:06   ` Herbert Euler
@ 2007-01-13  2:12     ` Miles Bader
  0 siblings, 0 replies; 6+ messages in thread
From: Miles Bader @ 2007-01-13  2:12 UTC (permalink / raw)
  Cc: acm, ams, emacs-devel

"Herbert Euler" <herberteuler@hotmail.com> writes:
> Sure.  And I think Alfred's solution is a true alternative
> to avoid these problems.  If there are something in
> the "Limitation and Known Bugs", I think his solution
> should be there too.

Yeah I think Alfred's solution is best in this case.

I also very often see code like:

   do {
      ...
   } while (
   #ifdef asdf
            a()
   #else
            b()
   #endif
          );

This is definitely ugly (so Alfred's method is probably better), but
it's "localized ugliness", and #ifdefs tend to be kind of ugly no matter
what you do (and hopefully rather rare), so people don't seem bothered
by it.

-Miles

-- 
Everywhere is walking distance if you have the time.  -- Steven Wright

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

end of thread, other threads:[~2007-01-13  2:12 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-01-12  1:58 Another small problem of CC Mode Herbert Euler
2007-01-12  2:05 ` Herbert Euler
2007-01-12  3:13 ` Alfred M. Szmidt
2007-01-12  9:03 ` Alan Mackenzie
2007-01-12 10:06   ` Herbert Euler
2007-01-13  2:12     ` Miles Bader

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