-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproctor-org.el
executable file
·90 lines (69 loc) · 3.25 KB
/
proctor-org.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
;;; proctor-org.el --- ERT support for Org mode -*- lexical-binding: t; -*-
;; Copyright (C) 2016 Aaron Harris
;; Author: Aaron Harris <[email protected]>
;; Keywords: tools, lisp
;; Dependencies: `proctor', `bfw', `org-capture'
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This module contains macros and functions designed for testing
;; commands for use in and relating to `org-mode'.
;;; Code:
(require 'proctor)
(require 'bfw)
(require 'org-capture)
;;;; Agenda
;;=========
(defcustom proctor-org-temp-agenda-file
(expand-file-name "temp.org" proctor-directory)
"Path to temp agenda file for `proctor-org-with-agenda-items'.
This should be an absolute path."
:group 'proctor
:type 'string)
(defun proctor-org-list-agendas ()
"Return a list of all agenda buffers currently open.
By design, an agenda buffer that has been protected with
`ert-with-buffer-renamed' (or `proctor-with-buffer-renamed',
etc.) is not included in this list (although
`ert-with-buffer-renamed' does create a different buffer with the
original name, and that buffer is included)."
(bfw-get-buffers-by-regexp "^[*]Org Agenda.*[*]$"))
(defmacro proctor-org-with-agenda-items (items &rest body)
"Evaluate BODY with temporary `org-mode' agenda ITEMS.
Create a temporary agenda file (`proctor-org-temp-agenda-file')
containing ITEMS, to be used in place of `org-agenda-files'.
Then evaluate BODY, and delete the agenda file afterwards. Also
kill any agenda buffers that were created inside BODY.
ITEMS should be a string or a list of strings; in the latter
case, the elements are concatenated, separated by newlines.
All %-escapes that are valid in capture templates are then
expanded, although many of those don't make sense outside of the
capture process; at the present time, the only escapes that have
been tested and are known to work as expected are the timestamp
escapes (%t, %T, %u, and %U).
Care is taken to insulate the BODY environment from the user's
default Org setup. In particular, all currently open agendas are
preserved using `proctor-with-buffers-renamed'."
(declare (indent 1)
(debug ([&or stringp (&rest stringp)] body)))
(when (listp items)
(setq items (mapconcat #'identity items "\n")))
`(let ((org-agenda-files
(list proctor-org-temp-agenda-file))
org-capture-plist)
(proctor-with-file proctor-org-temp-agenda-file
(org-capture-fill-template ,items)
(proctor-with-buffers-renamed
(mapcar #'buffer-name (proctor-org-list-agendas))
(unwind-protect (progn ,@body)
(mapcar #'bfw-kill-buffer-if-any (proctor-org-list-agendas)))))))
(provide 'proctor-org)
;;; proctor-org.el ends here