From: Max Mikhanosha <max@openchat.com>
To: emacs-orgmode@gnu.org
Subject: Hack: org-agenda-cache.el
Date: Sun, 15 Jan 2012 14:47:11 -0500 [thread overview]
Message-ID: <87r4z0bveo.wl%max@openchat.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1426 bytes --]
As my agenda files slowly grew over the years, the speed of generating
agenda had slowly deteriorated, finally hitting the point of me jdoing
something about it. (it got to around 5-7 seconds, which kind of
interrupts work-flow)
Attached file org-agenda-cache.el is a "quick fix" solution that I
developed for myself, its more of a request for discussion and not
intended as contribution yet.
Basic idea is:
1. Multiple-agenda buffers can exist at the same time, having separate
tag filters and other such settings. This is accomplished by bunch of
org-agenda-* variables being made buffer-local.
2. Custom agenda commands should bind `org-agenda-buffer-name' variable,
so that for example C-c a generates "*Agenda*" buffer and C-c t
generates "*Todo List*" buffer.
3. org-agenda checks if buffer with `org-agenda-buffer-name' exists
and if it does, it will show that buffer, rather then re-generating
it. To generate a fresh agenda, becomes C-c a r instead of C-c a
4. org-agenda-quit buries the agenda buffer instead of killing it.
5. All of the above shenanigans can be switched on and off by doing
M-x toggle-org-agenda-caching command, its off by default so you have
to turn it on after loading the file.
I had been using this setup for last few days, and it had really been
a blast, returning me to the times when I just started with org-mode,
and information had appeared in milliseconds rather then seconds.
[-- Attachment #2: org-agenda-cache.el --]
[-- Type: application/octet-stream, Size: 5668 bytes --]
;;; org-agenda-cache.el --- Cache agenda buffers instead of regenerating them each time
;; Cached agenda buffers
;;
;; Toggle with M-x toggle-org-agenda-caching
;;
;; If you include `org-agenda-buffer-name' into the list of bound
;; variables for a specific agenda view, then these agenda views
;; will be cached independently each in their own buffer
;;
;; Example setup:
;;
;; (setq org-agenda-custom-commands
;; '(("a" "Agenda and NEXT (priority)"
;; ((agenda ""
;; ((org-agenda-span 'day)))
;; (tags-todo "/!NEXT"
;; ((org-agenda-overriding-header "Next Tasks")
;; (org-agenda-tags-todo-honor-ignore-options t)
;; (org-agenda-todo-ignore-scheduled t)
;; (org-agenda-todo-ignore-deadlines t)
;; (org-tags-match-list-sublevels t)
;; (org-agenda-sorting-strategy
;; '(priority-down category-keep)))))
;; ((org-agenda-buffer-name "*Agenda*")))
;; ("t" "TODO entries"
;; todo ""
;; ((org-agenda-buffer-name "*Todo List*")))))
;;
;; Note that C-c a and C-c t will use two different agenda buffers
;; that are indecent of each other, and each can have different restrictions
;; or tag filter
(defvar org-agenda-use-caching nil
"When non-nil, org-agenda will show existing agenda buffer when
its available and org-agenda-exit will bury the agenda buffer
instead of destroying it. ")
(defun toggle-org-agenda-caching (&optional arg)
(interactive)
(setq org-agenda-use-caching (or arg (not org-agenda-use-caching)))
(message "Agenda caching was %s" (if org-agenda-use-caching "enabled" "disabled")))
(defvar org-agenda-inside-org-agenda nil)
(defvar org-cached-agenda-last-prefix-arg nil)
(defvar org-this-agenda-buffer-name nil)
(dolist (var '(org-cached-agenda-last-prefix-arg
org-this-agenda-buffer-name
org-agenda-redo-command
org-agenda-query-string
org-agenda-tag-filter
org-agenda-tag-filter-overlays
org-agenda-category-filter
org-agenda-columns-active
org-agenda-marker-table
org-agenda-markers
org-agenda-restrict
org-agenda-restrict-begin
org-agenda-overriding-restriction
org-agenda-archives-mode
org-agenda-current-span))
(make-variable-buffer-local var))
(defadvice org-agenda (around cached-agenda-buffer activate)
(if org-agenda-use-caching
(let ((org-agenda-inside-org-agenda t))
(catch 'org-agenda-used-existing-buffer
(setq ad-return-value ad-do-it)))
(setq ad-return-value ad-do-it)))
(defadvice org-agenda-redo (around cached-agenda-buffer activate)
(if org-agenda-use-caching
(let ((org-agenda-buffer-name (or org-this-agenda-buffer-name
org-agenda-buffer-name)))
(setq ad-return-value ad-do-it))
(setq ad-return-value ad-do-it)))
(defadvice org-prepare-agenda (around cached-agenda-buffer activate)
(if org-agenda-use-caching
(if (or (not org-agenda-inside-org-agenda)
org-agenda-multi
(not (get-buffer org-agenda-buffer-name))
(with-current-buffer (get-buffer org-agenda-buffer-name)
(not (equal
current-prefix-arg
org-cached-agenda-last-prefix-arg))))
(progn
(setq ad-return-value ad-do-it)
(with-current-buffer (get-buffer org-agenda-buffer-name)
(setq org-cached-agenda-last-prefix-arg current-prefix-arg)
(setq org-this-agenda-buffer-name org-agenda-buffer-name)))
;; Below block cut-n-paste copied from real `org-prepare-agenda' function
(let* ((abuf (get-buffer-create org-agenda-buffer-name))
(awin (get-buffer-window abuf)))
(cond
((equal (current-buffer) abuf) nil)
(awin (select-window awin))
((not (setq org-pre-agenda-window-conf (current-window-configuration))))
((equal org-agenda-window-setup 'current-window)
(org-pop-to-buffer-same-window abuf))
((equal org-agenda-window-setup 'other-window)
(org-switch-to-buffer-other-window abuf))
((equal org-agenda-window-setup 'other-frame)
(switch-to-buffer-other-frame abuf))
((equal org-agenda-window-setup 'reorganize-frame)
(delete-other-windows)
(org-switch-to-buffer-other-window abuf)))
;; additional test in case agenda is invoked from within agenda
;; buffer via elisp link
(unless (equal (current-buffer) abuf)
(org-pop-to-buffer-same-window abuf))
;; make org-agenda exit early
(throw 'org-agenda-used-existing-buffer nil)))
(setq ad-return-value ad-do-it)))
(defadvice org-agenda-quit (around cached-agenda-buffer activate)
(if org-agenda-use-caching
(org-agenda-bury)
(setq ad-return-value ad-do-it)))
(defun org-agenda-bury ()
"Restore window or frame configuration just like `org-agenda-quit' does
but bury the agenda buffer rather then killing it."
(interactive)
(let ((buf (current-buffer)))
(if (eq org-agenda-window-setup 'other-frame)
(progn
(delete-frame))
(and (not (eq org-agenda-window-setup 'current-window))
(not (one-window-p))
(delete-window)))
(with-current-buffer buf
(bury-buffer))))
(provide 'org-agenda-cache)
[-- Attachment #3: Type: text/plain, Size: 1 bytes --]
next reply other threads:[~2012-01-15 20:23 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-15 19:47 Max Mikhanosha [this message]
2012-01-16 12:18 ` Hack: org-agenda-cache.el Carsten Dominik
2012-01-16 15:40 ` Carsten Dominik
2012-01-16 16:31 ` Max Mikhanosha
2012-01-16 21:48 ` Carsten Dominik
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=87r4z0bveo.wl%max@openchat.com \
--to=max@openchat.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 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).