unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Change of C indentation style ('{')
@ 2003-10-23  1:09 Kenichi Handa
  2003-10-23 22:16 ` Martin Stjernholm
  0 siblings, 1 reply; 18+ messages in thread
From: Kenichi Handa @ 2003-10-23  1:09 UTC (permalink / raw)


I've just found that, in HEAD, the default indentation style
of '{' in C was changed in the case that it was placed on
the next line of macros such as FOR_EACH_FRAME.

For instance, see L1232 of frame.c.  The source code is
currently indented as below:

	  FOR_EACH_FRAME (tail, frame1)
	    {
	      if (! EQ (frame, frame1))
		break;
	    }

But, when I put cursor at the beginning of the second line
and type C-u TAB, the lines are indented as below:

	  FOR_EACH_FRAME (tail, frame1)
	  {
	    if (! EQ (frame, frame1))
	      break;
	  }

Is this change intentional?  Is it possible to get the
previous style by customizing something?

---
Ken'ichi HANDA
handa@m17n.org

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

* Re: Change of C indentation style ('{')
  2003-10-23  1:09 Change of C indentation style ('{') Kenichi Handa
@ 2003-10-23 22:16 ` Martin Stjernholm
  2003-10-24  1:25   ` Kenichi Handa
                     ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: Martin Stjernholm @ 2003-10-23 22:16 UTC (permalink / raw)
  Cc: bug-cc-mode, emacs-devel

Kenichi Handa <handa@m17n.org> wrote:

> I've just found that, in HEAD, the default indentation style
> of '{' in C was changed in the case that it was placed on
> the next line of macros such as FOR_EACH_FRAME.

That's because CC Mode analyzes the braces differently now. It marks
them as defun-open and defun-close instead of substatement-open and
substatement-close. That is because FOR_EACH_FRAME isn't recognized as
a substatement introducing keyword, and barring macro oddities
everything else has to be function definitions.

I'm not sure what to do about it. There are other cases when this new
heuristic is useful, e.g. for functions in macro arguments or gcc
nested functions.

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

* Re: Change of C indentation style ('{')
  2003-10-23 22:16 ` Martin Stjernholm
@ 2003-10-24  1:25   ` Kenichi Handa
  2003-10-24  3:48   ` Miles Bader
  2003-10-24 23:24   ` Richard Stallman
  2 siblings, 0 replies; 18+ messages in thread
From: Kenichi Handa @ 2003-10-24  1:25 UTC (permalink / raw)
  Cc: bug-cc-mode, emacs-devel

In article <5bhe1zy4z8.fsf@lister.roxen.com>, Martin Stjernholm <mast@lysator.liu.se> writes:

> Kenichi Handa <handa@m17n.org> wrote:
>>  I've just found that, in HEAD, the default indentation style
>>  of '{' in C was changed in the case that it was placed on
>>  the next line of macros such as FOR_EACH_FRAME.

> That's because CC Mode analyzes the braces differently now. It marks
> them as defun-open and defun-close instead of substatement-open and
> substatement-close. That is because FOR_EACH_FRAME isn't recognized as
> a substatement introducing keyword, and barring macro oddities
> everything else has to be function definitions.

I see.

> I'm not sure what to do about it. There are other cases when this new
> heuristic is useful, e.g. for functions in macro arguments or gcc
> nested functions.

Aren't there any way to make Emacs recognize the regular
expression, say "[A-Z_]+", as an additional substatement
introducing keyword?

---
Ken'ichi HANDA
handa@m17n.org

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

* Re: Change of C indentation style ('{')
  2003-10-23 22:16 ` Martin Stjernholm
  2003-10-24  1:25   ` Kenichi Handa
@ 2003-10-24  3:48   ` Miles Bader
  2003-10-24  9:56     ` Martin Stjernholm
  2003-10-24 23:24   ` Richard Stallman
  2 siblings, 1 reply; 18+ messages in thread
From: Miles Bader @ 2003-10-24  3:48 UTC (permalink / raw)
  Cc: Kenichi Handa, bug-cc-mode, emacs-devel

Martin Stjernholm <mast@lysator.liu.se> writes:
> That is because FOR_EACH_FRAME isn't recognized as
> a substatement introducing keyword, and barring macro oddities
> everything else has to be function definitions.
> 
> I'm not sure what to do about it. There are other cases when this new
> heuristic is useful, e.g. for functions in macro arguments or gcc
> nested functions.

The thing is, I wouldn't be surprised if `macro oddities' are actually
more common than the nested functions, or functions in macro arguments...

-Miles
-- 
I'd rather be consing.


-------------------------------------------------------
This SF.net email is sponsored by: The SF.net Donation Program.
Do you like what SourceForge.net is doing for the Open
Source Community?  Make a contribution, and help us add new
features and functionality. Click here: http://sourceforge.net/donate/


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

* Re: Change of C indentation style ('{')
  2003-10-24  3:48   ` Miles Bader
@ 2003-10-24  9:56     ` Martin Stjernholm
  2003-10-24 10:11       ` Miles Bader
  0 siblings, 1 reply; 18+ messages in thread
From: Martin Stjernholm @ 2003-10-24  9:56 UTC (permalink / raw)
  Cc: bug-cc-mode, emacs-devel, Kenichi Handa

Miles Bader <miles@lsi.nec.co.jp> wrote:

> The thing is, I wouldn't be surprised if `macro oddities' are actually
> more common than the nested functions, or functions in macro arguments...

You're probably right when it comes to C which uses cpp a lot. Perhaps
also for C++, ObjC and Pike; they have cpp support too but it's not
used quite as much there.

It should be possible to add some more checks. Afterall, macro
constructs like that can only be ambiguous with really old fashioned
K&R style function definitions.

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

* Re: Change of C indentation style ('{')
  2003-10-24  9:56     ` Martin Stjernholm
@ 2003-10-24 10:11       ` Miles Bader
  0 siblings, 0 replies; 18+ messages in thread
From: Miles Bader @ 2003-10-24 10:11 UTC (permalink / raw)
  Cc: bug-cc-mode, emacs-devel, Kenichi Handa

Martin Stjernholm <mast@lysator.liu.se> writes:
> > The thing is, I wouldn't be surprised if `macro oddities' are actually
> > more common than the nested functions, or functions in macro arguments...
> 
> You're probably right when it comes to C which uses cpp a lot. Perhaps
> also for C++, ObjC and Pike; they have cpp support too but it's not
> used quite as much there.
> 
> It should be possible to add some more checks. Afterall, macro
> constructs like that can only be ambiguous with really old fashioned
> K&R style function definitions.

I was thinking of things like:

   #define some_iterator_macro(var, arg1, arg2) ...

   void some_function (int y, int z)
   {
     some_iterator_macro (x, y + 3, z)
       {
         do_something_with (x);
       }
   }

That sort of macro usage is fairly common, and looks vaguely like an
ANSI C function declaration (no?).

-miles
-- 
I'm beginning to think that life is just one long Yoko Ono album; no rhyme
or reason, just a lot of incoherent shrieks and then it's over.  --Ian Wolff

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

* Re: Change of C indentation style ('{')
  2003-10-23 22:16 ` Martin Stjernholm
  2003-10-24  1:25   ` Kenichi Handa
  2003-10-24  3:48   ` Miles Bader
@ 2003-10-24 23:24   ` Richard Stallman
  2003-10-25 14:40     ` Martin Stjernholm
  2 siblings, 1 reply; 18+ messages in thread
From: Richard Stallman @ 2003-10-24 23:24 UTC (permalink / raw)
  Cc: handa, bug-cc-mode, emacs-devel

    That's because CC Mode analyzes the braces differently now. It marks
    them as defun-open and defun-close instead of substatement-open and
    substatement-close. That is because FOR_EACH_FRAME isn't recognized as
    a substatement introducing keyword, and barring macro oddities
    everything else has to be function definitions.

    I'm not sure what to do about it.

You could perhaps undo the change.

				      There are other cases when this new
    heuristic is useful, e.g. for functions in macro arguments or gcc
    nested functions.

could you show us the cases in question?
if we can't make them all work rt, we should choose the case
more useful in practice and make it wrk rt.

or there cd in theory be some convention used to say which way to do it.


-------------------------------------------------------
This SF.net email is sponsored by: The SF.net Donation Program.
Do you like what SourceForge.net is doing for the Open
Source Community?  Make a contribution, and help us add new
features and functionality. Click here: http://sourceforge.net/donate/


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

* Re: Change of C indentation style ('{')
  2003-10-24 23:24   ` Richard Stallman
@ 2003-10-25 14:40     ` Martin Stjernholm
  2003-10-27  7:02       ` Richard Stallman
  0 siblings, 1 reply; 18+ messages in thread
From: Martin Stjernholm @ 2003-10-25 14:40 UTC (permalink / raw)
  Cc: bug-cc-mode, emacs-devel, handa

Richard Stallman <rms@gnu.org> wrote:

>     I'm not sure what to do about it.
>
> You could perhaps undo the change.

That would also undo this improvement:

    ** Statements are recognized in a more robust way.
    Statements are recognized most of the time even when they occur in an
    "invalid" context, e.g. in a function argument.  In practice that can
    happen when macros are involved.

As an example, it fixes better indentation in this case:

    void f() {
      SOME_MACRO (
        if (successful)
          fprintf (stderr, "ok\n");
        else
          abort();
      );
    }

The reason these two cases are related is because the above has been
accomplished by changing the order between checks in
c-guess-basic-syntax.

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

* Re: Change of C indentation style ('{')
  2003-10-25 14:40     ` Martin Stjernholm
@ 2003-10-27  7:02       ` Richard Stallman
  2003-10-27 14:24         ` Martin Stjernholm
  0 siblings, 1 reply; 18+ messages in thread
From: Richard Stallman @ 2003-10-27  7:02 UTC (permalink / raw)
  Cc: bug-cc-mode, handa, emacs-devel

    That would also undo this improvement:

	** Statements are recognized in a more robust way.
	Statements are recognized most of the time even when they occur in an
	"invalid" context, e.g. in a function argument.  In practice that can
	happen when macros are involved.

    As an example, it fixes better indentation in this case:

	void f() {
	  SOME_MACRO (
	    if (successful)
	      fprintf (stderr, "ok\n");
	    else
	      abort();
	  );
	}

i see.

this test case has the { starting a fn body
not at col 0.  does the improvement occur in the same way
when users put the { in col 0?

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

* Re: Change of C indentation style ('{')
  2003-10-27  7:02       ` Richard Stallman
@ 2003-10-27 14:24         ` Martin Stjernholm
  2003-10-28 20:39           ` Richard Stallman
  0 siblings, 1 reply; 18+ messages in thread
From: Martin Stjernholm @ 2003-10-27 14:24 UTC (permalink / raw)
  Cc: bug-cc-mode, handa, emacs-devel

Richard Stallman <rms@gnu.org> wrote:

> this test case has the { starting a fn body
> not at col 0.  does the improvement occur in the same way
> when users put the { in col 0?

Yes. Only the surrounding parentheses belonging to the macro are
relevant. They normally signal to CC Mode to treat the content as
function arguments, which typically is an invalid context for
statements.

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

* Re: Change of C indentation style ('{')
  2003-10-27 14:24         ` Martin Stjernholm
@ 2003-10-28 20:39           ` Richard Stallman
  2003-10-29 19:28             ` Martin Stjernholm
  0 siblings, 1 reply; 18+ messages in thread
From: Richard Stallman @ 2003-10-28 20:39 UTC (permalink / raw)
  Cc: bug-cc-mode, emacs-devel, handa

Maybe the change is an improvement.  It is hard for me to judge
how often it helps and how often it hurts.

But an idea does occur to me that maybe the user could declare certain
symbols that should be treated like `while'.  Or maybe some more
general mechanism would fit easily into the framework of the rest of
cc-mode.  Then there could be some kind of declaration in the source
file itself, which would be hidden in a comment.  cc-mode could search
for these declarations when it visits a file.

Could you think about this approach?


-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?   SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/


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

* Re: Change of C indentation style ('{')
  2003-10-28 20:39           ` Richard Stallman
@ 2003-10-29 19:28             ` Martin Stjernholm
  2003-10-29 21:41               ` Miles Bader
  2003-10-30 18:01               ` Richard Stallman
  0 siblings, 2 replies; 18+ messages in thread
From: Martin Stjernholm @ 2003-10-29 19:28 UTC (permalink / raw)
  Cc: bug-cc-mode, emacs-devel, handa

Richard Stallman <rms@gnu.org> wrote:

> But an idea does occur to me that maybe the user could declare certain
> symbols that should be treated like `while'.  /.../
>
> Could you think about this approach?

I don't think that would be necessary. As I said in another branch of
this thread, these macro constructs are only truly ambiguous with old
K&R style function definitions. So it ought to be possible to solve
with more careful checks.


-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?   SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/


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

* Re: Change of C indentation style ('{')
  2003-10-29 19:28             ` Martin Stjernholm
@ 2003-10-29 21:41               ` Miles Bader
  2003-10-30  0:03                 ` Martin Stjernholm
                                   ` (2 more replies)
  2003-10-30 18:01               ` Richard Stallman
  1 sibling, 3 replies; 18+ messages in thread
From: Miles Bader @ 2003-10-29 21:41 UTC (permalink / raw)
  Cc: bug-cc-mode, emacs-devel, rms, handa

On Wed, Oct 29, 2003 at 08:28:42PM +0100, Martin Stjernholm wrote:
> I don't think that would be necessary. As I said in another branch of
> this thread, these macro constructs are only truly ambiguous with old
> K&R style function definitions. So it ought to be possible to solve
> with more careful checks.

What about the example I gave (in another message) that would seem to
indicate otherwise?

[Not that I think requring `declarations' of macros is a very workable idea
-- people wouldn't do it 99% of the time]

-Miles
-- 
.Numeric stability is probably not all that important when you're guessing.

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

* Re: Change of C indentation style ('{')
  2003-10-29 21:41               ` Miles Bader
@ 2003-10-30  0:03                 ` Martin Stjernholm
  2003-10-30  0:11                   ` Miles Bader
  2003-10-30  0:30                 ` Stefan Monnier
  2003-10-30 18:00                 ` Richard Stallman
  2 siblings, 1 reply; 18+ messages in thread
From: Martin Stjernholm @ 2003-10-30  0:03 UTC (permalink / raw)
  Cc: rms, bug-cc-mode, handa, emacs-devel

Miles Bader <miles@gnu.org> wrote:

> On Wed, Oct 29, 2003 at 08:28:42PM +0100, Martin Stjernholm wrote:
>> /.../ these macro constructs are only truly ambiguous with old K&R
>> style function definitions. So it ought to be possible to solve
>> with more careful checks.
>
> What about the example I gave (in another message) that would seem to
> indicate otherwise?

I can't see that it does. In your example it's possible to look at
both the expression in the parenthesis and the lack of a return type.
I planned to only check for the return type since it's more reliable.

> [Not that I think requring `declarations' of macros is a very workable idea
> -- people wouldn't do it 99% of the time]

I agree. (It's the same thing with the c-font-lock-extra-types
variable - I don't think it's good enough to rely on that to fontify
types correctly, and so I implemented a considerably more elaborate
method to recognize declarations and casts.)


-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?   SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/


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

* Re: Change of C indentation style ('{')
  2003-10-30  0:03                 ` Martin Stjernholm
@ 2003-10-30  0:11                   ` Miles Bader
  0 siblings, 0 replies; 18+ messages in thread
From: Miles Bader @ 2003-10-30  0:11 UTC (permalink / raw)
  Cc: Miles Bader, rms, bug-cc-mode, handa, emacs-devel

On Thu, Oct 30, 2003 at 01:03:01AM +0100, Martin Stjernholm wrote:
> > What about the example I gave (in another message) that would seem to
> > indicate otherwise?
> 
> I can't see that it does. In your example it's possible to look at
> both the expression in the parenthesis and the lack of a return type.
> I planned to only check for the return type since it's more reliable.

Ok, I see what you mean now; yeah, that seems like it should work...

-Miles
-- 
Love is a snowmobile racing across the tundra.  Suddenly it flips over,
pinning you underneath.  At night the ice weasels come.  --Nietzsche


-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?   SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/


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

* Re: Change of C indentation style ('{')
  2003-10-29 21:41               ` Miles Bader
  2003-10-30  0:03                 ` Martin Stjernholm
@ 2003-10-30  0:30                 ` Stefan Monnier
  2003-10-30 18:00                 ` Richard Stallman
  2 siblings, 0 replies; 18+ messages in thread
From: Stefan Monnier @ 2003-10-30  0:30 UTC (permalink / raw)
  Cc: Martin Stjernholm, bug-cc-mode, emacs-devel, rms, handa

> [Not that I think requring `declarations' of macros is a very workable idea
> -- people wouldn't do it 99% of the time]

Not only people wouldn't do it, but manually fixing a slightly incorrect
indentation is pretty easy and is cannot in general be avoided.

For people who want a full-reindent of the code to correctly preserve
the manually-indented parts of the code, I had suggested that we could
support special tags in comments to mean "don't touch this".
In my sml-mode, I used (*fixindent*) as the special tag.  This is needed
because it is very common in SML to want to indent some parts of code
specially: typically one function acts as a module but the author does not
want to indent everything within it by the customary 2 or 3 chars (SML code
already suffers from the tendency to indent too much).
The mode has no way to tell that this function is different from others,
so the user has to reindent a few key lines manually.  The `fixindent'
trick allows them to make the whole file "reindent safe".


        Stefan


-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?   SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/


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

* Re: Change of C indentation style ('{')
  2003-10-29 21:41               ` Miles Bader
  2003-10-30  0:03                 ` Martin Stjernholm
  2003-10-30  0:30                 ` Stefan Monnier
@ 2003-10-30 18:00                 ` Richard Stallman
  2 siblings, 0 replies; 18+ messages in thread
From: Richard Stallman @ 2003-10-30 18:00 UTC (permalink / raw)
  Cc: mast, bug-cc-mode, handa, emacs-devel

    [Not that I think requring `declarations' of macros is a very workable idea

Sure it is.  We have other features like this in emacs, and they are useful.

    -- people wouldn't do it 99% of the time]

People would do it when they care about the results, and that is good
enough to make it worth doing if it is easy to do.

Of course, a fully automatic solution is certainly better, if it is
not too much work.


-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?   SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/


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

* Re: Change of C indentation style ('{')
  2003-10-29 19:28             ` Martin Stjernholm
  2003-10-29 21:41               ` Miles Bader
@ 2003-10-30 18:01               ` Richard Stallman
  1 sibling, 0 replies; 18+ messages in thread
From: Richard Stallman @ 2003-10-30 18:01 UTC (permalink / raw)
  Cc: bug-cc-mode, emacs-devel, handa

    I don't think that would be necessary. As I said in another branch of
    this thread, these macro constructs are only truly ambiguous with old
    K&R style function definitions. So it ought to be possible to solve
    with more careful checks.

if you can make these cases all work right with no declarations,
so much the better.


-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?   SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/


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

end of thread, other threads:[~2003-10-30 18:01 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-23  1:09 Change of C indentation style ('{') Kenichi Handa
2003-10-23 22:16 ` Martin Stjernholm
2003-10-24  1:25   ` Kenichi Handa
2003-10-24  3:48   ` Miles Bader
2003-10-24  9:56     ` Martin Stjernholm
2003-10-24 10:11       ` Miles Bader
2003-10-24 23:24   ` Richard Stallman
2003-10-25 14:40     ` Martin Stjernholm
2003-10-27  7:02       ` Richard Stallman
2003-10-27 14:24         ` Martin Stjernholm
2003-10-28 20:39           ` Richard Stallman
2003-10-29 19:28             ` Martin Stjernholm
2003-10-29 21:41               ` Miles Bader
2003-10-30  0:03                 ` Martin Stjernholm
2003-10-30  0:11                   ` Miles Bader
2003-10-30  0:30                 ` Stefan Monnier
2003-10-30 18:00                 ` Richard Stallman
2003-10-30 18:01               ` Richard Stallman

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