From: Thorsten Jolitz <tjolitz@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: finding a parent node
Date: Tue, 02 Jul 2013 11:40:35 +0200 [thread overview]
Message-ID: <87a9m55mgc.fsf@gmail.com> (raw)
In-Reply-To: 87hagdo0ni.fsf@samsung.com
l.stelmach@samsung.com (Łukasz Stelmach) writes:
Hello,
> What is the best way to iterate over ((great)*grand)?parent headlines of
> the current one (at point), that meets some criteria.
not an answer to your question, but rather a related question I wanted
to post anyway, so I do it in this thread:
simple-test.org:
#+begin_src org
* header 1
:PROPERTIES:
:CUSTOM_ID: XYZ22
:END:
* header 2
[2013-06-28 Fr 11:01]
** subheader 1
Some text
** subheader 2
More text and a table
| label | col1 | col2 |
|--------+------+------|
| string | 3 | 4 |
Text and a src-block
#+begin_src emacs-lisp
(+ 3 4)
#+end_src
#+end_src
parse buffer:
#+begin_src emacs-lisp
(progn
(goto-char (point-max))
(newline 2)
(insert
(format "%s"
(with-current-buffer
(find-file-noselect
"/path/to/simple-test.org")
(setq tree (org-element-parse-buffer))))) )
#+end_src
excerpts form parse-tree:
#+begin_src emacs-lisp
(org-data
nil
;; first headline
(headline
(:raw-value header 1 :begin 1 :end55 :pre-blank0 :hiddenp
outline :contents-begin 12 :contents-end 55 :level 1 :priority
nil :tags nil :todo-keyword nil :todo-type nil :post-blank
1 :footnote-section-p nil :archivedp nil :commentedp nil :quotedp
nil :CUSTOM_ID XYZ22 :CATEGORY simple-test :title (header
1) :parent #0)
(section (:begin 12 :end 55 :contents-begin 12 :contents-end
55 :post-blank 0 :parent #1)
(property-drawer (:begin 12 :end 55 :hiddenp
outline :contents-begin 27 :contents-end 47 :post-blank
0 :post-affiliated 12 :parent #2) (node-property (:key
CUSTOM_ID :value XYZ22 :begin 27 :end 47 :post-blank 0 :parent
#3)))))
;; second headline
(headline (:raw-value header 2 :begin 55 :end 295 :pre-blank
0 :hiddenp outline :contents-begin 66 :contents-end 295 :level
1 :priority nil :tags nil :todo-keyword nil :todo-type
nil :post-blank 0 :footnote-section-p nil :archivedp
nil :commentedp nil :quotedp nil :CATEGORY
simple-test :title (header 2) :parent #0)
(section (:begin 66 :end 90 :contents-begin 66 :contents-end
90 :post-blank 0 :parent #1) (paragraph (:begin 66 :end
90 :contents-begin 66 :contents-end 90 :post-blank
0 :post-affiliated 66 :parent #2)
(timestamp (:type inactive :raw-value [2013-06-28 Fr
11:01] :year-start 2013 :month-start 6 :day-start 28 :hour-start
11 :minute-start 1 :year-end 2013 :month-end 6 :day-end
28 :hour-end 11 :minute-end 1 :begin 68 :end 89 :post-blank
0 :parent #3)) )) ...) )
#+end_src
now I can use `org-element-map' to access the elements and their attributes:
#+begin_src emacs-lisp
(insert
(format "\n\n%s"
(org-element-map
tree
'timestamp
'(lambda (X) (org-element-property :raw-value X)))))
;; => ([2013-06-28 Fr 11:01])
#+end_src
this gives me the first timestamp element and its property list:
#+begin_src emacs-lisp
(setq stamp1
(org-element-map
tree
'timestamp
'identity nil t))
#+end_src
but for further processing I always struggle with the :parent attribute and
the circularities in the list.
I often would like to use just a sublist like this, with :parent being a Link
or ID and not the parent object that refers to its parent object and so on ...
#+begin_src emacs-lisp
(timestamp (:type inactive :raw-value [2013-06-28 Fr
11:01] :year-start 2013 :month-start 6 :day-start 28 :hour-start
11 :minute-start 1 :year-end 2013 :month-end 6 :day-end
28 :hour-end 11 :minute-end 1 :begin 68 :end 89 :post-blank
0 :parent <<ID of or LINK to #3>>))
#+end_src
I tried to use the NO-RECURSION arg of `org-element-map' for this, but often
the parent is a headline or section, and then 'org-element-map' doesn't enter
headlines or sections and returns nil, i.e. the timestamp is never found.
Is there a way - using the parser/export framework toolbox - to avoid these
circularities, i.e. to either ignore the :parent attribute or better replace
the list object in it by something else that nevertheless identifies the
parent unmistakenly?
I know that with special bookkeeping while walking the tree one can deal with
these circularities, maybe I'm just new to this stuff, but I feel they make
the usual processing of such a nested list a bit complicated.
--
cheers,
Thorsten
next prev parent reply other threads:[~2013-07-02 9:41 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-02 7:56 finding a parent node Łukasz Stelmach
2013-07-02 9:40 ` Thorsten Jolitz [this message]
2013-07-02 11:06 ` Thorsten Jolitz
2013-07-02 11:35 ` Łukasz Stelmach
2013-07-02 12:12 ` Thorsten Jolitz
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=87a9m55mgc.fsf@gmail.com \
--to=tjolitz@gmail.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).