Kungsgeten / org-brain-export

Export org-brain to other formats
MIT License
31 stars 3 forks source link

An easy way to get tags and properties from an org-brain entry ? #7

Open theottm opened 4 years ago

theottm commented 4 years ago

In order to specify shapes and colors to dot, I would like to pass PROPERTIES values to org-brain-export-generate-data. What is the simplest way to get the result of org-entry-get or org-element-property of an org-bain entry ?

theottm commented 4 years ago

I found this : (org-with-point-at (org-brain-entry-marker entry) (org-entry-get nil "PROPERTY_NAME"))

bepolymathe commented 4 years ago

Have you found a solution to your problem? I'm interested, too, until we get something clickable...

theottm commented 4 years ago

I hacked something that worked for me but not sure it would fit each use case. Here is what I did :

  1. I defined a new function to get the properties from a brain entry (defun org-brain-get-property(entry prop) (org-with-point-at (org-brain-entry-marker entry) (org-entry-get nil prop)) )

  2. I redifined org-brain-export-generate-data so that the data of this property gets added to the a-list (defun org-brain-export-generate-data (entry) "Generate data representation oforg-brain' ENTRY. Represented as an alist." (a-list :id (org-brain-entry-identifier entry) :type (if (org-brain-filep entry) 'file 'headline) :title (org-brain-title entry) :text (org-brain-text entry) :children (mapcar (lambda (child) (org-brain-export--relation-data entry child)) (org-brain-children entry)) :parents (mapcar (lambda (parent) (org-brain-export--relation-data entry parent)) (org-brain-parents entry)) :friends (mapcar (lambda (friend) (org-brain-export--relation-data entry friend)) (org-brain-friends entry)) :myprop (org-brain-get-property entry "MY_PROPERTY") ; <-- HERE ))`

  3. I defined a function to associate each value of my property to a color (defun org-brain-export--dot-color(prop) (cond ((string= prop "DEF") "cyan") ((string= prop "AXIOM") "black") ((string= prop "SATZ") "red") ((string= prop "BEISPIEL") "white") ((string= prop "BEMERKUNG") "grey") ((string= prop "LEMMA") "pink") ((string= prop "KOROLLAR") "pink") ((string= prop "ALGO") "pink") ) )

  4. I redefined the function org-brain-export--dot-node-defso a color attribute corresponding to my prop is passed to the dot file (defun org-brain-export--dot-node-def (ob-data) "Get node entry line (a string) of OB-DATA." (format "%s [label=\"%s\", color=\"%s\"];\n" ; <-- HERE (org-brain-export--dot-id ob-data) (replace-regexp-in-string "\"" "" (alist-get :title ob-data)) (org-brain-export--dot-color (alist-get :myprop ob-data)) ; <-- HERE ) )

theottm commented 4 years ago

I will work on a more flexible an easy to use implementation (with defcustoms) when I have a bit more time (in March). I want to reach something as easy as setting a list of properties to export and an indication on what to add to the dot file depending on the value of the property.

theottm commented 4 years ago

Sorry elisp doesn't print very well. Copy all this in a scratch buffer and evaluate it. @Kungsgeten Is there a better way ?

Kungsgeten commented 4 years ago

Hi! Sorry for the late response. If its a single value property you could use (org-entry-get (org-brain-entry-marker entry) "PROPERTY_NAME"). If the property holds multiple values use org-entry-get-multivalued-property instead.

Perhaps org-brain-export-generate-data should have a key named :properties which gathers all the properties for every entry? The value of that key would probably be an alist. That way the function doesn't need to be expanded every time a property is needed for some specific reason.

theottm commented 4 years ago

Hi! Thanks for the snippet, that is a better way to get a property.

I think it is a good idea to pack all properties in one data structure. Is there something like org-entry-get-everything ? Maybe in org-element ? Or maybe it would be enough to just make a list of all known properties with something like org-buffer-property-keys and then run the org-entry-get for each entry and each property ?

Kungsgeten commented 4 years ago

There seems to be a function named org-entry-properties which collects all properties. Have a look here: https://orgmode.org/manual/Using-the-Property-API.html

It seems like (org-entry-properties (org-brain-entry-marker entry)) would work.

theottm commented 4 years ago

Oh nice. As simple as that :)