correl.github.io/_posts/2016-02-23-org-publish-with-theme.html
2016-02-23 15:58:43 -05:00

32 lines
4.3 KiB
HTML

---
title: "Use a different theme when publishing Org files"
author: "Correl Roush"
tags: emacs org-mode themes
---
<p>
I've been using <a href="https://github.com/cpaulik/emacs-material-theme">material-theme</a> lately, and I sometimes switch around,
but I've found that <a href="https://github.com/bbatsov/solarized-emacs">solarized</a> produces the best exported code block
results. To avoid having to remember to switch themes when exporting,
I wrote a quick wrapper for org-export to do it for me:
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #2aa198;">(</span><span style="color: #859900; font-weight: bold;">defun</span> <span style="color: #268bd2;">my/with-theme</span> <span style="color: #b58900;">(</span><span style="color: #c0afa7;">theme</span> <span style="color: #a7aac0;">fn</span> <span style="color: #b58900;">&amp;rest</span> <span style="color: #a6bb99;">args</span><span style="color: #b58900;">)</span>
<span style="color: #b58900;">(</span><span style="color: #859900; font-weight: bold;">let</span> <span style="color: #268bd2;">(</span><span style="color: #6c71c4;">(</span><span style="color: #a7aac0;">current-themes</span> <span style="color: #b6a0e0;">custom-enabled-themes</span><span style="color: #6c71c4;">)</span><span style="color: #268bd2;">)</span>
<span style="color: #268bd2;">(</span><span style="color: #9999bb;">mapcar</span> #'<span style="color: #a6bb99;">disable-theme</span> <span style="color: #b6a0e0;">custom-enabled-themes</span><span style="color: #268bd2;">)</span>
<span style="color: #268bd2;">(</span><span style="color: #c0afa7;">load-theme</span> <span style="color: #c0afa7;">theme</span> <span style="color: #a0d6e0;">t</span><span style="color: #268bd2;">)</span>
<span style="color: #268bd2;">(</span><span style="color: #859900; font-weight: bold;">let</span> <span style="color: #6c71c4;">(</span><span style="color: #859900;">(</span><span style="color: #a0d6e0;">result</span> <span style="color: #b58900;">(</span><span style="color: #b3c0a7;">apply</span> <span style="color: #a7aac0;">fn</span> <span style="color: #a6bb99;">args</span><span style="color: #b58900;">)</span><span style="color: #859900;">)</span><span style="color: #6c71c4;">)</span>
<span style="color: #6c71c4;">(</span><span style="color: #9999bb;">mapcar</span> #'<span style="color: #a6bb99;">disable-theme</span> <span style="color: #b6a0e0;">custom-enabled-themes</span><span style="color: #6c71c4;">)</span>
<span style="color: #6c71c4;">(</span><span style="color: #9999bb;">mapcar</span> <span style="color: #859900;">(</span><span style="color: #859900; font-weight: bold;">lambda</span> <span style="color: #b58900;">(</span><span style="color: #c0afa7;">theme</span><span style="color: #b58900;">)</span> <span style="color: #b58900;">(</span><span style="color: #c0afa7;">load-theme</span> <span style="color: #c0afa7;">theme</span> <span style="color: #a0d6e0;">t</span><span style="color: #b58900;">)</span><span style="color: #859900;">)</span> <span style="color: #a7aac0;">current-themes</span><span style="color: #6c71c4;">)</span>
<span style="color: #a0d6e0;">result</span><span style="color: #268bd2;">)</span><span style="color: #b58900;">)</span><span style="color: #2aa198;">)</span>
<span style="color: #2aa198;">(</span><span style="color: #e0d0a0;">advice-add</span> #'<span style="color: #c0afa7;">org-export-to-file</span> <span style="color: #839496; font-weight: bold;">:around</span> <span style="color: #b58900;">(</span><span style="color: #b6a0e0;">apply-partially</span> #'<span style="color: #bba699;">my/with-theme</span> '<span style="color: #99bbb4;">solarized-dark</span><span style="color: #b58900;">)</span><span style="color: #2aa198;">)</span>
<span style="color: #2aa198;">(</span><span style="color: #e0d0a0;">advice-add</span> #'<span style="color: #9999bb;">org-export-to-buffer</span> <span style="color: #839496; font-weight: bold;">:around</span> <span style="color: #b58900;">(</span><span style="color: #b6a0e0;">apply-partially</span> #'<span style="color: #bba699;">my/with-theme</span> '<span style="color: #99bbb4;">solarized-dark</span><span style="color: #b58900;">)</span><span style="color: #2aa198;">)</span>
</pre>
</div>
<p>
Voilà, no more bizarrely formatted code block exports from whatever
theme I might have loaded at the time :)
</p>