unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* continuing indentation in for loop condition in cc-mode
@ 2016-02-06  1:24 Gregory Fong
  2016-02-06  2:48 ` Emanuel Berg
  0 siblings, 1 reply; 6+ messages in thread
From: Gregory Fong @ 2016-02-06  1:24 UTC (permalink / raw)
  To: help-gnu-emacs

Hello all,

I was trying to figure out how to adjust indentation in a for loop in
emacs like so:

for (int i = 0;
  i < 5;
  ++i)
{
}

but I can't seem to find an offset that adjusts this parameter.
c-show-syntatic information just shows these as being a statement.

Emacs will default to align with the first item in the condition:

for (int i = 0;
     i < 5;
     ++i)
{
}

I can't imagine that I'm the only person who has tried to change this,
but it's surprisingly difficult to search for answers.  The closest
thing to a solution I've found is
https://lists.gnu.org/archive/html/help-gnu-emacs/2008-02/msg00791.html
, but it doesn't seem to change anything and I'm a bit out of my depth
trying to debug it.

If anyone has any thoughts on how to change the indentation to match
the style above, would very much appreciate the help :-).  Any
starting point would be good, I'm just not sure where to go beyond
modifying items in the c-offsets-alist.

Thanks and regards,
Gregory



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

* Re: continuing indentation in for loop condition in cc-mode
  2016-02-06  1:24 continuing indentation in for loop condition in cc-mode Gregory Fong
@ 2016-02-06  2:48 ` Emanuel Berg
  2016-02-13  1:00   ` Gregory Fong
  0 siblings, 1 reply; 6+ messages in thread
From: Emanuel Berg @ 2016-02-06  2:48 UTC (permalink / raw)
  To: help-gnu-emacs

Gregory Fong <gregory.0xf0@gmail.com> writes:

> for (int i = 0;
>   i < 5;
>   ++i)
> {
> }
>
> but I can't seem to find an offset that adjusts this
> parameter. c-show-syntatic information just shows
> these as being a statement.
>
> Emacs will default to align with the first item in
> the condition:
>
> for (int i = 0;
>      i < 5;
>      ++i)
> {
> }
>
> I can't imagine that I'm the only person who has
> tried to change this, but it's surprisingly
> difficult to search for answers.

Why is that so surprising? I'd say most people would
agree with the Emacs default.

Doesn't it make the most sense as well?

And, for such a basic for loop, why not put everything
on the same line?

    for (int i = 0; i < ARRAY_SIZE; i++) {
        ...
    }

-- 
underground experts united
http://user.it.uu.se/~embe8573




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

* Re: continuing indentation in for loop condition in cc-mode
  2016-02-06  2:48 ` Emanuel Berg
@ 2016-02-13  1:00   ` Gregory Fong
  0 siblings, 0 replies; 6+ messages in thread
From: Gregory Fong @ 2016-02-13  1:00 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg <embe8573 <at> student.uu.se> writes:
> Gregory Fong <gregory.0xf0 <at> gmail.com> writes:
> > for (int i = 0;
> >   i < 5;
> >   ++i)
> > {
> > }
> >
> > but I can't seem to find an offset that adjusts this
> > parameter. c-show-syntatic information just shows
> > these as being a statement.
> >
> > Emacs will default to align with the first item in
> > the condition:
> >
> > for (int i = 0;
> >      i < 5;
> >      ++i)
> > {
> > }
> >
> > I can't imagine that I'm the only person who has
> > tried to change this, but it's surprisingly
> > difficult to search for answers.
> 
> Why is that so surprising? I'd say most people would
> agree with the Emacs default.
> 
> Doesn't it make the most sense as well?

I personally like the default.  Unfortunately, the company
I work for uses the style I mentioned at the top.

This is mostly surprising to me because it's really the
only indentation issue I've ever run into using emacs.
Everything else has been customizable regardless of
whatever bizarro coding standard I've had to use, which
is impressive.

> 
> And, for such a basic for loop, why not put everything
> on the same line?
> 
>     for (int i = 0; i < ARRAY_SIZE; i++) {
>         ...
>     }
> 

Yes, that was a poor example.  I was thinking more
of the sorts of long lines you tend to get when working
in C++ with iterators, in which case I'm trying to get it
to look like this:

    for (auto iter = RidiculouslyLongClassName.begin();
      iter < RidiculouslyLongClassName.end();
      ++iter)
    {
      ...
    }


As it is right now, I keep having to remember to fix the
indentation manually, which has been driving me nuts.

If there's a known way to change this behavior, or if you
have an idea on where to start looking at how to do this,
I'd love to hear it. Just not sure where to start.

Thanks and regards,
Gregory





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

* Re: continuing indentation in for loop condition in cc-mode
@ 2016-02-13  2:18 Gregory Fong
  2016-02-15  0:56 ` Emanuel Berg
  2016-02-15  1:20 ` Emanuel Berg
  0 siblings, 2 replies; 6+ messages in thread
From: Gregory Fong @ 2016-02-13  2:18 UTC (permalink / raw)
  To: embe8573; +Cc: help-gnu-emacs

(sorry if you get this twice, I didn't realize I wasn't subscribed
to the list, tried to send using gmane, then that didn't work, so
now I'm just using the reply mailto button from the archive,
which might break the thread)

Emanuel Berg <embe8573 <at> student.uu.se> writes:
> Gregory Fong <gregory.0xf0 <at> gmail.com> writes:
> > for (int i = 0;
> >   i < 5;
> >   ++i)
> > {
> > }
> >
> > but I can't seem to find an offset that adjusts this
> > parameter. c-show-syntatic information just shows
> > these as being a statement.
> >
> > Emacs will default to align with the first item in
> > the condition:
> >
> > for (int i = 0;
> >      i < 5;
> >      ++i)
> > {
> > }
> >
> > I can't imagine that I'm the only person who has
> > tried to change this, but it's surprisingly
> > difficult to search for answers.
>
> Why is that so surprising? I'd say most people would
> agree with the Emacs default.
>
> Doesn't it make the most sense as well?

I personally like the default.  Unfortunately, the company
I work for uses the style I mentioned at the top.

This is mostly surprising to me because it's really the
only indentation issue I've ever run into using emacs.
Everything else has been customizable regardless of
whatever bizarro coding standard I've had to use, which
is impressive.

>
> And, for such a basic for loop, why not put everything
> on the same line?
>
>     for (int i = 0; i < ARRAY_SIZE; i++) {
>         ...
>     }
>

Yes, that was a poor example.  I was thinking more
of the sorts of long lines you tend to get when working
in C++ with iterators, in which case I'm trying to get it
to look like this:

    for (auto iter = RidiculouslyLongClassName.begin();
      iter < RidiculouslyLongClassName.end();
      ++iter)
    {
      ...
    }


As it is right now, I keep having to remember to fix the
indentation manually, which has been driving me nuts.

If there's a known way to change this behavior, or if you
have an idea on where to start looking at how to do this,
I'd love to hear it. Just not sure where to start.

Thanks and regards,
Gregory



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

* Re: continuing indentation in for loop condition in cc-mode
  2016-02-13  2:18 Gregory Fong
@ 2016-02-15  0:56 ` Emanuel Berg
  2016-02-15  1:20 ` Emanuel Berg
  1 sibling, 0 replies; 6+ messages in thread
From: Emanuel Berg @ 2016-02-15  0:56 UTC (permalink / raw)
  To: help-gnu-emacs

Gregory Fong <gregory.0xf0@gmail.com> writes:

> (sorry if you get this twice, I didn't realize
> I wasn't subscribed to the list, tried to send using
> gmane, then that didn't work, so now I'm just using
> the reply mailto button from the archive, which
> might break the thread)

I didn't see this until now because I have splitting
which places mails that are sent to me *and* the list
in a special out-of-action newsgroup. I check that now
and then. Why I didn't see it in the newsgroup itself
(gmane.emacs.help) remains as mystery tho...

> I personally like the default. Unfortunately, the
> company I work for uses the style I mentioned at
> the top.
>
> This is mostly surprising to me because it's really
> the only indentation issue I've ever run into using
> emacs. Everything else has been customizable

This is customizable as well. Or rather it is (at
least) programmable like everything else.

Check out this file:

    http://user.it.uu.se/~embe8573/fps/fpscalc.el

The "fpscalc-indent-line" is the function that
does indentation.

There should be a similar function for the C++ mode.
It is most likely more advanced and better, as it has
a bigger domain and more people worked on it for
a much longer time. But the principle that a function
does indentation should be the same.

So you can start by finding that function, continue by
understanding it, and last push for the summit by
modifying it to do you bidding.

That should be pretty simple :)

>> And, for such a basic for loop, why not put
>> everything on the same line?
>>
>> for (int i = 0; i < ARRAY_SIZE; i++) { ... }
>
> Yes, that was a poor example. I was thinking more of
> the sorts of long lines you tend to get when working
> in C++ with iterators, in which case I'm trying to get
> it to look like this:
>
>     for (auto iter =
> RidiculouslyLongClassName.begin(); iter <
> RidiculouslyLongClassName.end(); ++iter) { ... }

Yuk! That reminds me of Java. But it doesn't have to
be *that* bad.

You don't have to do initialization of the iterator
within the for loop syntax, right?

And you can likewise assign an external variable
(external to the for loop syntax) to hold the range of
the iteration, instead of invoking the end() method
at each iteration.

It is perhaps not the OO way but it'll solve
(workaround) the syntax/indentation issue.

> As it is right now, I keep having to remember to fix
> the indentation manually, which has been driving
> me nuts.

Really? What's wrong with fixing it manually?
For example this message I have written 100% manually
with zero problems. How many such loops do you do each
day? Perhaps you should do mental-physical training,
e.g. yoga, instead of getting nuts at corporate-style
C++ indentation?

> If there's a known way to change this behavior, or
> if you have an idea on where to start looking at how
> to do this, I'd love to hear it. Just not sure where
> to start.

Start at the Elisp code which is the Emacs C++ mode.

PS. I post this to the newsgroup as well.
    But I include a copy to your mail as you might
    have forgotten about this issue since there was no
    replies for some time. Again, I didn't see the
    post at the newsgroup. If others did, they didn't
    respond (or I didn't see those posts either).
    This post they will see and possibly reply to, so
    even tho you read this as a personal mail be sure
    to check the newsgroup/mailing list as well.

-- 
underground experts united
http://user.it.uu.se/~embe8573




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

* Re: continuing indentation in for loop condition in cc-mode
  2016-02-13  2:18 Gregory Fong
  2016-02-15  0:56 ` Emanuel Berg
@ 2016-02-15  1:20 ` Emanuel Berg
  1 sibling, 0 replies; 6+ messages in thread
From: Emanuel Berg @ 2016-02-15  1:20 UTC (permalink / raw)
  To: help-gnu-emacs

Gregory Fong <gregory.0xf0@gmail.com> writes:

> (sorry if you get this twice, I didn't realize
> I wasn't subscribed to the list, tried to send using
> gmane, then that didn't work, so now I'm just using
> the reply mailto button from the archive, which
> might break the thread)

OK, so now I see it here as well! Actually I see it
*twice* here. So now I've seen it three times.
And because of all the citing - can we even say four?

-- 
underground experts united
http://user.it.uu.se/~embe8573




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

end of thread, other threads:[~2016-02-15  1:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-06  1:24 continuing indentation in for loop condition in cc-mode Gregory Fong
2016-02-06  2:48 ` Emanuel Berg
2016-02-13  1:00   ` Gregory Fong
  -- strict thread matches above, loose matches on Subject: below --
2016-02-13  2:18 Gregory Fong
2016-02-15  0:56 ` Emanuel Berg
2016-02-15  1:20 ` Emanuel Berg

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