emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Richard <theonewiththeevillook@yahoo.fr>
To: Nicolas Goaziou <n.goaziou@gmail.com>
Cc: Nicolas Richard <theonewiththeevillook@yahoo.fr>, emacs-orgmode@gnu.org
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	[thread overview]
Message-ID: <87a9d42tsw.fsf@yahoo.fr> (raw)
In-Reply-To: <87ha7cjwdx.fsf@gmail.com> (Nicolas Goaziou's message of "Wed, 05 Mar 2014 20:08:58 +0100")

Hi Nicolas,

Nicolas Goaziou <n.goaziou@gmail.com> 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.

  parent reply	other threads:[~2014-03-05 21:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-05 15:44 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/)] Nicolas Richard
2014-03-05 19:08 ` Nicolas Goaziou
2014-03-05 21:55   ` Nicolas Richard
2014-03-05 21:56   ` Nicolas Richard [this message]
2014-03-05 22:27     ` Nicolas Goaziou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a9d42tsw.fsf@yahoo.fr \
    --to=theonewiththeevillook@yahoo.fr \
    --cc=emacs-orgmode@gnu.org \
    --cc=n.goaziou@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).