Reputation: 2853
I recently configured my Emacs setup to use python-mode.el instead of python.el. This changed has apparently caused org mode to no longer be able to export python source blocks, as I get
org-export-format-source-code-or-example: "End of buffer"
as the only message after export, and no export file is generated.
I'd like to know why this is, and what I can do to fix it. My python-mode.el is installed through el-get (not that I think that is important). It is loaded in my init file like so:
(add-to-list 'load-path "~/.emacs.d/el-get/python-mode/")
(autoload 'python-mode "python-mode" "Python Mode." t)
(add-to-list 'auto-mode-alist '("\\.py\\'" . python-mode))
(add-to-list 'interpreter-mode-alist '("python" . python-mode))
Here's the sample that produces this error:
This is a test.
#+BEGIN_SRC python
print "Hello, World"
#+END_SRC
And here is what I see in Messages:
Export buffer:
Exporting...
org-babel-exp processing...
org-export-format-source-code-or-example: End of buffer
Upvotes: 1
Views: 766
Reputation: 4804
AFAIS when exporting source-code, the language-modes are not queried.
It's a matter of the exporter.
Upvotes: 0
Reputation: 1716
In my configuration,
I have the same problem. When I trace what causes this error, I found that org-html-fontifiy-code
in ox-html.el
causes this error. Especially code block around below:
(save-excursion
(let ((beg (point-min))
(end (point-max)))
(goto-char beg)
(while (progn (end-of-line) (< (point) end))
(put-text-property (point) (1+ (point)) 'face nil)
(forward-char 1))))
Normally, in the last iteration of the while loop, the point before put-text-property
usually has the value (1- (point-max))
, putting text property (which does not change the point), then it calls forward-char
to move the point to (point-max)
, and stop the while loop.
Strangely, in python source block, put-text-property
moves the point to (1+ (point))
. So in the last iteration, put-text-property
moves the point to (1+ (point))
, so that the point is already at the (point-max)
, so calling forward-char
will fail with "End of buffer" error.
I smell the fish in python-mode; Perhaps they install some hook functions or something to make put-text-property
moves the point? I'm not sure. For the monkey patch, here's the dirty patch for above code block:
(save-excursion
(let ((beg (point-min))
(end (point-max)))
(goto-char beg)
(while (progn (end-of-line) (< (point) end))
(let ((oldpos (point)))
(put-text-property (point) (1+ (point)) 'face nil)
(goto-char oldpos))
(forward-char 1))))
Sorry for my laziness, but could anyone post this to org-mode/python-mode mailing list?
Upvotes: 1