help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Ert batch-mode error


From: Stefan Monnier
Subject: Re: Ert batch-mode error
Date: Mon, 06 Apr 2020 23:50:09 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> This macro tries calls font-lock-fontity-region, perhaps the problem
> is that font-lock mode doesn't activate in batch mode (although it's
> not clear to me why your should depend on font-lock). I wrote
> yas--with-font-locked-temp-buffer for some yasnippet tests to deal
> with similar problems.
>
> https://github.com/joaotavora/yasnippet/blob/0.14.0/yasnippet-tests.el#L856-L874

Yuck!  This should use `font-lock-ensure` which *should* work in this
case (if it doesn't, please file a bug report; it's been introduced in
large part to solve these kinds of use cases).

But looking at yasnippet-tests.el, I'm not sure what's going on:
the only case where font-lock seems to be relevant is
`do-yas-org-native-tab-in-source-block` (and it already uses
`font-lock-ensure` when available).  So (barring compatibility with
Emacs<24 for which you still need the non-font-lock-ensure version),
would the patch below still perform the tests correctly?


        Stefan


diff --git a/packages/yasnippet/yasnippet-tests.el 
b/packages/yasnippet/yasnippet-tests.el
index f7ca2bb41..5d64085c6 100644
--- a/packages/yasnippet/yasnippet-tests.el
+++ b/packages/yasnippet/yasnippet-tests.el
@@ -2,7 +2,7 @@
 
 ;; Copyright (C) 2012-2015, 2017-2018  Free Software Foundation, Inc.
 
-;; Author: Joo Tvora <joaot@siscog.pt>
+;; Author: João Távora <joaot@siscog.pt>
 ;; Keywords: emulations, convenience
 
 ;; This program is free software; you can redistribute it and/or modify
@@ -853,28 +853,8 @@ mapconcat #'(lambda (arg)
     (yas-expand-snippet "\\`\\`\\`foo\n\n\\`\\`\\`")
     (should (equal (buffer-string) "```foo\n\n```"))))
 
-(defmacro yas--with-font-locked-temp-buffer (&rest body)
-  "Like `with-temp-buffer', but ensure `font-lock-mode'."
-  (declare (indent 0) (debug t))
-  (let ((temp-buffer (make-symbol "temp-buffer")))
-    ;; NOTE: buffer name must not start with a space, otherwise
-    ;; `font-lock-mode' doesn't turn on.
-    `(let ((,temp-buffer (generate-new-buffer "*yas-temp*")))
-       (with-current-buffer ,temp-buffer
-         ;; pretend we're interactive so `font-lock-mode' turns on
-         (let ((noninteractive nil)
-               ;; turn on font locking after major mode change
-               (change-major-mode-after-body-hook #'font-lock-mode))
-           (unwind-protect
-               (progn (require 'font-lock)
-                      ;; turn on font locking before major mode change
-                      (font-lock-mode +1)
-                      ,@body)
-             (and (buffer-name ,temp-buffer)
-                  (kill-buffer ,temp-buffer))))))))
-
 (ert-deftest example-for-issue-474 ()
-  (yas--with-font-locked-temp-buffer
+  (with-temp-buffer
     (c-mode)
     (yas-minor-mode 1)
     (insert "#include <foo>\n")
@@ -882,7 +862,7 @@ mapconcat #'(lambda (arg)
     (should (string= (yas--buffer-contents) "#include <foo>\nTODO: "))))
 
 (ert-deftest example-for-issue-404 ()
-  (yas--with-font-locked-temp-buffer
+  (with-temp-buffer
     (c++-mode)
     (yas-minor-mode 1)
     (insert "#include <foo>\n")
@@ -890,7 +870,7 @@ mapconcat #'(lambda (arg)
     (should (string= (yas--buffer-contents) "#include <foo>\nmain"))))
 
 (ert-deftest example-for-issue-404-c-mode ()
-  (yas--with-font-locked-temp-buffer
+  (with-temp-buffer
     (c-mode)
     (yas-minor-mode 1)
     (insert "#include <foo>\n")
@@ -1686,14 +1666,12 @@ TODO: be meaner"
           ;; `org-src-tab-acts-natively' to have effect.
           (org-src-fontify-natively t))
       (yas-reload-all)
-      ;; Org relies on font-lock to identify source blocks.
-      (yas--with-font-locked-temp-buffer
+      (with-temp-buffer
        (org-mode)
        (yas-minor-mode 1)
        (insert "#+BEGIN_SRC " mode "\nT\n#+END_SRC")
-       (if (fboundp 'font-lock-ensure)
-           (font-lock-ensure)
-         (jit-lock-fontify-now))
+       ;; Org relies on font-lock to identify source blocks.
+       (font-lock-ensure)
        (re-search-backward "^T$") (goto-char (match-end 0))
        (should (org-in-src-block-p))
        (ert-simulate-command `(,(key-binding (kbd "TAB"))))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]