[TxMt] Reformat ^Q does not account comments and other boundaries

Adam Strzelecki ono at java.pl
Wed Nov 20 11:19:36 UTC 2013


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


More information about the textmate mailing list