emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Vladimir Alexiev" <vladimir.alexiev@ontotext.com>
To: emacs-orgmode@gnu.org
Subject: Re: How to define file-local preamble for graphviz dot?
Date: Tue, 5 Aug 2014 17:30:10 +0300	[thread overview]
Message-ID: <23315.361623145$1407249060@news.gmane.org> (raw)
In-Reply-To: 

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.

             reply	other threads:[~2014-08-05 14:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-05 14:30 Vladimir Alexiev [this message]
  -- strict thread matches above, loose matches on Subject: below --
2014-08-01 16:28 How to define file-local preamble for graphviz dot? Vladimir Alexiev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='23315.361623145$1407249060@news.gmane.org' \
    --to=vladimir.alexiev@ontotext.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).