From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: bug#22472: 25.0.50; org-mode: latex fragments can't be un-rendered after a revert Date: Thu, 04 Feb 2016 09:35:13 +0100 Message-ID: <87zivgoou6.fsf@nicolasgoaziou.fr> References: <874mdz9th5.fsf@secretsauce.net> <87oabyuwbf.fsf@free.fr> <87powd2usq.fsf@secretsauce.net> <87mvrh2qbf.fsf@secretsauce.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:35532) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRFMb-0002Uc-OA for emacs-orgmode@gnu.org; Thu, 04 Feb 2016 03:34:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aRFMY-0008C9-Gt for emacs-orgmode@gnu.org; Thu, 04 Feb 2016 03:34:05 -0500 Received: from debbugs.gnu.org ([208.118.235.43]:50310) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRFMY-0008C5-Db for emacs-orgmode@gnu.org; Thu, 04 Feb 2016 03:34:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84) (envelope-from ) id 1aRFMY-0005XH-4V for emacs-orgmode@gnu.org; Thu, 04 Feb 2016 03:34:02 -0500 Sender: "Debbugs-submit" Resent-Message-ID: In-Reply-To: <87mvrh2qbf.fsf@secretsauce.net> (Dima Kogan's message of "Wed, 03 Feb 2016 17:54:12 -0800") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Dima Kogan Cc: Bastien Guerry , 22472@debbugs.gnu.org --=-=-= Content-Type: text/plain Hello, Dima Kogan writes: > Dima Kogan writes: > >> So a revert puts emacs into an inconsistent state, where the equation is >> rendered, but the source may or may not be there anymore, and where org >> doesn't think there's a render there at all. > > This looks like an issue in emacs, rather than org. I think the right > solution is for a revert to delete all overlays. I.e.: > > (add-hook 'before-revert-hook 'delete-all-overlays) > > This generally works, but is unideal because: > > > 1. We'd want this to apply to org buffers, not to all emacs buffers > > 2. This works only if revert-buffer-function is nil or > revert-buffer--default. > > > If we don't want to delete overlays on revert, then > org-latex-fragment-image-overlays must be properly set to reflect the > overlay state, AND emacs should make sure the overlay is still valid on > revert. > > Any particular thoughts? Would the following patch (applied on maint) solve the problem? Regards, -- Nicolas Goaziou --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Remove-LaTeX-overlay-when-text-below-is-modified.patch >From eb1de6c2bcd02593a4a704f805faa9020f5fdddb Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Thu, 4 Feb 2016 09:32:51 +0100 Subject: [PATCH] Remove LaTeX overlay when text below is modified * lisp/org.el (org--format-latex-make-overlay): New function. (org-format-latex): Use new function. Reported-by: Dima Kogan --- lisp/org.el | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index fd08292..a48ae70 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -19079,6 +19079,27 @@ for all fragments in the buffer." (set-window-start nil window-start) (message (concat msg "done"))))))) +(defun org--format-latex-make-overlay (beg end image) + "Build an overlay between BEG and END using IMAGE file. +Register new overlay in `org-latex-fragment-image-overlays'." + (let ((ov (make-overlay beg end))) + (overlay-put ov 'org-overlay-type 'org-latex-overlay) + (overlay-put ov 'evaporate t) + (overlay-put ov + 'modification-hooks + (list (lambda (o flag beg end &optional l) + (unless flag + (org-remove-latex-fragment-image-overlays + (overlay-start o) (overlay-end o)))))) + (if (featurep 'xemacs) + (progn + (overlay-put ov 'invisible t) + (overlay-put ov 'end-glyph (make-glyph (vector 'png :file image)))) + (overlay-put ov + 'display + (list 'image :type 'png :file image :ascent 'center))) + (push ov org-latex-fragment-image-overlays))) + (defun org-format-latex (prefix &optional dir overlays msg forbuffer processing-type) "Replace LaTeX fragments with links to an image, and produce images. @@ -19170,25 +19191,7 @@ Some of the options can be changed using the variable (when (eq (overlay-get o 'org-overlay-type) 'org-latex-overlay) (delete-overlay o))) - (let ((ov (make-overlay beg end))) - (overlay-put ov - 'org-overlay-type - 'org-latex-overlay) - (overlay-put ov 'evaporate t) - (if (featurep 'xemacs) - (progn - (overlay-put ov 'invisible t) - (overlay-put - ov 'end-glyph - (make-glyph - (vector 'png :file movefile)))) - (overlay-put - ov 'display - (list 'image - :type 'png - :file movefile - :ascent 'center))) - (push ov org-latex-fragment-image-overlays)) + (org--format-latex-make-overlay beg end movefile) (goto-char end)) (delete-region beg end) (insert -- 2.6.3 --=-=-=--