From mboxrd@z Thu Jan 1 00:00:00 1970 From: l.stelmach@samsung.com (=?utf-8?Q?=C5=81ukasz?= Stelmach) Subject: Re: finding a parent node Date: Tue, 02 Jul 2013 13:35:58 +0200 Message-ID: <87vc4tmbxd.fsf@samsung.com> References: <87hagdo0ni.fsf@samsung.com> <87r4fh43wl.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:49922) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Utz5e-0002Vr-Ch for emacs-orgmode@gnu.org; Tue, 02 Jul 2013 07:49:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Utz5c-0001cf-Gd for emacs-orgmode@gnu.org; Tue, 02 Jul 2013 07:49:46 -0400 Received: from plane.gmane.org ([80.91.229.3]:37354) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UtysV-0004jy-Ir for emacs-orgmode@gnu.org; Tue, 02 Jul 2013 07:36:11 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1UtysT-0003yP-Ik for emacs-orgmode@gnu.org; Tue, 02 Jul 2013 13:36:09 +0200 Received: from 217-67-201-162.itsa.net.pl ([217.67.201.162]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 02 Jul 2013 13:36:09 +0200 Received: from l.stelmach by 217-67-201-162.itsa.net.pl with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 02 Jul 2013 13:36:09 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org It was <2013-07-02 wto 13:06>, when Thorsten Jolitz wrote: > l.stelmach@samsung.com (Łukasz Stelmach) writes: > > Hello Lukasz, > > assume my simple-test.org with a :TASK: tag: > > #+begin_src org > * header 1 > :PROPERTIES: > :CUSTOM_ID: XYZ22 > :END: > * header 2 :TASK: > [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 > >> With my point somewher deep I'like to find the closest parent heading >> tagged :TASKS:. > > Lets move point to the source-block and get `org-element-context': > > #+begin_src emacs-lisp > (with-current-buffer > (find-file > "/path/to/simple-test.org") > (goto-char (point-min)) > (org-babel-next-src-block) > (message "%s" (point)) > (format "%s" > (org-element-context))) > #+end_src > #+begin_quote > "(src-block (:language emacs-lisp :switches nil :parameters nil :begin 319 > :end 362 :number-lines nil :preserve-indent nil :retain-labels t :use-labels > t :label-fmt nil :hiddenp nil :value (+ 3 4) :post-blank 0 :post-affiliated > 319 :parent nil))" > #+end_quote > > too bad, does not work in isolated use, :parent is nil. Othewise one could > get the parent(s) and check for the :TASK: tag. > > So the only way to find this headline I know of would be: > > #+begin_src emacs-lisp > (with-current-buffer > (find-file-noselect > "/path/to/simple-test.org") > (let ((tree (org-element-parse-buffer))) > (org-element-map tree 'headline > (lambda (hl) > (and > (member "TASK" (org-element-property :tags hl)) > (list (org-element-property :begin hl) > (org-element-property :end hl))))))) > #+end_src > > returns > > ,----------- > | ((55 362)) > `----------- > > so you could at least find out if (point) is inside a headline with a :TASK: > tag, then get this headline and use its attribute list to move to some place > inside of it. > > But I'm sure Nicolas can give you a much better solution (I would be > interested in that solution too). This might be enough for me as I get the tree in the exporting code. However, this way is far from efficient. If only there was a way to find the current element in the tree. I am not sure yet, but a sequence of org-back-to-heading and re-search-backward inside a save-excursion may be the easiest way to place the point where I want it. Any other thoughts? -- Łukasz Stelmach Samsung R&D Institute Poland Samsung Electronics