From 818f80db9e4898ecd64d90299194f61751ab9080 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Sun, 11 Jan 2015 22:58:11 -0500 Subject: Decouple Bog search from Org agenda Previously, using bog-search-notes and bog-search-notes-for-citekey clobbered the existing agenda buffer. Make these commands output to a Bog-specific buffer and take care to restore org-lprops after executing. Unfortunately, this still relies heavily on Org agenda internals, but I don't see an obvious way around this. --- bog.el | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/bog.el b/bog.el index 204e8ce..70e9aae 100644 --- a/bog.el +++ b/bog.el @@ -831,16 +831,32 @@ level `bog-refile-maxlevel' are considered." (-map #'car nodir-files)) nodir-files)))) +(defmacro bog--with-search-lprops (&rest body) + "Execute BODY with Bog-related agenda values. +Restore the `org-lprops' property value for +`org-agenda-redo-command' after executing BODY." + (declare (indent 0)) + `(let ((org-lprops (get 'org-agenda-redo-command 'org-lprops)) + (bog-lprops '((org-agenda-buffer-name "*Bog search*") + (org-agenda-files (bog-notes)) + org-agenda-text-search-extra-files + org-agenda-sticky))) + (put 'org-agenda-redo-command 'org-lprops bog-lprops) + (org-let bog-lprops ,@body) + (use-local-map (let ((map (make-sparse-keymap))) + (set-keymap-parent map org-agenda-mode-map) + (define-key map "r" 'bog-agenda-redo) + map)) + (put 'org-agenda-redo-command 'org-lprops org-lprops))) + (defun bog-search-notes (&optional todo-only string) "Search notes using `org-search-view'. With prefix argument TODO-ONLY, search only TODO entries. If STRING is non-nil, use it as the search term (instead of prompting for one)." (interactive "P") - (let ((lprops '((org-agenda-files (bog-notes)) - (org-agenda-text-search-extra-files nil)))) - (put 'org-agenda-redo-command 'org-lprops lprops) - (org-let lprops '(org-search-view todo-only string)))) + (bog--with-search-lprops + '(org-search-view todo-only string))) (defun bog-search-notes-for-citekey (&optional todo-only) "Search notes for citekey using `org-search-view'. @@ -854,6 +870,11 @@ not found, prompt with citekeys present in any note file." (bog-search-notes todo-only (bog-citekey-from-surroundings-or-all nil))) +(defun bog-agenda-redo (&optional all) + (interactive "P") + (bog--with-search-lprops + '(org-agenda-redo all))) + (defun bog-sort-topic-headings-in-buffer (&optional sorting-type) "Sort topic headings in this buffer. SORTING-TYPE is a character passed to `org-sort-entries'. If -- cgit v1.2.3