all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* auto-fill mode in java-mode
@ 2003-10-11 22:07 Adam Hardy
  0 siblings, 0 replies; 10+ messages in thread
From: Adam Hardy @ 2003-10-11 22:07 UTC (permalink / raw)


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

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

* Re: auto-fill mode in java-mode
       [not found] <mailman.1541.1065910097.21628.help-gnu-emacs@gnu.org>
@ 2003-10-13  9:10 ` Alan Mackenzie
  2003-10-13 21:58   ` Adam Hardy
       [not found]   ` <mailman.1632.1066082371.21628.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 10+ messages in thread
From: Alan Mackenzie @ 2003-10-13  9:10 UTC (permalink / raw)


Adam Hardy <emacs@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: 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] 10+ messages in thread

* Re: auto-fill mode in java-mode
  2003-10-13  9:10 ` auto-fill mode in java-mode Alan Mackenzie
@ 2003-10-13 21:58   ` Adam Hardy
       [not found]   ` <mailman.1632.1066082371.21628.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 10+ messages in thread
From: Adam Hardy @ 2003-10-13 21:58 UTC (permalink / raw)
  Cc: help-gnu-emacs

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,
Adam

-- 
GNU Emacs 21.3.1 on Linux 2.4.20 RH9

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

* Re: auto-fill mode in java-mode
       [not found]   ` <mailman.1632.1066082371.21628.help-gnu-emacs@gnu.org>
@ 2003-10-16 21:16     ` Alan Mackenzie
  2003-10-17  9:38       ` Adam Hardy
  2003-10-17 14:49       ` Stefan Monnier
  0 siblings, 2 replies; 10+ messages in thread
From: Alan Mackenzie @ 2003-10-16 21:16 UTC (permalink / raw)


Adam Hardy <emacs@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

-- 
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] 10+ messages in thread

* Re: auto-fill mode in java-mode
  2003-10-16 21:16     ` Alan Mackenzie
@ 2003-10-17  9:38       ` Adam Hardy
  2003-10-17 14:49       ` Stefan Monnier
  1 sibling, 0 replies; 10+ messages in thread
From: Adam Hardy @ 2003-10-17  9:38 UTC (permalink / raw)


On 10/16/2003 11:16 PM Alan Mackenzie wrote:
> Adam Hardy <emacs@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.

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!

Adam

-- 
GNU Emacs 21.3.1 on Linux 2.4.20 RH9

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

* Re: auto-fill mode in java-mode
  2003-10-16 21:16     ` Alan Mackenzie
  2003-10-17  9:38       ` Adam Hardy
@ 2003-10-17 14:49       ` Stefan Monnier
  2003-10-18 17:15         ` Adam Hardy
       [not found]         ` <mailman.1944.1066497425.21628.help-gnu-emacs@gnu.org>
  1 sibling, 2 replies; 10+ messages in thread
From: Stefan Monnier @ 2003-10-17 14:49 UTC (permalink / raw)


> 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

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

* Re: auto-fill mode in java-mode
  2003-10-17 14:49       ` Stefan Monnier
@ 2003-10-18 17:15         ` Adam Hardy
       [not found]         ` <mailman.1944.1066497425.21628.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 10+ messages in thread
From: Adam Hardy @ 2003-10-18 17:15 UTC (permalink / raw)


On 10/17/2003 04:49 PM Stefan Monnier wrote:
>>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.

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
Adam

-- 
GNU Emacs 21.3.1 on Linux 2.4.20 RH9

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

* Re: auto-fill mode in java-mode
       [not found]         ` <mailman.1944.1066497425.21628.help-gnu-emacs@gnu.org>
@ 2003-10-18 21:03           ` Johan Bockgård
  2003-10-18 21:23           ` lawrence mitchell
  2003-10-19  9:07           ` Micah Cowan
  2 siblings, 0 replies; 10+ messages in thread
From: Johan Bockgård @ 2003-10-18 21:03 UTC (permalink / raw)


Adam Hardy <emacs@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

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

* Re: auto-fill mode in java-mode
       [not found]         ` <mailman.1944.1066497425.21628.help-gnu-emacs@gnu.org>
  2003-10-18 21:03           ` Johan Bockgård
@ 2003-10-18 21:23           ` lawrence mitchell
  2003-10-19  9:07           ` Micah Cowan
  2 siblings, 0 replies; 10+ messages in thread
From: lawrence mitchell @ 2003-10-18 21:23 UTC (permalink / raw)


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 <wence@gmx.li>

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

* Re: auto-fill mode in java-mode
       [not found]         ` <mailman.1944.1066497425.21628.help-gnu-emacs@gnu.org>
  2003-10-18 21:03           ` Johan Bockgård
  2003-10-18 21:23           ` lawrence mitchell
@ 2003-10-19  9:07           ` Micah Cowan
  2 siblings, 0 replies; 10+ messages in thread
From: Micah Cowan @ 2003-10-19  9:07 UTC (permalink / raw)


Adam Hardy <emacs@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

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

end of thread, other threads:[~2003-10-19  9:07 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.1541.1065910097.21628.help-gnu-emacs@gnu.org>
2003-10-13  9:10 ` auto-fill mode in java-mode Alan Mackenzie
2003-10-13 21:58   ` Adam Hardy
     [not found]   ` <mailman.1632.1066082371.21628.help-gnu-emacs@gnu.org>
2003-10-16 21:16     ` Alan Mackenzie
2003-10-17  9:38       ` Adam Hardy
2003-10-17 14:49       ` Stefan Monnier
2003-10-18 17:15         ` Adam Hardy
     [not found]         ` <mailman.1944.1066497425.21628.help-gnu-emacs@gnu.org>
2003-10-18 21:03           ` Johan Bockgård
2003-10-18 21:23           ` lawrence mitchell
2003-10-19  9:07           ` Micah Cowan
2003-10-11 22:07 Adam Hardy

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.