Search code examples
emacsautofillauctex

AUCTeX: custom ‘fill-nobreak-predicate’ hook to respect braces


I use the following C-ish indentation/bracing style when writing LaTeX code:

\foo{
  blah blah... this line is getting too long and should be wrapped
}

whenever I need to re-wrap (technically, refill) a block/paragraph, according to fill-column option (50 in this example), I hit M-q. That also changes the braces' position:

\foo{ blah blah blah... this line is getting too
  long and should be wrapped }

which hurts my eyes :-( Indeed I'd like to keep the braces in their original position, namely:

\foo{ 
  blah blah blah... this line is getting too
  long and should be wrapped 
}

I guess I should add a custom fill-nobreak-predicate hook for AUCTeX, or customize paragraph-start and paragraph-separate, but I'm not that skilled with emacs lisp...

Since this question might apply to any markup-text-mode, fill free to move it upstream.


Solution

  • With @Stefan suggestion., I come up with this, Seems working well, for simple tests,

    (add-hook 'LaTeX-mode-hook
              '(lambda ()
                (setq paragraph-separate (concat " *}\\|^ *\\\\[a-zA-Z]* ?{\\|"
                                                  paragraph-separate))))