Search code examples
org-mode

Get org-mode fontification in a non-org-mode buffer


I realize this is a weird question as you can get fontification just fine in org files.

But I am experimenting with using some org features, in this case org fontification, in non org buffers.

I am a long time org user and I am comfortable with reading the source of Org and indeed have found functions like org-set-font-lock-defaults and org-ensure-font-lock and org-fontify-like-in-org-mode and have experimented with calling some of these, but have not gotten any results. For instance by something like: open an foo.org file, switch to fundamental mode and then invoke one of the likely functions mentioned above programmatically on the buffer hoping to see the buffer fontified as is typical of org-mode.

I am only superficially familiar with Emacs' font lock system and text properties otherwise perhaps I'd have already figured it out. Any tips of where fontification in Org actually kicks in and how to do this would be appreciated.


Solution

  • It should be just a matter of setting defaults and fontifying the buffer:

    (org-set-font-lock-defaults)
    (font-lock-fontify-buffer)