1
$ emacs file.html

We have one long line, with no ASCII whitespace to break on.
Before:

weeklyOSM 的想法是蒐集來自世界各地,與 OSM 相關的新聞,處理這些新聞並將其翻譯成盡可能多種語言。這應該有助於讓社群知道所有消息並克服語言障礙。

Do M-q (fill-paragraph), getting:
After:

weeklyOSM 的想法是蒐集來自世界各地,與 OSM 相關的新聞,處理這些新聞並
將其翻譯成盡可能多種語言。這應該有助於讓社群知道所有消息並克服語言障礙。

But I want it to break only after punctuation (, ) or whitespace

So what's the big deal about a newline injected between your Chinese characters?

The newlines become unsightly spaces when the HTML is rendered.

Well then just post-process it to get the newlines back out.

What a hassle.

So how would you like it broken?

weeklyOSM 的想法是蒐集來自世界各地,
與 OSM 相關的新聞,
處理這些新聞並將其翻譯成盡可能多種語言。
這應該有助於讓社群知道所有消息並克服語言障礙。

Well then just substitute newlines after each punctuation, s/,|。/$&\n/g in Perl.

Yes, but M-q will still break my longer stretches.

Well then don't use M-q.

But can't I just set some variable that would allow me to live a normal life, like my ASCII using friends do?

I mean great, some people think it is cool to add newlines (which I say are just as bad as spaces) between Chinese characters. Well how do I opt-out?

2
  • Write a function to do what you want and set fill-paragraph-function to it?
    – NickD
    Commented Oct 27 at 2:10
  • I should change some syntax table, so I wouldn't need to rewrite each and every function that breaks lines. Commented Nov 3 at 0:12

2 Answers 2

1

Don’t use fill-paragraph at all. Just use visual-line-mode instead. This visually wraps the long lines without inserting newline characters in the file. You can customize word-wrap-whitespace-characters to wrap at punctuation as well as whitespace if you need to.

0

Rather than trying to change and/or customize emacs, just go with the flow and indeed run your file through

perl -pwle 's/[;。,】]/$& /g' #etc. wide punctuation characters

and emacs will hopefully break at the spaces you have inserted.

As for long stretches, perhaps find a spot where a wide comma plus space can be inserted.

( https://www.unicode.org/reports/tr14/ but note when breaking in HTML source, the breaks become unsightly spaces when rendered.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.