Subject: Re: bug#36227: 26.1; sgml-mode indents as comment inside of -- text blocks

From: Noam Postavsky <[email-masked]>
Date: Sat, 15 Jun 2019 19:59:29 -0400

severity 36227 minor
tags 36227 + confirmed
quit

Akkana Peck <[email-masked]> writes:

> In emacs -Q, edit a file in html-mode (derived from sgml-mode),
> e.g. visit /tmp/foo.html.
>
> M-x auto-fill-mode <RET>
>
> Type some nonsense words with ' -- ' in the middle, like this:
>
> asd shdf ladshjkl sjdk -- asdfh jklsdfh
>
> and keep typing until it wraps.
>
> sgml-mode will wrap adding unwanted extra dashes and indentations,
> like this:
>
> asd shdf ladshjkl sjdk -- asdfh jklsdfh jasdklf hjsdkl hjsdaklf sdf --
> 		       -- jkldsfhj kalshfjkasdlfh jaksd

> The problematic behavior seems to come from comment-line-break-function.
> One workaround I've found is to add this in my html-mode and sgml-mode
> hooks to prevent the special processing of line breaks inside comments:
>
>     (kill-local-variable 'comment-line-break-function)
>
> Maybe comment-line-break-function should check sgml-specials and return
> without doing anything if - isn't one of the specials?

It's not to do with the sgml-specials, the problem is that the standard
auto-fill-function, `do-auto-fill', calls `default-indent-new-line'
which calls `comment-line-break-function' regardless of whether point is
inside a comment or not.  As far as I can tell, it works in most modes
because they disable auto-filling outside of comments in the first
place.  sgml-mode doesn't, because most of its non-comment text is just
plain text that should be filled normally.

So I think there should be a sgml-mode specific
comment-line-break-function, which checks whether it's in a comment or
not (presumably using syntax-ppss).