Since reformat & reformat+justify are built-ins I can’t really provide decent patch w/o asking prior how we could solve the issue.
Two examples:
(1) Git commit:
I type commit message, than I press ⌃Q on 2nd paragraph.
——————————— before ——————————
Lorem ipsum dolor sit amet
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # On branch master
——————————— after ———————————
Lorem ipsum dolor sit amet
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # On branch master # # Initial commit #
This isn’t really what I would expect. Of course when I put empty line after 2nd paragraph it does work fine. Unfortunately I keep forgetting about that.
(2) Same applies to LaTeX, which is even more frustrating, since empty line in LaTex is actually meaningful.
——————————— before ——————————
\documentclass{article} \begin{document} \title Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. \end{document}
——————————— after ———————————
\documentclass{article} \begin{document} \title Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. \end{document}
——————————— expected ———————————
\documentclass{article} \begin{document} \title Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. \end{document}
Also this applies to following cases when new environment starts before some text block.
——————————— before —————————— long paragraph text % comment ——————————— after ——————————— long paragraph text wrapped % comment
——————————— before —————————— long paragraph text \begin{equation} … ——————————— after ——————————— long paragraph text wrapped \begin{equation} …
So basically reformat should take into account paragraph boundaries of given language (grammar). I’d say it would be just enough if paragraph boundary would be: (1) line with commend (2) ending or starting of fold scope
WDYT?
— Adam
On 20 Nov 2013, at 18:19, Adam Strzelecki wrote:
[…] So basically reformat should take into account paragraph boundaries of given language (grammar). I’d say it would be just enough if paragraph boundary would be: (1) line with commend (2) ending or starting of fold scope
Another example is quoted text (in emails / markdown).
If you use ⌃⌘T with key equivalent search for all scopes you can see we overload ⌃Q for a few, though only quoted text in emails is really a case where the command is semantically doing the same action (AFAIK).
It does sound like a way to make the built-in code adaptable to handle more non-prose cases would be to introduce a prefix character setting (possibly regexp).
I’m not sure if it should always be a paragraph separator versus a prefix character that gets stripped before doing the reflow, and then added after the reflow, with lines that have different prefixes considered different paragraphs, and thus would also act as separators, since it should only reflow a single paragraph at a time. This should allow reflowing comments and quoted text (when caret is on a line with such, while pressing ⌃Q).
Btw: The built-in code already has some logic to deal with bulleted list items (iirc).