all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Re: How to define file-local preamble for graphviz dot?
@ 2014-08-05 14:30 Vladimir Alexiev
  0 siblings, 0 replies; 2+ messages in thread
From: Vladimir Alexiev @ 2014-08-05 14:30 UTC (permalink / raw)
  To: emacs-orgmode

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.

^ permalink raw reply	[flat|nested] 2+ messages in thread
* How to define file-local preamble for graphviz dot?
@ 2014-08-01 16:28 Vladimir Alexiev
  0 siblings, 0 replies; 2+ messages in thread
From: Vladimir Alexiev @ 2014-08-01 16:28 UTC (permalink / raw)
  To: emacs-orgmode

I have a bunch of dot settings that I want to set globally. I hacked it like this:

(setq va/org-dot-preamble "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]")

(defadvice org-babel-expand-body:dot (before add-preamble (body params) activate)
  "add DOT=va/org-dot-preamble as :var in params, so $dot is replaced with it"
  (setq params (cons (cons ':var (cons 'DOT va/org-dot-preamble))
                     params)))

And then I start dot code blocks with "$dot", which is replaced with the above string:

#+begin_src dot :results silent file :file ./img/SymmetricProperty.png
$dot 
x -> y [label="q"]
y -> x [label="q" color=red]
}
#+end_src

I can override a dot param by adding a different value after the common inclusion $dot, e.g.:
$dot ranksep=0.7

The problem is
*** how can I make this per-file? 
Neither #+BIND nor emacs "Local Variables:" does the trick.
Bonus if I can do it per-heading :-)

dot can take these settings from the command line, eg
-G "rankdir=LR nodesep=0.2 ranksep=0.1 arrowsize=0.2"
-N "fontname=courier fontsize=10 margin=\"0.02,0.01\" shape=box width=0.1 height=0.1"
-E "fontname=courier fontsize=8 labelfontname=courier labelfontsize=8"

So I could try to mess with the :cmdline slot of org-babel-default-header-args:dot ... is this evaluated locally?

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-08-05 14:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-05 14:30 How to define file-local preamble for graphviz dot? Vladimir Alexiev
  -- strict thread matches above, loose matches on Subject: below --
2014-08-01 16:28 Vladimir Alexiev

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.