> Also, the juggle with Org buffer visible/invisible feels fragile. Well,
> it is fragile. I tried with emacs -Q, where the src edit buffer occupies
> half window. It kinda works (unreliably), but when I do C-x 1,
> unexpectedly, no preview appears inside src buffer.
> I suspect that the opposite will be also true - if src edit buffer is
> maximized at the beginning, showing the Org buffer beside, will not make
> the preview move to there.
> And there are also indirect buffers...

> I saw many strange bugs depending on how and when I activated the
> previews and depending whether I edited the fragment or now and
> depending whether previews were present before I switch to src edit
> buffer or not.

I've redesigned the org-src buffer LaTeX preview system.  Here is the
commit message describing the changes:

Commit 624bd45dd95014228943c927c520811949338d67

* lisp/org-latex-preview.el:
(org-latex-preview-live--src-buffer-setup): Simplify preview
generation from org-src buffers and handle many edge cases.

As before, preview updates from org-src buffers only happens when
`org-latex-preview-mode' is on and
`org-latex-preview-display-live' is set appropriately.

- Use `derived-mode-p' instead of checking for latex-mode
- For simplicity, place a preview overlay over the entire contents
  of the org-src buffer.  This makes it possible (and convenient)
  to generate a preview for multiple LaTeX environments.
- If the LaTeX fragment in the Org buffer being edited is not
  being previewed, place a preview overlay over to synchronize
  with the overlay in the org-src buffer.
- Do not simulate `org-latex-preview-mode' in the org-src buffer:
  this has many edge cases because org-element-context is
  not supported in the org-src buffer.
- Instead, ensure that the overlay in the org-src buffer is always
  kept "open" (showing the text) using appropriate hooks
- Switch between showing previews in the org-src buffer and in the
  Org buffer dynamically, depending on whether the Org buffer is
  visible.  Switching between the two kinds of display happens
  when there is a preview update from editing the text.

The code is also simpler than before now.

All of the edge cases we discussed off-list have been addressed, but I
have no doubt that several more exist.  If you find more please document
the steps to reproduce them.

With this I am out of time to work on org-latex-preview.  I'm not sure I
can make any large code changes any more.  I should be able to spend a
little bit of time every evening for further fixes this week, and I'm
still hoping to merge this patchset ASAP.

I think we made considerable progress, and org-latex-preview.el itself
should be almost ready now.

Reply via email to