io12 / org-fragtog

Automatically toggle Org mode LaTeX fragment previews as the cursor enters and exits them
MIT License
397 stars 14 forks source link

Add org-fragtog-preview-delay #14

Closed Yevgnen closed 3 years ago

Yevgnen commented 3 years ago

When cursor is moving very fast across equations in different lines/columns, org-latex-preview is triggered very frequently and instantly. This commit adds a custom variable org-fragtog-preview-delay to allow preview to be shown when Emacs is idle.

io12 commented 3 years ago

Thanks for the PR! This seems like a great idea.

I noticed a few bugs, though. First, since the timer is created inside save-excursion, the timer could trigger when the point is not in the excursion anymore, causing the wrong fragment to be toggled. Second, if the point quickly moves around, entering and leaving the same fragment twice, two timers get created. This causes the preview to be toggled twice, leaving the fragment unchanged.

The first problem can be fixed pretty easily by moving the save-excursion call inside the timer, but the second problem might require a mapping from fragments to timers. I'm not sure what the "key" to the mapping could be, since the user can edit most things about the fragment before the timer triggers.

io12 commented 3 years ago

Closing because of inactivity (sorry). It might be possible to get this working well, but it would probably take lots of complexity to avoid all the edge cases I mentioned in my first comment. Making fragment generation fully async would be cool too, but that's probably outside the scope of org-fragtog.