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 Richard
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 22:55:09 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Hi Nicolas,

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

But as I said, I don't think speed matters much for this specific function.

> 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.



reply via email to

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