unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Java mode indention
@ 2003-07-31 16:02 J Richardson
  0 siblings, 0 replies; 9+ messages in thread
From: J Richardson @ 2003-07-31 16:02 UTC (permalink / raw)



I can't figure out how to get Emacs to indent this the way I'd like.
It seems to be using the position of the last opening parenthesis as
the offset.

    Writer out = new BufferedWriter(new FileWriter(
                                        "filename.log")));

I'd like it to use the base offset of the beginning of the statement
instead.

    Writer out = new BufferedWriter(new FileWriter(
        "filename.log")));

Anyone have an idea?

Thanks,
Jen

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

* Re: Java mode indention
       [not found] <mailman.789.1059668280.8231.help-gnu-emacs@gnu.org>
@ 2003-07-31 17:06 ` Kai Großjohann
  2003-07-31 19:43   ` J Richardson
       [not found]   ` <mailman.806.1059680707.8231.help-gnu-emacs@gnu.org>
  2003-08-10 17:35 ` Stefan Monnier
  1 sibling, 2 replies; 9+ messages in thread
From: Kai Großjohann @ 2003-07-31 17:06 UTC (permalink / raw)


J Richardson <jrivers77@yahoo.com> writes:

> I'd like it to use the base offset of the beginning of the statement
> instead.

I've done this for the case where the open paren is the last thing on
the line.  This way, I get the following:

f(a,
  b);
f(
    a,
    b);

I did it my running (c-set-offset 'arglist-intro '+) from
java-mode-hook:

(defun my-java-indent ()
  (c-set-offset ...))
(add-hook 'java-mode-hook 'my-java-indent)
-- 
~/.signature

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

* Re: Java mode indention
  2003-07-31 17:06 ` Java mode indention Kai Großjohann
@ 2003-07-31 19:43   ` J Richardson
       [not found]   ` <mailman.806.1059680707.8231.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 9+ messages in thread
From: J Richardson @ 2003-07-31 19:43 UTC (permalink / raw)


kai.grossjohann@gmx.net (Kai Großjohann) writes:

> J Richardson <jrivers77@yahoo.com> writes:
> 
> > I'd like it to use the base offset of the beginning of the statement
> > instead.
> 
> I've done this for the case where the open paren is the last thing on
> the line.  This way, I get the following:
> 
> f(a,
>   b);
> f(
>     a,
>     b);
> 
> I did it my running (c-set-offset 'arglist-intro '+) from
> java-mode-hook:
> 
> (defun my-java-indent ()
>   (c-set-offset ...))
> (add-hook 'java-mode-hook 'my-java-indent)

I have that... it only works for one set of parentheses though. I
don't like what it does if you add another one. I'm not sure what
terminology to use. It goes from the start of the method call instead
of the start of the whole statement.

My offset is set to 4, and I have (c-set-offset 'arglist-intro '+), so:

  a_method(another_method(foo,
               bar));

          ^ it adds the extra offset of 4 from here

when I'd prefer this:

  a_method(another_method(foo,
      bar));

  ^ I want it to add it from here

If there is only one parenthesis then the two cases are the same.
I've been living with it for a while, and your recent question about
indentation reminded me about it :-)

At one point it did what I wanted, but that was at my old job and I
don't remember which version of Emacs it was. Either the default
behavior changed or there was something in my .emacs there that I
forgot to bring forward sometime. I've taken out my customizations to
make sure it isn't something I've added that did it.

Thanks,
Jen

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

* Re: Java mode indention
       [not found]   ` <mailman.806.1059680707.8231.help-gnu-emacs@gnu.org>
@ 2003-08-01 20:38     ` Kai Großjohann
  2003-08-01 21:24     ` Alan Mackenzie
  1 sibling, 0 replies; 9+ messages in thread
From: Kai Großjohann @ 2003-08-01 20:38 UTC (permalink / raw)


J Richardson <jrivers77@yahoo.com> writes:

> My offset is set to 4, and I have (c-set-offset 'arglist-intro '+), so:
>
>   a_method(another_method(foo,
>                bar));
>
>           ^ it adds the extra offset of 4 from here

Gnnn.  This is bad.  Why does it do that?  Hrmpf.

I guess that setting this other thingy that is responsible for the

    f(a,
        b);

case will also do the trick for you.  Maybe I'm gonna hafta bite the
bullet.
-- 
~/.signature

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

* Re: Java mode indention
       [not found]   ` <mailman.806.1059680707.8231.help-gnu-emacs@gnu.org>
  2003-08-01 20:38     ` Kai Großjohann
@ 2003-08-01 21:24     ` Alan Mackenzie
  2003-08-06 18:21       ` J Richardson
  1 sibling, 1 reply; 9+ messages in thread
From: Alan Mackenzie @ 2003-08-01 21:24 UTC (permalink / raw)


J Richardson <jrivers77@yahoo.com> wrote on 31 Jul 2003 15:43:20 -0400:
> kai.grossjohann@gmx.net (Kai Großjohann) writes:

>> J Richardson <jrivers77@yahoo.com> writes:

[ .... ]

>> I did it my running (c-set-offset 'arglist-intro '+) from
>> java-mode-hook:

>> (defun my-java-indent ()
>>   (c-set-offset ...))
>> (add-hook 'java-mode-hook 'my-java-indent)

> I have that... it only works for one set of parentheses though. I don't
> like what it does if you add another one. I'm not sure what terminology
> to use. It goes from the start of the method call instead of the start
> of the whole statement.

> My offset is set to 4, and I have (c-set-offset 'arglist-intro '+), so:

>   a_method(another_method(foo,
>                bar));

>           ^ it adds the extra offset of 4 from here

Are you being absolutely accurate here?  "bar" seems to be indented _5_
columns from the "(" and _13_ columns from beginning-of-line.  Could you
do a C-c C-s (i.e. `c-show-syntactic-information') on this line, please?

Also, which version of CC Mode are you using?  (Do M-x c-version).

> when I'd prefer this:

>   a_method(another_method(foo,
>       bar));

>   ^ I want it to add it from here

In the most recent CC Mode (5.30) it looks like the "bar" would get
indented 8 columns from begining-of-line (4 columns (c-basic-offset) for
each level of parentheses).  This isn't very good either.  It may well be
that the best quick fix would be to write you a special indentation
function (see the page "Indentation Functions" in the CC Mode manual).

The most helpful place to report this sort of problem is on the CC Mode
mailing list at bug-cc-mode@gnu.org.

> If there is only one parenthesis then the two cases are the same.
> I've been living with it for a while, and your recent question about
> indentation reminded me about it :-)

> At one point it did what I wanted, but that was at my old job and I
> don't remember which version of Emacs it was. Either the default
> behavior changed or there was something in my .emacs there that I
> forgot to bring forward sometime. I've taken out my customizations to
> make sure it isn't something I've added that did it.

> Thanks,
> Jen

-- 
Alan Mackenzie (Munich, Germany)
Email: aacm@muuc.dee; to decode, wherever there is a repeated letter
(like "aa"), remove half of them (leaving, say, "a").

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

* Re: Java mode indention
  2003-08-01 21:24     ` Alan Mackenzie
@ 2003-08-06 18:21       ` J Richardson
  2003-08-06 20:05         ` J Richardson
  0 siblings, 1 reply; 9+ messages in thread
From: J Richardson @ 2003-08-06 18:21 UTC (permalink / raw)


Alan Mackenzie<none@example.invalid> writes:

> J Richardson <jrivers77@yahoo.com> wrote on 31 Jul 2003 15:43:20 -0400:
> > kai.grossjohann@gmx.net (Kai Großjohann) writes:
> 
> >> J Richardson <jrivers77@yahoo.com> writes:
> 
> [ .... ]
> 
> >> I did it my running (c-set-offset 'arglist-intro '+) from
> >> java-mode-hook:
> 
> >> (defun my-java-indent ()
> >>   (c-set-offset ...))
> >> (add-hook 'java-mode-hook 'my-java-indent)
> 
> > I have that... it only works for one set of parentheses though. I don't
> > like what it does if you add another one. I'm not sure what terminology
> > to use. It goes from the start of the method call instead of the start
> > of the whole statement.
> 
> > My offset is set to 4, and I have (c-set-offset 'arglist-intro '+), so:
> 
> >   a_method(another_method(foo,
> >                bar));
> 
> >           ^ it adds the extra offset of 4 from here
> 
> Are you being absolutely accurate here?  "bar" seems to be indented _5_
> columns from the "(" and _13_ columns from beginning-of-line.  Could you
> do a C-c C-s (i.e. `c-show-syntactic-information') on this line, please?
> 

Sorry, two things here. The ^ actually should be one more space to the
right, and I was thinking about my other example. It's
arglist-cont-nonempty in this case. It's set to + too.

  arglist-intro:
  a_method(another_method(
               foo, bar));


  arglist-cont-nonempty:
  a_method(another_method(foo,
               bar));

> Also, which version of CC Mode are you using?  (Do M-x c-version).

CC Mode version 5.28

> 
> > when I'd prefer this:
> 
> >   a_method(another_method(foo,
> >       bar));
> 
> >   ^ I want it to add it from here
> 
> In the most recent CC Mode (5.30) it looks like the "bar" would get
> indented 8 columns from begining-of-line (4 columns (c-basic-offset) for
> each level of parentheses).  This isn't very good either.  It may well be
> that the best quick fix would be to write you a special indentation
> function (see the page "Indentation Functions" in the CC Mode manual).

I'll check out 5.30. Indenting from the beginning of the line is the
issue I wasn't sure how to work around.

I looked at indentation functions a while ago. Rechecking now, they
take a syntactic component cons cell which contains the "buffer
relative position" and return the offset to add to that position. I'm
by no means an elisp guru, so I may be missing something, but since
it's the buffer relative position that I don't like I'm not sure how
to get that to work. It sounds like CC Mode 5.30 may help there
though.

> 
> The most helpful place to report this sort of problem is on the CC Mode
> mailing list at bug-cc-mode@gnu.org.
> 

Thanks!

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

* Re: Java mode indention
  2003-08-06 18:21       ` J Richardson
@ 2003-08-06 20:05         ` J Richardson
  0 siblings, 0 replies; 9+ messages in thread
From: J Richardson @ 2003-08-06 20:05 UTC (permalink / raw)


J Richardson <jrivers77@yahoo.com> writes:

> 
>   arglist-intro:
>   a_method(another_method(
>                foo, bar));
> 
> 
>   arglist-cont-nonempty:
>   a_method(another_method(foo,
>                bar));
> 
> > Also, which version of CC Mode are you using?  (Do M-x c-version).
> 
> CC Mode version 5.28
> 
> > 
> > > when I'd prefer this:
> > 
> > >   a_method(another_method(foo,
> > >       bar));
> > 
> > >   ^ I want it to add it from here
> > 
> > In the most recent CC Mode (5.30) it looks like the "bar" would get
> > indented 8 columns from begining-of-line (4 columns (c-basic-offset) for
> > each level of parentheses).  This isn't very good either.  It may well be
> > that the best quick fix would be to write you a special indentation
> > function (see the page "Indentation Functions" in the CC Mode manual).
> 
> I'll check out 5.30. Indenting from the beginning of the line is the
> issue I wasn't sure how to work around.
> 
> I looked at indentation functions a while ago. Rechecking now, they
> take a syntactic component cons cell which contains the "buffer
> relative position" and return the offset to add to that position. I'm
> by no means an elisp guru, so I may be missing something, but since
> it's the buffer relative position that I don't like I'm not sure how
> to get that to work. It sounds like CC Mode 5.30 may help there
> though.
> 
> > 
> > The most helpful place to report this sort of problem is on the CC Mode
> > mailing list at bug-cc-mode@gnu.org.
> > 

Ooh, I have it now. Archives from bug-cc-mode@gnu.org helped. I didn't
know about the back-to-indentation function.

(defun jc-indent-method-args (langelem)
  (save-excursion
    (goto-char (cdr langelem))
    (back-to-indentation)
    (vector (+ (current-column) c-basic-offset))))

(c-set-offset 'arglist-intro 'jc-indent-method-args)
(c-set-offset 'arglist-cont 'jc-indent-method-args)
(c-set-offset 'arglist-cont-nonempty 'jc-indent-method-args)

It seems to work so far.

Thanks!

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

* Re: Java mode indention
       [not found] <mailman.789.1059668280.8231.help-gnu-emacs@gnu.org>
  2003-07-31 17:06 ` Java mode indention Kai Großjohann
@ 2003-08-10 17:35 ` Stefan Monnier
  2003-08-12 17:03   ` J Richardson
  1 sibling, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2003-08-10 17:35 UTC (permalink / raw)


>     Writer out = new BufferedWriter(new FileWriter(
>                                         "filename.log")));
[...]
>     Writer out = new BufferedWriter(new FileWriter(
>         "filename.log")));

How do you deal with multiple arguments as in:

     Writer out = new BufferedWriter(new FileWriter(
                                         "filename.log"),
                                     secondarg));
or
     Writer out = new BufferedWriter(firstarg,
                                     new FileWriter(
                                         "filename.log")));


-- Stefan

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

* Re: Java mode indention
  2003-08-10 17:35 ` Stefan Monnier
@ 2003-08-12 17:03   ` J Richardson
  0 siblings, 0 replies; 9+ messages in thread
From: J Richardson @ 2003-08-12 17:03 UTC (permalink / raw)


"Stefan Monnier" <monnier+gnu.emacs.help/news/@flint.cs.yale.edu> writes:

> >     Writer out = new BufferedWriter(new FileWriter(
> >                                         "filename.log")));
> [...]
> >     Writer out = new BufferedWriter(new FileWriter(
> >         "filename.log")));
> 
> How do you deal with multiple arguments as in:
> 
>      Writer out = new BufferedWriter(new FileWriter(
>                                          "filename.log"),
>                                      secondarg));
> or
>      Writer out = new BufferedWriter(firstarg,
>                                      new FileWriter(
>                                          "filename.log")));

What it's doing now (after I tinkered with it) is:

        Writer out = new BufferedWriter(new FileWriter(
            "filename.log"),
            secondarg);

        Writer out = new BufferedWriter(firstarg,
            new FileWriter(
                "filename.log"));

Which is ok, though I'm of two minds about the extra indent level on
the second one. If I had a lot of nested calls with multiple
parameters it would be helpful, but I don't see that much.

I don't run into lots of long nested calls except with IO Streams and
Readers/Writers in Java, and I rarely use more than one parameter with
them. As long as the wrapped line ends up far enough to the left that
I have enough space to type something useful it doesn't bother me.

Jen

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

end of thread, other threads:[~2003-08-12 17:03 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.789.1059668280.8231.help-gnu-emacs@gnu.org>
2003-07-31 17:06 ` Java mode indention Kai Großjohann
2003-07-31 19:43   ` J Richardson
     [not found]   ` <mailman.806.1059680707.8231.help-gnu-emacs@gnu.org>
2003-08-01 20:38     ` Kai Großjohann
2003-08-01 21:24     ` Alan Mackenzie
2003-08-06 18:21       ` J Richardson
2003-08-06 20:05         ` J Richardson
2003-08-10 17:35 ` Stefan Monnier
2003-08-12 17:03   ` J Richardson
2003-07-31 16:02 J Richardson

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