Emacs: org-html-export returns org-html-fontify-code: Wrong number of arguments…

A few days ago, for no reason (for fun, maybe), I cloned the Github mirror of Emacs and built a latest Emacs. I also removed my old Emacs (I was silly, I blame Melbourne’s weather :D). Many subtle problems occurred since then, for example, executing org-html-export-as-html often causes the following error:

org-html-fontify-code: Wrong number of arguments: #[(_beg _end) "À ‡" [font-lock-fontify-buffer] 1], 0

1 Solution

Redefine function org-font-lock-ensure. Add the following code snippet to init.el and execute it to solve the problem:

(defun org-font-lock-ensure ()
  (font-lock-fontify-buffer))

2 HACK LOG

I find that if there is no source code blocks in the content, then org-html-export-as-html works properly. So I guess the problem occurred during exporting source code blocks to HTML.

M-x toggle-debug-on-error (to prints a backtrace when an error happens in Emacs)

Then create a very simple org-mode file which only contains a python code block:

def hello():
   print "hello world"

Now press M-x org-html-export-as-html , here is the Backtrace (unimportant parts are omitted):

Debugger entered--Lisp error: (wrong-number-of-arguments #[(_beg _end) "\300 \207" [font-lock-fontify-buffer] 1] 0)
  org-font-lock-ensure()
  org-html-fontify-code("def hello():\n   print \"hello world\"\n" "python")
  org-html-do-format-code("def hello():\n   print \"hello world\"\n" "python" nil t nil)
.
.
.

Obviously, the problem was in org-font-lock-ensure .

Click on it to see its definition:

(defalias 'org-font-lock-ensure
  (if (fboundp 'org-font-lock-ensure)
      #'font-lock-ensure
    (lambda (_beg _end) (font-lock-fontify-buffer))))

It means: if org-font-lock-ensure is not defined, then define it as (lambda (_beg _end) (font-lock-fontify-buffer)) .

But I don’t get it, font-lock-fontify-buffer doesn’t use arguments _beg and _end , why are they passed in?

Stop exploration here (it might just be a bug of org-mode), just redefine org-font-lock-ensure:

(defun org-font-lock-ensure ()
  (font-lock-fontify-buffer))

Press M-x org-html-export-as-html again, it works! Problem solved (temporarily)!

3 Lessons Learned

  • Don’t update software for no reason.
  • When update is necessary, keep an old version if possible.

Leave a Reply