This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
el-secretario.el
133 lines (111 loc) · 4.16 KB
/
el-secretario.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
;;; el-secretario.el General interface for el-secretario -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2020 Leo
;;
;; Author: Leo Okawa Ericson <http://github/Zetagon>
;; Maintainer: Leo <[email protected]>
;; Created: September 20, 2020
;; Modified: October 17, 2020
;; Version: 0.0.1
;; Keywords:
;; Homepage: https://github.com/Zetagon/el-secretario
;; Package-Requires: ((emacs 26.1) (cl-lib "0.5") (hydra "0.15.0")(org-ql "0.6-pre"))
;;
;; This file is not part of GNU Emacs.
;;
;;; Commentary:
;;
;;
;;
;;; Code:
(require 'hydra)
(require 'org-ql)
(require 'el-secretario-org)
(require 'el-secretario-message)
(require 'el-secretario-notmuch)
(require 'el-secretario-space)
(require 'el-secretario-tasks)
(defvar el-secretario-is-testing nil
"Determines if code is running in testing mode.
When a user is interacting with el-secretario this should always
be nil. Set it to `t' if in testing
")
(defhydra el-secretario-default-hydra ()
("n" el-secretario-next-item "next" :exit t)
("q" (el-secretario-end-sesion) "Quit" :exit t)
("/" nil "disable hydra" :exit t))
(defun el-secretario-activate-hydra ()
(interactive)
(when el-secretario-current-source-list
(funcall (el-secretario-source-hydra-body
(car el-secretario-current-source-list)))))
(cl-defstruct el-secretario-source
init-function
next-function
prev-function
hydra-body
finished-hook
next-item-hook)
(defvar el-secretario-current-source-list nil
"TODO")
(defvar el-secretario-current-source-list-done nil
"TODO")
(defvar el-secretario-status-buffer-name "*el-secretario-status*"
"TODO")
(defvar el-secretario--original-buffer nil
"The buffer the user was in before activating el-secretario.")
(defhydra el-secretario--hydra-quit (:exit t
:foreign-keys run)
("q" (when el-secretario--original-buffer
(switch-to-buffer el-secretario--original-buffer)) "Quit"))
;;;###autoload
(defun el-secretario-start-session (source-list)
(setq el-secretario--original-buffer (current-buffer))
(setq el-secretario-current-source-list source-list)
(with-current-buffer (get-buffer-create "*el-secretario-en*")
(delete-region (point-min) (point-max)))
(funcall (el-secretario-source-init-function (car source-list)))
(el-secretario-status-buffer-activate))
(defun el-secretario-end-sesion ()
(switch-to-buffer el-secretario--original-buffer)
(el-secretario-status-buffer-deactivate))
(defun el-secretario-next-item ()
(interactive)
(when el-secretario-current-source-list
(funcall (el-secretario-source-next-function
(car el-secretario-current-source-list)))))
(defun el-secretario--next-source ()
(if el-secretario-current-source-list
(progn
(push el-secretario-current-source-list-done
(car el-secretario-current-source-list))
(pop el-secretario-current-source-list)
(if el-secretario-current-source-list
(funcall (el-secretario-source-init-function
(car el-secretario-current-source-list)))
(with-current-buffer (get-buffer-create "*el-secretario-en*")
(insert "Done!"))
(switch-to-buffer (get-buffer-create "*el-secretario-en*"))))
(el-secretario-end-sesion)))
(defun el-secretario-status-buffer-activate ()
(el-secretario-status-buffer-deactivate)
(display-buffer-in-side-window (get-buffer-create el-secretario-status-buffer-name)
'((side . top))))
(defun el-secretario-status-buffer-deactivate ()
(-some-> (get-buffer-window el-secretario-status-buffer-name)
(delete-window)))
;;; Utility functions
(defvar el-secretario--y-or-no-p-input-list nil
"The list `el-secretario-y-or-no-p' will take from if in testing mode")
(defun el-secretario--y-or-n-p (prompt)
(if el-secretario-is-testing
(pop el-secretario--y-or-no-p-input-list)
(y-or-n-p prompt)))
;; (let ((el-secretario-is-testing t)
;; (el-secretario--y-or-no-p-input-list '(n n y)))
;; (el-secretario--y-or-n-p "foo")
;; (el-secretario--y-or-n-p "foo")
;; (el-secretario--y-or-n-p "foo")
;; (el-secretario--y-or-n-p "foo"))
(provide 'el-secretario)
;;; el-secretario.el ends here