Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
theottm opened this issue Feb 17, 2020 · 9 comments
Open

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

theottm opened this issue Feb 17, 2020 · 9 comments
Labels
discussion question Further information is requested

Comments

@theottm
Copy link

theottm commented Feb 17, 2020

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 theottm changed the title An easy way to get tags and properties for an entry ? An easy way to get tags and properties from an org-brain entry ? Feb 17, 2020
@theottm
Copy link
Author

theottm commented Feb 17, 2020

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

@bepolymathe
Copy link

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

@theottm
Copy link
Author

theottm commented Feb 21, 2020

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 of org-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
Copy link
Author

theottm commented Feb 21, 2020

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
Copy link
Author

theottm commented Feb 21, 2020

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

@Kungsgeten
Copy link
Owner

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.

@Kungsgeten Kungsgeten added discussion question Further information is requested labels Feb 24, 2020
@theottm
Copy link
Author

theottm commented Feb 24, 2020

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
Copy link
Owner

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
Copy link
Author

theottm commented Feb 24, 2020

Oh nice. As simple as that :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants