From 00a9d74ad1da8a2e3b4a8519f66d1488af306fd5 Mon Sep 17 00:00:00 2001
From: Tobias Zawada
Date: Thu, 2 May 2019 01:30:13 +0200
Subject: [PATCH] Addresses #10. Left-over for #10. There were still multiple
runs of texfrag-region for derived major modes.
---
test/README_TEST.org | 66 ++++++++++++++++++++++----------------------
texfrag.el | 26 ++++++++++++-----
2 files changed, 52 insertions(+), 40 deletions(-)
diff --git a/test/README_TEST.org b/test/README_TEST.org
index 46c5b75..a68741a 100644
--- a/test/README_TEST.org
+++ b/test/README_TEST.org
@@ -140,39 +140,39 @@ b(x) = (x_{i+d}-x_i)\cdot [x_i,\ldots,x_{i+d}]_y (y-x)^d_+
Second html document for testing with eww:
#+BEGIN_SRC html :tangle /tmp/test1.html :results silent
-
-
-
- Second texfrag html test for eww
-
-
- Second texfrag html test for eww
-
- MathJax test.
-
- - Testing parenthesis fragments: The theorem of Pythagoras: \(\def\di{\operatorname{d}}\def\ph{\varphi}\def\I{\operatorname{i}}Z=\sqrt{X^2 + Y^2}\).
- - Testing dollar fragments: Einstein's formula of the photo-voltaic process: $E\;=\;h\cdot f$
- - Testing bracket fragments: B-spline basis function
- \[
- b(\xi) = (x_{i+d}-x_i)\cdot [x_i,\ldots,x_{i+d}]_y (y-\xi)^d_+
- \]
-
- - Testing LaTeX environments: Cauchy's integral formula
- \begin{align*}
- \frac1{2\pi\I}\oint_C \frac{f(Z)}{Z-z_0}\di Z &= \lim_{r\downarrow0} \frac1{2\pi\I}\int_{\ph=0}^{2\pi} \frac{f(z_0+r\exp(\I\ph))}{r\exp(\I\ph)}r\exp(\I\ph) \I\di \ph\\
- &= f(z)
- \end{align*}
-
-
-
-
+
+
+
+ Second texfrag html test for eww
+
+
+ Second texfrag html test for eww
+
+ MathJax test.
+
+ - Testing parenthesis fragments: The theorem of Pythagoras: \(\def\di{\operatorname{d}}\def\ph{\varphi}\def\I{\operatorname{i}}Z=\sqrt{X^2 + Y^2}\).
+ - Testing dollar fragments: Einstein's formula of the photo-voltaic process: $E\;=\;h\cdot f$
+ - Testing bracket fragments: B-spline basis function
+ \[
+ b(\xi) = (x_{i+d}-x_i)\cdot [x_i,\ldots,x_{i+d}]_y (y-\xi)^d_+
+ \]
+
+ - Testing LaTeX environments: Cauchy's integral formula
+ \begin{align*}
+ \frac1{2\pi\I}\oint_C \frac{f(Z)}{Z-z_0}\di Z &= \lim_{r\downarrow0} \frac1{2\pi\I}\int_{\ph=0}^{2\pi} \frac{f(z_0+r\exp(\I\ph))}{r\exp(\I\ph)}r\exp(\I\ph) \I\di \ph\\
+ &= f(z)
+ \end{align*}
+
+
+
+
#+END_SRC
diff --git a/texfrag.el b/texfrag.el
index b88ef75..9453ef7 100644
--- a/texfrag.el
+++ b/texfrag.el
@@ -187,6 +187,14 @@ This can be a file name or a sexp that generates the file name."
(list :tag "Generator function" :inline t (const :generator) (function identity)))))
"Customization type for `texfrag-frag-alist'.")
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(defvar-local texfrag-preview-buffer-at-start-done nil
+ "Set to t if `texfrag-region' is run in function `texfrag-mode'.
+Protection against repeated execution of `texfrag-region'
+through function `texfrag-mode' with non-nil `texfrag-preview-buffer-at-start'
+in the case of derived modes.")
+
(define-widget 'texfrag-regexp 'string
"A regular expression."
:match 'texfrag-widget-regexp-match
@@ -442,7 +450,7 @@ for further details about the argument and the return value."
(cMatches (texfrag-combine-match-data bStr bMatches eStr eMatches))
)
(unless eOuter
- (user-error "LaTeX fragment beginning at %s with %s not closed." bOuter bStr)) ;; Changed %d for bOuter to %s to handle case bOuter==nil.
+ (user-error "LaTeX fragment beginning at %s with %s in buffer %s not closed" bOuter bStr (current-buffer))) ;; Changed %d for bOuter to %s to handle case bOuter==nil.
(set-match-data cMatches)
(list bOuter eOuter
(concat (replace-match (nth 2 matchList) nil nil cStr)
@@ -470,7 +478,7 @@ for further details about the argument and the return value."
(cStr (concat bStr eStr))
)
(unless bOuter
- (user-error "LaTeX fragment ending at %d with %s has no start string." bOuter eStr))
+ (user-error "LaTeX fragment ending at %d with %s has no start string" bOuter eStr))
(set-match-data cMatches)
(list bOuter eOuter
(concat (replace-match (nth 2 matchList) nil nil cStr)
@@ -662,7 +670,7 @@ This variable is the link back from the LaTeX-buffer to the source buffer.")
(declare (debug body))
`(progn
(unless (buffer-live-p texfrag-source-buffer)
- (user-error "TeXfrag source buffer %S not ready in LaTeX target buffer %S." texfrag-source-buffer (current-buffer)))
+ (user-error "TeXfrag source buffer %S not ready in LaTeX target buffer %S" texfrag-source-buffer (current-buffer)))
(with-current-buffer texfrag-source-buffer
,@body)))
@@ -671,7 +679,7 @@ This variable is the link back from the LaTeX-buffer to the source buffer.")
(declare (debug body))
`(progn
(unless (buffer-live-p texfrag-tex-buffer)
- (user-error "TeXfrag LaTeX buffer %S not ready in LaTeX target buffer %S." texfrag-tex-buffer (current-buffer)))
+ (user-error "TeXfrag LaTeX buffer %S not ready in LaTeX target buffer %S" texfrag-tex-buffer (current-buffer)))
(with-current-buffer texfrag-tex-buffer
,@body)))
@@ -764,7 +772,7 @@ or the string itself."
(defun texfrag-generator-place-preview (ov img _box &optional _counters _tempdir &rest _place-opts)
"Call me like `preview-gs-place'.
-Return OV after setting 'preview-image to a cons (img . img)
+Return OV after setting 'preview-image to a cons (IMG . IMG)
assuming that img is already an image."
(when (stringp img)
(setq img (expand-file-name img))
@@ -999,11 +1007,15 @@ Example:
(define-key texfrag-mode-map texfrag-prefix texfrag-submap)
(LaTeX-preview-setup)
(preview-mode-setup)
- (when texfrag-preview-buffer-at-start
- (preview-buffer))
+ (when (and texfrag-preview-buffer-at-start
+ ;; Protect against multiple activation in derived major modes:
+ (null texfrag-preview-buffer-at-start-done))
+ (preview-buffer)
+ (setq texfrag-preview-buffer-at-start-done t))
(add-hook 'kill-buffer-hook #'texfrag-cleanup nil t)
(add-hook 'change-major-mode-hook #'texfrag-cleanup nil t))
(texfrag-cleanup)
+ (setq texfrag-preview-buffer-at-start-done nil)
(remove-hook 'kill-buffer-hook #'texfrag-cleanup t)
(remove-hook 'change-major-mode-hook #'texfrag-cleanup t)
(preview-clearout-document)))