Hello,

Nicolas Richard <theonewiththeevill...@yahoo.fr> writes:

> I take the opportuinty to ask if we should try and make this function
> use org-element instead.
>
> My naïve approach doesn't work:
>
> #+begin_src emacs-lisp
>   (save-excursion
>     (org-back-to-heading t)
>     (let ((elt (org-element-at-point)))
>       (while (and elt
>                 (not
>                  (org-element-property :commentedp elt)))
>       (setq elt
>             (org-element-property :parent elt)))
>       elt))
> #+end_src
>
> because an heading doesn't know what its parent heading is (the property
> is nil). This can be fixed by doing:
>
> #+begin_src emacs-lisp
> (defun org-babel-under-commented-heading-p ()
>   "Return t if currently under a commented heading."
>   (unless (org-before-first-heading-p)
>     (save-excursion
>       (org-back-to-heading t)
>       (let ((elt (org-element-at-point)))
>       (while (and elt
>                   (not
>                    (org-element-property :commentedp elt)))
>         (setq elt
>               (and (org-up-heading-safe)
>                    (org-element-at-point))))
>       elt))))
> #+end_src
>
>
> byt I'm not sure it is very pretty. Opinions ?

Of course, `org-element-at-point' can parse headlines, but if speed is
a factor, since headline syntax is not context-dependent, it is often
worth considering using regexps.

Also, don't forget `org-with-limited-levels' when you need to tell
a headline from an inlinetask.


Regards,

-- 
Nicolas Goaziou

Reply via email to