0

I am trying to access elements within the array generated by defstruct. More specifically, I would like to access the NOTER_DOCUMENT file path from org-noter's org-noter--session variable. The only way I managed to find was by indices with aref like so:

(aref org-noter--session 10)

Can I access the path nested within the 5th element (aref org-noter--session 5) via the :NOTER_DOCUMENT flag instead of the 10th element above?


Sample Input:

#s(org-noter--session 454687110523409506 #<frame Emacs Org-noter - Neurobehavioral and Social-Emotional Development 0x556a291015b0> #<buffer Neurobehavioral and Social-Emotional Development> #<buffer Notes of Neurobehavioral and Social-Emotional Development> (headline (:raw-value "Neurobehavioral and Social-Emotional Development" :begin 239 :end 3118 :pre-blank 0 :contents-begin 290 :contents-end 3118 :robust-begin 621 :robust-end 3116 :level 1 :priority nil :tags nil :todo-keyword nil :todo-type nil :post-blank 0 :footnote-section-p nil :archivedp nil :commentedp nil :post-affiliated 239 :CUSTOM_ID "Tronick_NeurobehavioralSocialEmotionalDevelopment_2007" :TYPE "book" :AUTHOR "Tronick, Edward" :NOTER_DOCUMENT "~/Calibre Library/Ed Tronick/The Neurobehavioral and Social-Emotional Development of Infants and Children (Norton Series on (1040)/The Neurobehavioral and Social-Emotional D - Ed Tronick.epub" :title "Neurobehavioral and Social-Emotional Development" :mode first-section :granularity greater-element :parent (org-data (:begin 1 :contents-begin 1 :contents-end 3118 :end 3118 :robust-begin 139 :robust-end 3116 :post-blank 0 :post-affiliated 1 :path "/home/sati/org/roam/reading_notes/Tronick_NeurobehavioralSocialEmotionalDevelopment_2007.org" :mode org-data :ID "0b3db03a-8b05-4b00-961d-d6cee4a8421c" :ROAM_REFS "cite:Tronick_NeurobehavioralSocialEmotionalDevelopment_2007" :CATEGORY "Tronick_NeurobehavioralSocialEmotionalDevelopment_2007" :granularity greater-element) #1)) (section (:begin 290 :end 622 :contents-begin 290 :contents-end 622 :robust-begin 290 :robust-end 620 :post-blank 0 :post-affiliated 290 :mode section :granularity greater-element :parent #1) (property-drawer (:begin 290 :end 622 :contents-begin 303 :contents-end 616 :post-blank 0 :post-affiliated 290 :mode planning :granularity greater-element :parent #2))) (headline (:raw-value "Strange Situation not useful in other cultures" :begin 622 :end 1017 :pre-blank 0 :contents-begin 672 :contents-end 1016 :robust-begin 715 :robust-end 1014 :level 2 :priority nil :tags nil :todo-keyword nil :todo-type nil :post-blank 1 :footnote-section-p nil :archivedp nil :commentedp nil :post-affiliated 622 :NOTER_PAGE "(15 . 1063)" :title "Strange Situation not useful in other cultures" :mode nil :granularity greater-element :parent #1) (section (:begin 672 :end 1017 :contents-begin 672 :contents-end 1016 :robust-begin 672 :robust-end 1014 :post-blank 1 :post-affiliated 672 :mode section :granularity greater-element :parent #2) (property-drawer (:begin 672 :end 717 :contents-begin 685 :contents-end 710 :post-blank 1 :post-affiliated 672 :mode planning :granularity greater-element :parent #3)) (paragraph (:begin 717 :end 1016 :contents-begin 717 :contents-end 1016 :post-blank 0 :post-affiliated 717 :mode nil :granularity greater-element :parent #3)))) (headline (:raw-value "Evolutionary Development of Empathy" :begin 1017 :end 2424 :pre-blank 0 :contents-begin 1056 :contents-end 2422 :robust-begin 1099 :robust-end 2420 :level 2 :priority nil :tags nil :todo-keyword nil :todo-type nil :post-blank 2 :footnote-section-p nil :archivedp nil :commentedp nil :post-affiliated 1017 :NOTER_PAGE "(17 . 4866)" :title "Evolutionary Development of Empathy" :mode nil :granularity greater-element :parent #1) (section (:begin 1056 :end 2424 :contents-begin 1056 :contents-end 2422 :robust-begin 1056 :robust-end 2420 :post-blank 2 :post-affiliated 1056 :mode section :granularity greater-element :parent #2) (property-drawer (:begin 1056 :end 1101 :contents-begin 1069 :contents-end 1094 :post-blank 1 :post-affiliated 1056 :mode planning :granularity greater-element :parent #3)) (paragraph (:begin 1101 :end 1359 :contents-begin 1101 :contents-end 1358 :post-blank 1 :post-affiliated 1101 :mode nil :granularity greater-element :parent #3)) (paragraph (:begin 1359 :end 1699 :contents-begin 1359 :contents-end 1698 :post-blank 1 :post-affiliated 1359 :mode nil :granularity greater-element :parent #3)) (paragraph (:begin 1699 :end 1927 :contents-begin 1699 :contents-end 1926 :post-blank 1 :post-affiliated 1699 :mode nil :granularity greater-element :parent #3)) (paragraph (:begin 1927 :end 2050 :contents-begin 1927 :contents-end 2049 :post-blank 1 :post-affiliated 1927 :mode nil :granularity greater-element :parent #3)) (comment (:begin 2050 :end 2074 :value "Unrelated side-note:" :post-blank 1 :post-affiliated 2050 :mode nil :granularity greater-element :parent #3)) (paragraph (:begin 2074 :end 2422 :contents-begin 2074 :contents-end 2422 :post-blank 0 :post-affiliated 2074 :mode nil :granularity greater-element :parent #3)))) (headline (:raw-value "Attachment Theory" :begin 2424 :end 3083 :pre-blank 0 :contents-begin 2445 :contents-end 3081 :robust-begin 2488 :robust-end 3079 :level 2 :priority nil :tags nil :todo-keyword nil :todo-type nil :post-blank 2 :footnote-section-p nil :archivedp nil :commentedp nil :post-affiliated 2424 :NOTER_PAGE "(17 . 9191)" :title "Attachment Theory" :mode nil :granularity greater-element :parent #1) (section (:begin 2445 :end 3083 :contents-begin 2445 :contents-end 3081 :robust-begin 2445 :robust-end 3079 :post-blank 2 :post-affiliated 2445 :mode section :granularity greater-element :parent #2) (property-drawer (:begin 2445 :end 2490 :contents-begin 2458 :contents-end 2483 :post-blank 1 :post-affiliated 2445 :mode planning :granularity greater-element :parent #3)) (paragraph (:begin 2490 :end 2586 :contents-begin 2490 :contents-end 2585 :post-blank 1 :post-affiliated 2490 :mode nil :granularity greater-element :parent #3)) (paragraph (:begin 2586 :end 2643 :contents-begin 2586 :contents-end 2642 :post-blank 1 :post-affiliated 2586 :mode nil :granularity greater-element :parent #3)) (paragraph (:begin 2643 :end 2681 :contents-begin 2643 :contents-end 2680 :post-blank 1 :post-affiliated 2643 :mode nil :granularity greater-element :parent #3)) (paragraph (:begin 2681 :end 2882 :contents-begin 2681 :contents-end 2881 :post-blank 1 :post-affiliated 2681 :mode nil :granularity greater-element :parent #3)) (paragraph (:begin 2882 :end 3081 :contents-begin 2882 :contents-end 3081 :post-blank 0 :post-affiliated 2882 :mode nil :granularity greater-element :parent #3)))) (headline (:raw-value "Tronick's notions about Empathy" :begin 3083 :end 3118 :pre-blank 0 :contents-begin nil :contents-end nil :robust-begin nil :robust-end nil :level 2 :priority nil :tags nil :todo-keyword nil :todo-type nil :post-blank 0 :footnote-section-p nil :archivedp nil :commentedp nil :post-affiliated 3083 :title "Tronick's notions about Empathy" :mode nil :granularity greater-element :parent #1))) 1 nov-mode "Neurobehavioral and Social-Emotional Development" "/home/sati/org/roam/reading_notes/Tronick_NeurobehavioralSocialEmotionalDevelopment_2007.org" "~/Calibre Library/Ed Tronick/The Neurobehavioral and Social-Emotional Development of Infants and Children (Norton Series on (1040)/The Neurobehavioral and Social-Emotional D - Ed Tronick.epub" 1 1 (start scroll) horizontal-split (0.5 . 0.5) nil t 0.3)
Sati
  • 775
  • 6
  • 21

1 Answers1

2

defstruct creates an accessor function for every field; you don’t need to know the field offset. Just call org-noter--session-notes-file-path, or whatever accessor you need (it’s not entirely clear from your question what field you want to access).

You should read the docstring for defstruct:

 -- Macro: cl-defstruct name slots...
     The ‘cl-defstruct’ form defines a new structure type called NAME,
     with the specified SLOTS.  (The SLOTS may begin with a string which
     documents the structure type.)  In the simplest case, NAME and each
     of the SLOTS are symbols.  For example,

          (cl-defstruct person first-name age sex)

     defines a struct type called ‘person’ that contains three slots.
     Given a ‘person’ object P, you can access those slots by calling
     ‘(person-first-name P)’, ‘(person-age P)’, and ‘(person-sex P)’.
     …

Use C-h f to read the documentation of a function (or a macro, in this case) within Emacs.

db48x
  • 15,741
  • 1
  • 19
  • 23