From: Thorsten Jolitz <tjolitz@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: How to find the headline matching a string
Date: Tue, 03 Jun 2014 11:05:56 +0200 [thread overview]
Message-ID: <87r436mkgb.fsf@gmail.com> (raw)
In-Reply-To: 874n05e0ls.fsf@ericabrahamsen.net
Eric Abrahamsen <eric@ericabrahamsen.net> writes:
> Thorsten Jolitz <tjolitz@gmail.com> writes:
>
>> Chris Poole <lists@chrispoole.com> writes:
>>
>>> Eric Abrahamsen:
>>>> the `org-map-entries' function can be given a scope of 'agenda
>>>
>>> That worked perfectly, thanks. Here's what I ended up with:
>>>
>>> (org-map-entries (lambda ()
>>> (when (equal title (org-get-heading t t))
>>> (org-entry-put (point) "TODO" "DONE")))
>>> tag 'agenda)
>>
>> As much as I like the powerful `org-map-entries', I wonder if it will
>> coexist with `org-element-map' in the future, since it does not use the
>> new parser.
>>
>> Whats the recommendation here? Should one rather use
>>
>> ,-----------------------------------------------------------
>> | (org-element-map (org-element-parse-buffer) 'headline (lambda () ...))
>> `-----------------------------------------------------------
>>
>> nowadays, or do both functions serve different purposes, or is it just a
>> matter of taste?
>
> Interesting! I wasn't even aware of org-element-map, thanks for that.
> Obviously I don't know the answer to your question, but they do seem to
> do very similar things. On the other hand, `org-element-map' won't do
> multiple files, and if you want to restrict to certain elements you have
> to do the matching logic yourself (as opposed to `org-map-entries's
> agenda-style search string).
>
> I'd be curious, too, to hear if `org-map-entries' is going to get EOL'd
> at some point. I suppose it's safe so long as `org-scan-tags' remains
> the heart of the agenda process.
>
> Here's my stab at two roughly equivalent functions, one using
> org-element, the other older function. Just for the hell of it I tried
> using "benchmark" to profile them, but have no idea if the results mean
> much of anything. Most importantly, I don't really know if
> `org-element-parse-buffer' ends up using the cache or not -- I assume
> not.
>
> (defun my-find-title-element-map (title)
> (interactive "sTitle: ")
> (let ((files (org-agenda-files))
> found)
> (dolist (f files)
> (with-current-buffer (org-get-agenda-file-buffer f)
> (org-element-map (org-element-parse-buffer 'headline)
> 'headline
> (lambda (hl)
> (when (string= title (org-element-property :title hl))
> (push (move-marker (make-marker)
> (org-element-property :begin hl))
> found))))))
> found))
>
>
> (defun my-find-title-entries-map (title)
> (interactive "sTitle: ")
> (let (found)
> (org-map-entries
> (lambda ()
> (when (string= title (org-get-heading t t))
> (push (move-marker (make-marker)
> (line-beginning-position))
> found)))
> nil 'agenda)
> found))
>
> (benchmark-run 100 (my-find-title-element-map "Unique Heading Text"))
> => (164.576821235 142 23.892782392000186)
>
> (benchmark-run 100 (my-find-title-entries-map "Unique Heading Text"))
> => (58.111630133 36 6.047778745000016)
This is interesting too - and a bit surprising. On my machine, the
org-element based function takes almost 4 times as long as the
org-map-entries based function:
#+BEGIN_SRC emacs-lisp
(defun my-find-title-element-map (title)
(interactive "sTitle: ")
(let ((files (org-agenda-files))
found)
(dolist (f files)
(with-current-buffer (org-get-agenda-file-buffer f)
(org-element-map (org-element-parse-buffer 'headline)
'headline
(lambda (hl)
(when (string= title (org-element-property :title hl))
(push (move-marker (make-marker)
(org-element-property :begin hl))
found))))))
found))
#+END_SRC
#+results:
: my-find-title-element-map
#+BEGIN_SRC emacs-lisp
(defun my-find-title-entries-map (title)
(interactive "sTitle: ")
(let (found)
(org-map-entries
(lambda ()
(when (string= title (org-get-heading t t))
(push (move-marker (make-marker)
(line-beginning-position))
found)))
nil 'agenda)
found))
#+END_SRC
#+results:
: my-find-title-entries-map
#+BEGIN_SRC emacs-lisp :results raw
(benchmark-run 30 (my-find-title-element-map "Unique Heading Text"))
#+END_SRC
#+results:
(160.439753043 735 76.66140414599985)
# => (164.576821235 142 23.892782392000186)
#+BEGIN_SRC emacs-lisp :results raw
(benchmark-run 30 (my-find-title-entries-map "Unique Heading Text"))
#+END_SRC
#+results:
(37.973595622000005 123 12.137436705999733)
# => (58.111630133 36 6.047778745000016)
--
cheers,
Thorsten
next prev parent reply other threads:[~2014-06-03 9:06 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-31 15:07 How to find the headline matching a string Chris Poole
2014-05-31 15:27 ` Eric Abrahamsen
2014-05-31 16:51 ` Chris Poole
2014-05-31 17:00 ` Igor Sosa Mayor
2014-05-31 17:31 ` Chris Poole
2014-05-31 17:53 ` Igor Sosa Mayor
2014-05-31 20:14 ` Thorsten Jolitz
2014-06-01 4:05 ` Eric Abrahamsen
2014-06-03 9:05 ` Thorsten Jolitz [this message]
2014-06-03 9:51 ` Eric Abrahamsen
2014-06-03 20:21 ` Nicolas Goaziou
2014-06-04 1:36 ` Eric Abrahamsen
2014-06-04 11:27 ` Thorsten Jolitz
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87r436mkgb.fsf@gmail.com \
--to=tjolitz@gmail.com \
--cc=emacs-orgmode@gnu.org \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.