[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] How to define file-local preamble for graphviz dot?
From: |
Vladimir Alexiev |
Subject: |
Re: [O] How to define file-local preamble for graphviz dot? |
Date: |
Tue, 5 Aug 2014 17:30:10 +0300 |
Vladimir Alexiev <vladimir.alexiev <at> ontotext.com> writes:
> I have a bunch of dot settings that I want to set globally. I hacked it like
> this:
> (defadvice org-babel-expand-body:dot (before add-preamble (body params)
> activate)
A better way to hack it is like that, using the header args :prologue and
:epilogue
(eval-after-load "ob-dot"
' (progn
(add-to-list 'org-babel-default-header-args:dot
'(:cache . "yes"))
(add-to-list 'org-babel-default-header-args:dot
'(:prologue . "digraph g {
rankdir=LR nodesep=0.2 ranksep=0.1 arrowsize=0.2
node [fontname=courier fontsize=10 margin=\"0.02,0.01\" shape=box width=0.1
height=0.1]
edge [fontname=courier fontsize=8 labelfontname=courier labelfontsize=8]"))
(add-to-list 'org-babel-default-header-args:dot
'(:epilogue . "}"))))
Unfortunately ob-dot doesn't interpret :prologue and :epilogue, so I adviced it:
(defadvice org-babel-expand-body:dot (before prologue-epilogue activate)
"Interpret :prologue and :epilogue headers, like
org-babel-expand-body:generic"
(let ((pro (cdr-safe (assoc :prologue params)))
(epi (cdr-safe (assoc :epilogue params))))
(setq body (mapconcat #'identity
(append (when pro (list pro))
(list body)
(when epi (list epi)))
"\n"))))
Then in a particular file I can override the :prologue like so:
* Local Variables :noexport:
Local Variables:
eval: (setq-local org-babel-default-header-args:dot (cons '(:prologue .
"digraph g {
rankdir=LR nodesep=0.2 ranksep=0.3 arrowsize=0.1
node [fontname=courier fontsize=8 margin=\"0.02,0.01\" shape=circle
width=0.25 height=0.25 label=\"\"]
edge [fontname=courier fontsize=8 labelfontname=courier labelfontsize=8]")
(cl-remove :prologue org-babel-default-header-args:dot :key 'car :test 'eq)))
End:
This works, although it asks for confirmation every time the file is loaded.
Trying to do it with a code block:
#+BEGIN_SRC emacs-lisp :results silent :exports none
#+END_SRC
didn't work because that code is not executed automatically on export.