Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

auto-fill mode in java-mode

3 views
Skip to first unread message

Adam Hardy

unread,
Oct 11, 2003, 6:07:00 PM10/11/03
to help-gn...@gnu.org
I'm trying to get my java-mode to wrap lines at 75 cols and I've not got
it working. I'm pretty sure that my java-mode settings, which sets it up
just how I want it except the wrapping, must be inhibiting auto-fill,
but I can't see how. This is my java-mode lisp in .emacs:

(add-hook 'java-mode-hook
'(lambda ()
;; Konfiguration des Javamodes
(c-set-style '"Java")
(setq c-basic-offset 4)
(c-set-offset 'topmost-intro-cont c-basic-offset)
(c-set-offset 'inline-open 0)
(c-set-offset 'inclass 4)
(c-set-offset 'substatement-open 0)
(c-set-offset 'block-open '-)
(c-set-offset 'objc-method-intro 'c-lineup-arglist-intro-after-paren)
;; Konfiguration verschiedener Features
(setq c-electric-pound-behavior '(alignleft))
;; allgemeine Konfiguration
(set-variable 'comment-column 40)
;; Konfiguration der Funktionalitaet der Returntaste
(local-set-key [return] 'newline-and-indent)
(local-set-key [S-return] 'newline)
(local-set-key [C-return] 'c-mark-function)))

;; Turn on auto-fill-mode in desired modes
(setq-default fill-column 75)
(add-hook 'java-mode-hook 'turn-on-auto-fill)

Thanks for any help.

Adam

--
GNU Emacs 21.3.1 on Linux 2.4.20 RH9

Alan Mackenzie

unread,
Oct 13, 2003, 5:10:53 AM10/13/03
to
Adam Hardy <em...@cyberspaceroad.com> wrote on Sun, 12 Oct 2003 00:07:00
+0200:

> I'm trying to get my java-mode to wrap lines at 75 cols and I've not
> got it working.

What do you mean by "lines"? In the CC Modes, only comments get
auto-filled by default. Are your comment lines getting auto-filled? Do
you also want code lines to get auto-filled?

If you want lines of code to get filled too, set the user option
c-ignore-auto-fill. For example, in your mode hook add something like

(setq c-ignore-auto-fill '(cpp))

which will fill everything but preprocessor lines (do such exist in
Java?). c-ignore-auto-fill is fully documented on the page "Text Filling
and Line Breaking" in the CC Mode info pages.

I'm not sure how useful the auto-filling is in lines other than comment
lines.

[ .... ]

> Thanks for any help.

Best of luck! Come back again if the above doesn't help.

> Adam

> --
> GNU Emacs 21.3.1 on Linux 2.4.20 RH9

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

Adam Hardy

unread,
Oct 13, 2003, 5:58:08 PM10/13/03
to Alan Mackenzie, help-gn...@gnu.org
On 10/13/2003 11:10 AM Alan Mackenzie wrote:
>>I'm trying to get my java-mode to wrap lines at 75 cols and I've not
>>got it working.
>
> What do you mean by "lines"? In the CC Modes, only comments get
> auto-filled by default. Are your comment lines getting auto-filled? Do
> you also want code lines to get auto-filled?

Yes they are and yes I do :)

>
> If you want lines of code to get filled too, set the user option
> c-ignore-auto-fill. For example, in your mode hook add something like
>
> (setq c-ignore-auto-fill '(cpp))
>
> which will fill everything but preprocessor lines (do such exist in
> Java?). c-ignore-auto-fill is fully documented on the page "Text Filling
> and Line Breaking" in the CC Mode info pages.
>
> I'm not sure how useful the auto-filling is in lines other than comment
> lines.

That is very useful, thanks. And after reading the docs you pointed me
at, I installed filladapt-mode as well, which makes it even better.

Essentially I want to restrict the width so I can just cut & paste my
code into emails without the email mangling it.

It does sometimes break the line in surprising places, but that's not an
issue.

There is only one quibble that I have with the arrangement as I now have
it, and the cc-mode help, which is great, is not telling me how or why
it happens:

- when auto-fill breaks a line, it ignores my idea of what the
indentation should be. I have to hit tab (or an electric key) for the
indentation to sort itself out. I assume my settings are in need of some
adjustment, but I don't know which of the following it is:

(c-set-offset 'topmost-intro-cont c-basic-offset)
(c-set-offset 'inline-open 0)
(c-set-offset 'inclass 4)
(c-set-offset 'substatement-open 0)
(c-set-offset 'block-open '-)
(c-set-offset 'objc-method-intro 'c-lineup-arglist-intro-after-paren)

(setq c-electric-pound-behavior '(alignleft))
(local-set-key [return] 'newline-and-indent)


Thanks again,

Alan Mackenzie

unread,
Oct 16, 2003, 5:16:58 PM10/16/03
to
Adam Hardy <em...@cyberspaceroad.com> wrote on Mon, 13 Oct 2003 23:58:08
+0200:

> On 10/13/2003 11:10 AM Alan Mackenzie wrote:
>>>I'm trying to get my java-mode to wrap lines at 75 cols and I've not
>>>got it working.

[ .... ]

>> I'm not sure how useful the auto-filling is in lines other than
>> comment lines.

[ .... ]

> There is only one quibble that I have with the arrangement as I now
> have it, and the cc-mode help, which is great, is not telling me how or
> why it happens:

> - when auto-fill breaks a line, it ignores my idea of what the
> indentation should be. I have to hit tab (or an electric key) for the
> indentation to sort itself out. I assume my settings are in need of
> some adjustment, but I don't know which of the following it is:

[ settings snipped ]

I don't think there's any code in CC Mode to re-indent auto-filled stuff
(apart from comments). It's one of these things that "nobody" will ever
really need (Hah!), and nobody can be bothered to code. The variable
c-ignore-auto-fill seems more like an emergency kludge than a fully
worked out facility.

If you think about it, auto-fill with reindentation would be complicated -
The Java code could be filled, then reindented, causing it to spill over
the right margin, requiring re-filling, then reindentation, ..... It
would probably end up looking like an Outlook-Express Usenet posting. :-(

You could always reindent the code with C-M-\ or C-M-q or something. But
that will ruin the 75 column limit. :-( There probably isn't a good
solution to this (other than to enhance CC Mode). Sorry.

> Adam

Adam Hardy

unread,
Oct 17, 2003, 5:38:40 AM10/17/03
to help-gn...@gnu.org

That's what I'm doing now - it's only 1 key-press. I can definitely live
with it though.

Interesting to see you are based in Munich. I am too.

I would have posted off-list but your email address doesn't show.

Thanks for the help!

Stefan Monnier

unread,
Oct 17, 2003, 10:49:50 AM10/17/03
to
> If you think about it, auto-fill with reindentation would be complicated -
> The Java code could be filled, then reindented, causing it to spill over
> the right margin, requiring re-filling, then reindentation, ..... It
> would probably end up looking like an Outlook-Express Usenet posting. :-(

It's not that bad: you only re-indent the second line, so there is no
circularity and things end just fine. If it doesn't work, it's only
because nobody coded it up or because there's a bug.


Stefan

Adam Hardy

unread,
Oct 18, 2003, 1:15:41 PM10/18/03
to Stefan Monnier, help-gn...@gnu.org

The indentation works if you want the line to rewrap to the point where
the line above starts, but in java that's rarely the case.

As someone in the thread said earlier, auto-filling java code is a
pretty unusual thing to want to do.

Although it is true that auto-fill will break and wrap my line of java,
and not indent the new line to where it should be, this is in fact a
minor issue since I mostly want to choose where in the original line the
line-break should go, manually, but auto-fill automatically takes the
previous white space.

I realise now that my issue here is that it would actually be preferable
to have emacs just stop taking input beyond line 72 - and beep instead.
Or perhaps color the text red, because I can imagine situations where I
can't break the line.

Is anything like that possible?

Actually is 72 the standard email line length? As I said earlier, my
requirement is to have all the code easily emailable without being
rewrapped by the email software.

Cheers

Johan Bockgård

unread,
Oct 18, 2003, 5:03:22 PM10/18/03
to
Adam Hardy <em...@cyberspaceroad.com> writes:

> I realise now that my issue here is that it would actually be
> preferable to have emacs just stop taking input beyond line 72 - and
> beep instead. Or perhaps color the text red, because I can imagine
> situations where I can't break the line.

You could try one of

wide-column.el --- Calls functions dependant on column position.
highlight-beyond-fill-column.el --- font-lock-add-keywords aid for Emacs
vvb-mode.el --- a minor mode to display a Visible Vertical Bar on a column
line-limit.el --- Line Limit mode

--
Johan Bockgård

lawrence mitchell

unread,
Oct 18, 2003, 5:23:49 PM10/18/03
to
Adam Hardy wrote:

[...]

> I realise now that my issue here is that it would actually be
> preferable to have emacs just stop taking input beyond line 72 - and
> beep instead. Or perhaps color the text red, because I can imagine
> situations where I can't break the line.

How about:

(defun my-dont-insert-after-fill-column (&rest x)
(when (> (current-column)
fill-column)
(delete-char -1)
(beep)))

(add-hook 'after-change-functions 'my-dont-insert-after-fill-column)

> Is anything like that possible?

[...]

--
lawrence mitchell <we...@gmx.li>

Micah Cowan

unread,
Oct 19, 2003, 5:07:31 AM10/19/03
to
Adam Hardy <em...@cyberspaceroad.com> writes:

> Actually is 72 the standard email line length? As I said earlier,
> my requirement is to have all the code easily emailable without
> being rewrapped by the email software.

RFC 822, which defines the format of email messages (or did until
it was replaced by RFC 2822), notes that "long lines" is commonly
understood to be lines that are "greater than 65 or 72
characters." RFC 2822 says that a line "SHOULD be no more than
78 characters, excluding the CRLF." RFC 1855, "Netiquette
Guidelines", Section 2.1.1 ("For mail") requests that line length
be limited to "fewer than 65 characters."

Keeping line length under 65 also allows several levels of
quoting prefixes before overflow becomes a danger; for this
reason, I keep my fill-column set to 65.

-Micah

0 new messages