From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: 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 Message-ID: <87ha7cjwdx.fsf@gmail.com> References: <87zjl4wsz7.fsf@yahoo.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:37595) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WLHBI-0007Gb-GS for emacs-orgmode@gnu.org; Wed, 05 Mar 2014 14:08:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WLHBD-0002TS-AU for emacs-orgmode@gnu.org; Wed, 05 Mar 2014 14:08:40 -0500 Received: from mail-wg0-x22d.google.com ([2a00:1450:400c:c00::22d]:55571) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WLHBD-0002Ss-3A for emacs-orgmode@gnu.org; Wed, 05 Mar 2014 14:08:35 -0500 Received: by mail-wg0-f45.google.com with SMTP id l18so1313756wgh.4 for ; Wed, 05 Mar 2014 11:08:34 -0800 (PST) In-Reply-To: <87zjl4wsz7.fsf@yahoo.fr> (Nicolas Richard's message of "Wed, 05 Mar 2014 16:44:12 +0100") 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: Nicolas Richard Cc: emacs-orgmode@gnu.org Hello, Nicolas Richard writes: > I take the opportuinty to ask if we should try and make this function > use org-element instead. > > My na=C3=AFve 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, --=20 Nicolas Goaziou