1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-11-26 07:33:39 +00:00

Speed-up multiple calls to `org-diary'.

Patch by Matt Lundin

Matt writes:

> The missing piece of the puzzle is integration with "diary" and
> "cal-tex" functions via the org-diary sexp. I have found org-diary to be
> excruciatingly slow when called for anything more than a couple of days.
> I have the following line in my diary file:
>
> &%%(org-diary :timestamp :sexp)
>
> If I try to view 20 or so upcoming days in the diary by typing C-u 20 d
> on a date in the calendar, it can take upwards of 30 seconds to generate
> the diary display. This is of little consequence, since I can, after
> all, simply use the custom agenda command. But I often want to print out
> a nice LaTeX calendar of my appointments with cal-tex-cursor-month. And
> that takes upwards of 50 seconds (see attached elp-results file).
>
> Judging from the elp-results, the culprit seems to be
> org-prepare-agenda-buffers (46 seconds), which is called 31 times (once
> for each day). It seems to me that since org-diary is being called 31
> times in quick succession by the same function (diary-sexp-entry), one
> should only need to call org-prepare-agenda-buffers once.
>
> The only solution I could see to this problem was to add a test to see
> if org-diary had been called less than 1 second ago. Thus, I added the
> variable org-diary-last-run-time and a conditional in org-diary that
> only runs org-prepare-agenda-buffers if org-diary-last-run-time is less
> than 1 second in the past.
>
> With the patch, it now takes appr. 5 seconds to generate the LaTeX
> calendar with cal-tex and org-prepare-agenda-buffers is called only
> once.
This commit is contained in:
Carsten Dominik 2010-03-29 11:24:06 +02:00
parent aed051cf8c
commit a3f3efe82d
2 changed files with 13 additions and 1 deletions

View File

@ -1,5 +1,9 @@
2010-03-29 Carsten Dominik <carsten.dominik@gmail.com>
* org-agenda.el (org-diary-last-run-time): New variable.
(org-diary): prepare agenda buffers only if last call was some
time ago.
* org-html.el (org-export-html-preprocess): Replace \ref macros
with a link.
(org-format-org-table-html): Add the label as an anchor.

View File

@ -4086,6 +4086,8 @@ Needed to avoid empty dates which mess up holiday display."
(apply 'diary-add-to-list args)
(apply 'add-to-diary-list args)))
(defvar org-diary-last-run-time nil)
;;;###autoload
(defun org-diary (&rest args)
"Return diary information from org-files.
@ -4123,8 +4125,14 @@ function from a program - use `org-agenda-get-day-entries' instead."
(let* ((files (if (and entry (stringp entry) (string-match "\\S-" entry))
(list entry)
(org-agenda-files t)))
(time (org-float-time))
file rtn results)
(org-prepare-agenda-buffers files)
(when (or (not org-diary-last-run-time)
(> (- time
org-diary-last-run-time)
3))
(org-prepare-agenda-buffers files))
(setq org-diary-last-run-time time)
;; If this is called during org-agenda, don't return any entries to
;; the calendar. Org Agenda will list these entries itself.
(if org-disable-agenda-to-diary (setq files nil))