>>>>> Tassilo Horn <t...@gnu.org> writes:
> Stefan Monnier <monn...@iro.umontreal.ca> writes:
>>> Get your shits together, Stefan,
>> 
>> I'll try to mess up in a more challenging way next time, I promise.

> Challenge accepted. :-)

Well, it seems that we already have a challenge. :-)

I'm now fixing regression tests, and found that preview.el(.in) still
needs adaptation because it uses ad-{enable,disable}-advice explicitly.
Attached is a possible solution. Stefan, is it safe to repeat the same
`advice-add' or `advice-remove'? That is,
1. Do (advice-add FUNC :before #'preview--open-for-replace) once.
2. Do the same (advice-add FUNC :before #'preview--open-for-replace)
   again.
or
1. Do (advice-remove FUNC #'preview--open-for-replace) on a FUNC which
   isn't yet given advice.

Experiments seem to suggest that it's safe. But if not, I have to add
`advice-member-p' test.

Regards,
Ikumi Keita

diff --git a/preview.el.in b/preview.el.in
index c6bc8b7705..d8395935ce 100644
--- a/preview.el.in
+++ b/preview.el.in
@@ -2058,7 +2058,7 @@ overlays not in the active window."
       (push ovr preview-temporary-opened))))
 
 (if (fboundp 'advice-add)               ;Emacs≄24.4 (or ELPA package nadvice)
-    (advice-add 'replace-highlight :before #'preview--open-for-replace)
+    nil ; See the defcustom below.
   (defadvice replace-highlight (before preview)
     (preview--open-for-replace (ad-get-arg 0) (ad-get-arg 1))))
 
@@ -2073,10 +2073,16 @@ overlays not in the active window."
   :require 'preview
   :set (lambda (symbol value)
          (set-default symbol value)
-         (if value
-             (ad-enable-advice 'replace-highlight 'before 'preview)
-           (ad-disable-advice 'replace-highlight 'before 'preview))
-         (ad-activate 'replace-highlight))
+         (if (fboundp 'advice-add) ; COMPATIBILITY for Emacs<24.4
+             (if value
+                 (advice-add 'replace-highlight :before
+                             #'preview--open-for-replace)
+               (advice-remove 'replace-highlight
+                              #'preview--open-for-replace))
+           (if value
+               (ad-enable-advice 'replace-highlight 'before 'preview)
+             (ad-disable-advice 'replace-highlight 'before 'preview))
+           (ad-activate 'replace-highlight)))
   :initialize #'custom-initialize-reset)
 
 (defun preview-relaxed-string= (&rest args)
diff --git a/tests/japanese/preview-latex.el b/tests/japanese/preview-latex.el
index 9b5f395523..14fc3d1ac9 100644
--- a/tests/japanese/preview-latex.el
+++ b/tests/japanese/preview-latex.el
@@ -274,7 +274,7 @@ String encoded in `shift_jis' can have regexp meta characters in it."
       (let* ((buffer (TeX-process-buffer-name (TeX-master-file nil t)))
              (process (get-buffer-process buffer)))
         (if process (delete-process process))
-        (kill-buffer buffer))
+        (if (get-buffer buffer) (kill-buffer buffer)))
       (TeX-clean t)
       (dolist (dir preview-temp-dirs)
         (if (file-exists-p (directory-file-name dir))
diff --git a/tests/latex/font-latex-test.el b/tests/latex/font-latex-test.el
index 7484d03992..5555f748b3 100644
--- a/tests/latex/font-latex-test.el
+++ b/tests/latex/font-latex-test.el
@@ -24,6 +24,8 @@
 (require 'ert)
 (require 'latex)
 (require 'font-latex)
+(defvar font-lock-beg)
+(defvar font-lock-end)
 
 (ert-deftest font-latex-three-dollars ()
   "Test three consecutive dollar is ignored."
@@ -45,8 +47,7 @@ $a$")
   "Test f-l-e-r-b-q doesn't extend region too eagerly."
   (with-temp-buffer
     (let ((TeX-install-font-lock 'font-latex-setup)
-          (font-latex-quotes 'french)
-          font-lock-beg font-lock-end)
+          (font-latex-quotes 'french))
       (LaTeX-mode)
 
       ;; Test 1: Double prime in math expression doesn't cause region
diff --git a/tests/tex/path-expansion.el b/tests/tex/path-expansion.el
index 2246e92ca8..f19c331965 100644
--- a/tests/tex/path-expansion.el
+++ b/tests/tex/path-expansion.el
@@ -25,6 +25,7 @@
 
 (ert-deftest TeX-variable-truncation ()
   "Check whether list variable is not truncated as side effect."
+  (defvar var)
   (let ((var '("str1" "str2"))
         (TeX-kpathsea-path-delimiter nil)
         (TeX-search-files-type-alist

Reply via email to