mattfidler / fold-dwim-org

Org-style folding for dwim-fold
7 stars 2 forks source link

TeX Style strict folding #3

Open mattfidler opened 10 years ago

mattfidler commented 10 years ago

See Issue #1

ThibautVerron commented 10 years ago

It looks like it won't be easy... fold-dwim does define a function fold-dwim-auctex-env-or-macro, which returns whether the point is in a macro or an environment, or neither. So starting from there, we could use it to see if we would be folding an environment, and then looking-at to see if we are at \begin{..} or \end{..}, or LaTeX-find-matching-begin and compare the line numbers.

But when the point is on the first backslash of the \begin, the above function (and TeX-fold-item) then behave as if the point was to be considered out of the environment.

Example (the pipe shows the point):

\begin{equation}
  \|begin{matrix}

  \end{matrix}
\end{equation}

==>

\begin{equation}
  [matrix]
\end{equation}
\begin{equation}
  |\begin{matrix}

  \end{matrix}
\end{equation}

==>

[equation]

I guess this is something which would require a fix from upstream (at least fold-dwim, and probably auctex as well). Or intended behavior for a reason I can't imagine.

Anyway, the current code does fold the outer environment, as showed in the example. With strict folding it would either show the same behavior (if we use looking-at to see if we are on the right line), or not fold at all (if we use LaTeX-find-matching-begin). Would it be an "improvement for most of the cases" or an "introduction of erratic behavior"? :)