9

markdown-mode is pretty good at filling paragraphs overall, but there's one flaw that really bothers me. If a paragraph contains a line which ends in two spaces, it only starts filling never fills that line.

For instance, take the following example, where the second line ends in two spaces.

If I hit M-q right here at the start, this line will get broken into two, but the others won't.
If I hit M-q right here only the NEXT line will get split. All because this line here ends in two spaces.__
If I hit M-q right here, this line will get broken into two, but the others won't.

The example explains itself. Even If I hit M-q at the start of each line, I'm still left with this:

If I hit M-q right here at the start this line will get broken into
two, but the others won't.
If I hit M-q right here only the NEXT line will get split. All because this line here ends in two spaces.__
If I hit M-q right here, this line will get broken into two, but the
others won't.

What I would like to have is this:

If I hit M-q right here at the start this line will get broken into
two, but the others won't. If I hit M-q right here only the NEXT line
will get split. All because this line here ends in two spaces.__
If I hit M-q right here, this line will get broken into two, but the
others won't.

Q: How can I get fill-paragraph to behave like this?

Clearly, markdown-mode is considering the entire middle line to be a paragraph separator, when it should be just the spaces at the end.

Malabarba
  • 22,878
  • 6
  • 78
  • 163

1 Answers1

1

So one inelegant hammer of a solution for this is to set paragraph-separate as a file-local variable. The mode sets it to "\\(?:[ \t\f]\\|.* \\)*$" as a mode-local-variable; if I set it back to its default value (taken from the help string for paragraph-separate) like so:

-*- mode: markdown; paragraph-separate: "[  ^L]*$" -*-

then I get the behaviour you're searching for:

If I hit M-q right here at the start, this line will get broken into
two, but the others won't.  If I hit M-q right here only the NEXT line
will get split. All because this line here ends in two spaces.__If I
hit M-q right here, this line will get broken into two, but the others
won't.

The comment in the git repo that introduces this says:

Respect hard line breaks when filling paragraphs

A downside of this patch is that paragraph movement commands will also stop at hard line breaks, thus slightly changing the definition of "paragraph" in this mode.

After a lot of tracing, I think I've got the function actually invoked by M-q down to fill-individual-paragraphs; but it's complicated, and even after looking at that comment I still haven't figured out exactly what's going on...thus, blunt hammer, and I don't know what other consequences it'll have. But it seems to work. :-)

itsjeyd
  • 14,586
  • 3
  • 58
  • 87
  • Thanks. Unfortunately, this not get the behaviour I'm looking for. I correctly fills the first 2 lines, but the 3 line is filled incorrectly. Note the slight difference between the paragraph you have here and the "desired outcome" in the question. The third line get's pulled into the jumble, which changes the actual way the paragraph is rendered by markdown. That's undesirable. The third line should remain a line of its own. I suspect this is a limitation of Emacs' fill-paragraph logic, and can only be fixed with a dedicated function. – Malabarba Dec 01 '14 at 10:27
  • Arghh, I missed that! :-( – Saint Aardvark the Carpeted Dec 01 '14 at 14:31