From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Richard 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 22:56:47 +0100 Message-ID: <87a9d42tsw.fsf@yahoo.fr> References: <87zjl4wsz7.fsf@yahoo.fr> <87ha7cjwdx.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:42019) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WLJoD-0003Ef-IA for emacs-orgmode@gnu.org; Wed, 05 Mar 2014 16:57:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WLJo6-0007NF-8C for emacs-orgmode@gnu.org; Wed, 05 Mar 2014 16:57:01 -0500 Received: from mailrelay006.isp.belgacom.be ([195.238.6.172]:51093) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WLJo6-0007N5-2K for emacs-orgmode@gnu.org; Wed, 05 Mar 2014 16:56:54 -0500 In-Reply-To: <87ha7cjwdx.fsf@gmail.com> (Nicolas Goaziou's message of "Wed, 05 Mar 2014 20:08:58 +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 Goaziou Cc: Nicolas Richard , emacs-orgmode@gnu.org Hi Nicolas, Nicolas Goaziou writes: > 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. I don't know if speed is terribly important here, but since my suggested approach uses a loop instead of recursion, it ends up being faster for nested headlines (more than 5 levels). This obviously could be fixed in the initial approach too. Since we know where point is, we could also use (org-element-headline-parser nil t) instead of (org-element-at-point). That's a tiny bit faster. For those interested, here's timing info: (progn (defun yf/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-headline-parser nil t))) (while (and elt (not (org-element-property :commentedp elt))) (setq elt (and (org-up-heading-safe) (org-element-headline-parser nil t)))) elt)))) (elp-instrument-list '(org-babel-under-commented-heading-p yf/org-babel-under-commented-heading-p)) (let ((org-element-use-cache t)) (with-temp-buffer (insert "* foo bar ** bal *** bal **** bal ***** bal ****** bal ******* bal ******** bal ********* bal ********** bal *********** bal ************ bal ************* bal ************** bal") (org-mode) (goto-char (point-min)) (forward-line 4) ;; <- 0 for top level, etc. ;; (profiler-reset) (let ((n 100)) (garbage-collect) (dotimes (_ n) (org-babel-under-commented-heading-p)) (dotimes (_ n) (yf/org-babel-under-commented-heading-p)) (elp-results) ) ;; (profiler-report) ))) > Also, don't forget `org-with-limited-levels' when you need to tell > a headline from an inlinetask. I have absolutely no idea if this is important here. -- Nicolas.