Subject: Re: bug#23180: 2016-01-31; Auto-capitalize and change env

From: Mosè Giordano <[email-masked]>
Date: Fri, 1 Apr 2016 17:30:26 +0200

2016-04-01 15:17 GMT+02:00 Uwe Brauer <[email-masked]>:
>
>     > 2016-04-01 14:27 GMT+02:00 Uwe Brauer <[email-masked]>:
>
>     > Still can't reproduce, and I think there is an error in your recipe.
>     > I guess you start from
>
>     > \begin{equation}
>     >   A_i
>     > \end{equation}
>
>     > move anywhere inside the environment, issue C-u C-c C-e "align" RET and get
>
>     > \begin{equation}
>     >   A_i
>     > \end{align}
>
>     > Is it correct?  Then I can't reproduce, I get
>
> More or less. The begin document is changed as well. I just repeated the
> steps.
>
> First the recipe.
>
>   emacs -Q
>   load auc-init.el
>   load my-auto.el
>   load $HOME/.emacs.d/elpa/auto-capitalize-20131013.2205/auto-capitalize.el
>
> Open a Latex file
>
>
> \documentclass[11pt]{article}
> \begin{document}
>
>
> \begin{equation}
>  A_i a_{I}i
> \end{equation}
> \end{document}
>
> move anywhere inside the environment, issue C-u C-c C-e "align" RET and
> get
>
> And I obtain
> \documentclass[11pt]{article}
> \begin{align}
>
>
> \begin{equation}
>  A_i a_{I}i
> \end{align}
>
> \end{document}
>

Ok, thanks, now I can reproduce it but can't find the real culprit.
The problem is that after `replace-match' point is left after
"\begin", instead of after "\end{align".  I can't understand what
moves point.  Apparently point is moved after `after-change-functions'
hook is run.  In a LaTeX buffer its value is (auto-capitalize
jit-lock-after-change t), but neither `auto-capitalize' nor
`jit-lock-after-change' moves point.  I really don't know what is
causing point to be moved after the change.

I can't reproduce the bug with other major modes (I tested
fundamental-mode and text-mode).  I can't reproduce it with other
values of `auto-capitalize-predicate' , like both (lambda () t) or
(lambda () nil), so I thought `texmathp' is involved but it doesn't move point.

Here are the smallest recipe to reproduce the bug once auto-capitalize
and AUCTeX have been loaded and the file you provided has been
visited:

--8<---------------cut here---------------start------------->8---
(goto-char (point-max))
(re-search-backward "equation")
(replace-match "foo")
--8<---------------cut here---------------end--------------->8---

As I said, point after `replace-match' isn't where it should be.

Does someone have an idea of what happens after
`after-change-functions' hook is run?  Help is welcome!

Bye,
Mosè

PS: regarding the specific problem you're reporting we can work around
it by wrapping a `save-excursion' around `replace-match', but I'd
prefer to find what really triggers the bug and then decide what to
do.