emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Bug: [patch] also tangle headlines that begin with lower case st


From: Nicolas Goaziou
Subject: Re: [O] Bug: [patch] also tangle headlines that begin with lower case string "comment" [8.2.5h (release_8.2.5h-680-g12df70 @ /home/youngfrog/sources/org-mode/lisp/)]
Date: Wed, 05 Mar 2014 20:08:58 +0100

Hello,

Nicolas Richard <address@hidden> 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

[Prev in Thread] Current Thread [Next in Thread]