# [ESS] ess-noweb-font-lock-mode: emacs hangs using uncomment-region with math environments

Braun, Michael br@unm @ending from m@il@@mu@edu
Mon Jan 7 04:50:25 CET 2019

In a .Rnw file, when calling uncomment-region on a region that contains a LaTeX math environment (such as align), Emacs will hang, requiring a Force Quit.  I am using Aquamacs Emacs 3.5, ESS 18.10.2, and MacOS 10.14.2, but this problem has persisted since at least Aquamacs 3.2 and ESS 16.10.   I’ve been wrestling with this issue since at least 2016, but now it’s time to get some help.

To replicate, save the following content in a file with a .Rnw extension. Then, select a region that includes the equation, and run comment-region, and then uncomment-region.  I have these functions are bound to M-; or C-c ; .

------
\documentclass{article}
\usepackage{amsmath}

\begin{document}

On the following equation, try comment-region, and then uncomment-region.
The uncomment-region call is what hangs the process.

\begin{align}
1+1=2
\end{align}

\end{document}
-------

My longstanding workaround is to either toggle ess-noweb-font-lock-mode off, or toggle font-lock-mode on, right after opening the file.  This makes the problem with uncomment-region disappear. But then I lose the ESS font-lock features.

Interestingly, this does not crash Emacs  if the file is saved with a .tex extension.  Also, in a .tex file, comment-region prefixes lines with %, but in a .Rnw file, the comment prefix is %%. I’m not sure if that’s relevant, but it might be, and I’d like to find a way to change that behavior as well.

Any thoughts?

Thanks,

Michael Braun
braunm _at_ smu.edu