hniksic / emacs-htmlize

Convert buffer text and decorations to HTML.
192 stars 45 forks source link

Warning about font-lock-fontify-buffer with Emacs 25.3 #14

Closed scfc closed 5 years ago

scfc commented 6 years ago

With Emacs 25.3, byte-compiling htmlize.el triggers a warning:

In htmlize-file:
htmlize.el:1893:17:Warning: `font-lock-fontify-buffer' is for interactive use
    only; use `font-lock-ensure' or `font-lock-flush' instead.

The following patch solves this (while still fontifying the output :-)):

--- /dev/fd/63  2018-01-07 01:24:02.790734877 +0000
+++ emacs-htmlize-release-1.51/htmlize.el       2018-01-07 00:42:57.278556882 +0000
@@ -1889,11 +1889,7 @@
       (let ((buffer-file-name file))
        ;; Set the major mode for the sake of font-lock.
        (normal-mode)
-       (font-lock-mode 1)
-       (unless font-lock-mode
-         ;; In GNU Emacs (font-lock-mode 1) doesn't force font-lock,
-         ;; contrary to the documentation.  This seems to work.
-         (font-lock-fontify-buffer))
+       (font-lock-ensure)
        ;; htmlize the buffer and save the HTML.
        (with-current-buffer (htmlize-buffer-1)
          (unwind-protect

As I don't know the best way to preserve compatibility with Emacs 21/21, I won't submit this as a pull request (BTW, htmlize.el "aims for compatibility with Emacsen version 21 and later", while README.md "aims for compatibility with Emacsen version 22 and later").

hniksic commented 6 years ago

I've now made it so that font-lock-ensure is used where available, but I'm afraid the warning is still present. htmlize no longer aims for compatibility with Emacsen as old as 21, but I'm not yet ready to drop support for Emacs 24, which I am still using on some machines.

hniksic commented 5 years ago

The warning should now be removed as well.