Skip to content

Commit

Permalink
org-diary-sexp-entry: Cache results
Browse files Browse the repository at this point in the history
* lisp/org.el (org--diary-sexp-entry-cache): New variable holding
cached return values of `org-diary-sexp-entry'.
(org-diary-sexp-entry): Use `org--diary-sexp-entry-cache'.
  • Loading branch information
yantar92 committed Sep 21, 2022
1 parent c35a856 commit 4075662
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions lisp/org.el
Original file line number Diff line number Diff line change
Expand Up @@ -14425,34 +14425,39 @@ D may be an absolute day number, or a calendar-type list (month day year)."
(let ((hl (calendar-check-holidays org-agenda-current-date)))
(and hl (mapconcat #'identity hl "; "))))

(defvar org--diary-sexp-entry-cache (make-hash-table :test #'equal)
"Hash table holding return values of `org-diary-sexp-entry'.")
(defun org-diary-sexp-entry (sexp entry d)
"Process a SEXP diary ENTRY for date D."
(require 'diary-lib)
;; `org-anniversary' and alike expect ENTRY and DATE to be bound
;; dynamically.
(let* ((sexp `(let ((entry ,entry)
(date ',d))
,(car (read-from-string sexp))))
;; FIXME: Do not use (eval ... t) in the following sexp as
;; diary vars are still using dynamic scope.
(result (if calendar-debug-sexp (eval sexp)
(condition-case nil
(eval sexp)
(error
(beep)
(message "Bad sexp at line %d in %s: %s"
(org-current-line)
(buffer-file-name) sexp)
(sleep-for 2))))))
(cond ((stringp result) (split-string result "; "))
((and (consp result)
(not (consp (cdr result)))
(stringp (cdr result)))
(cdr result))
((and (consp result)
(stringp (car result)))
result)
(result entry))))
(or (gethash (list sexp entry d) org--diary-sexp-entry-cache)
(puthash (list sexp entry d)
(let* ((sexp `(let ((entry ,entry)
(date ',d))
,(car (read-from-string sexp))))
;; FIXME: Do not use (eval ... t) in the following sexp as
;; diary vars are still using dynamic scope.
(result (if calendar-debug-sexp (eval sexp)
(condition-case nil
(eval sexp)
(error
(beep)
(message "Bad sexp at line %d in %s: %s"
(org-current-line)
(buffer-file-name) sexp)
(sleep-for 2))))))
(cond ((stringp result) (split-string result "; "))
((and (consp result)
(not (consp (cdr result)))
(stringp (cdr result)))
(cdr result))
((and (consp result)
(stringp (car result)))
result)
(result entry)))
org--diary-sexp-entry-cache)))

(defun org-diary-to-ical-string (frombuf)
"Get iCalendar entries from diary entries in buffer FROMBUF.
Expand Down

0 comments on commit 4075662

Please sign in to comment.