emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] How to represent this in Org-mode


From: Nicolas Richard
Subject: Re: [O] How to represent this in Org-mode
Date: Thu, 14 Aug 2014 13:08:52 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.92 (gnu/linux)

Marcin Borkowski <address@hidden> writes:

> Hello,
>
> now that I learned how to use a hammer, everything looks like a nail.
> So I want to use Org-mode for this; my question is, did anyone do
> anything similar and has some suggestions how to structure this
> material?

I did not do it, but still have one suggestion.

Each module could come with a name (e.g. CUSTOM_ID) and you could add a
:PREREQ: property listing all the other modules that are
prerequisite of that one.

It might then take some lisp to convert the data into an actual
dependency graph. graphviz might also come in handy for this task : it
allows to draw directed graphs easily. see below, I ended up writing
some of that lisp.

Imagine an org file like this:
#+BEGIN_SRC org
  ,* Module A
  :PROPERTIES:
  :CUSTOM_ID: A
  :END:
  ,* Module B
  :PROPERTIES:
  :CUSTOM_ID: B
  :PREREQ:   A
  :END:
  ,* Module C
  :PROPERTIES:
  :CUSTOM_ID: C
  :PREREQ:   A
  :END:
  ,* Module D
  :PROPERTIES:
  :CUSTOM_ID: D
  :PREREQ:   A B
  :END:
#+END_SRC

It could be translated to an graphviz code like this one very easily :

#+BEGIN_SRC dot :file dot-example3.png
       digraph test123 {
               {A} -> B;
               {A} -> C;
               {A B} -> D;
       }
#+END_SRC
which then compiles into a dependency graph. (note that "{A}-> B" could
also be written as "A -> B", but an automated translation mechanism
doesn't need to do that)

Here's some more graphviz code (taken from the manpage IIRC, the
comments in french are mine) to see what it can do if you want more:

#+begin_src dot :file dot-example.png
  digraph test123 {
          // on peut faire un digraphe sans tête de flèches!
          edge [arrowhead=none];
          // créer des flèches
          a -> b -> c;
          // créer des flèches d'un noeud vers plusieurs
          a -> {x y} [weight=10];
          // donner la forme d'un noeud
          b [shape=box];
          // donner un nom, une couleur, etc. à un noeud
          c [label="hello\nworld",color=blue,fontsize=24,
               fontname="Palatino-Italic",fontcolor=red,style=filled];
          // créer une flèche avec un label et un poids.
          // si on diminue le poids (4, 3, 2, 1, 0), la flèche se courbe.
          a -> z [label="hi", weight=60];
          // label multiligne.
          x -> z [label="multi-line\nlabel"];
          // 
          edge [style=dashed,color=red,arrowhead=normal];
          {rank=same; b->x};
  }
#+end_src

Because I was curious, I wrote a few lines of elisp to do the
conversion:

;; call this one via M-x ...
(defun yf/org-dependencies ()
  (interactive)
  (with-output-to-temp-buffer (get-buffer-create "*OrgFormatDeps*")
    (princ "digraph OrgDeps {\n")
    (org-map-entries 'yf/org-format-dependency)
    (princ "}")
    (terpri)
    (pop-to-buffer (current-buffer))))

;; this is a helper function
(defun yf/org-format-dependency ()
  (let ((id (org-entry-get (point) "CUSTOM_ID"))
        (prereqs (org-entry-get-multivalued-property (point) "PREREQ")))
    (when (and id prereqs)
      (princ
       (concat "     {"
               (mapconcat 'identity prereqs " ")
               "} -> "
               id
               ";"))
      (terpri))))


-- 
Nico.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]