-
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathpen-brain.el
More file actions
111 lines (94 loc) · 3.74 KB
/
pen-brain.el
File metadata and controls
111 lines (94 loc) · 3.74 KB
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
(require 'org-brain)
(require 'pen-support)
(defun org-brain-current-brain ()
(f-base org-brain-path))
(defun org-brain-parent-name ()
(mapconcat 'identity
(org-brain-remove-irrelevant-names-from-path
(mapcar
'org-brain-name-from-list-maybe
(org-brain-parents org-brain--vis-entry)))
" "))
(defun org-brain-is-index-name (s)
(or (string-equal s "index")
(string-equal s "reference")))
(defun org-brain-pf-topic (&optional short)
"Topic used for pen functions"
(let ((cn (org-brain-current-name t)))
(if (and (org-brain-is-index-name cn)
(not (sor (org-brain-parent-name))))
(if (org-brain-is-index-name (org-brain-current-brain))
"general knowledge"
(org-brain-current-brain))
(let ((p (org-brain-parent-name)))
(if (and (sor p)
(not short)
(not (org-brain-is-index-name p)))
(concat cn " (" cn " is a subtopic of " p ")")
cn)))))
(defun org-brain-show-topic ()
(interactive)
(call-interactively 'pen-topic))
(defun pen-org-brain-current-topic (&optional for-external-searching)
(interactive)
(let ((cname (org-brain-current-name))
(pname (org-brain-parent-name))
(path (mapcar 'org-brain-name-from-list-maybe (append (org-brain-parents org-brain--vis-entry) (list org-brain--vis-entry))))
(topic))
(setq topic
(cond
((org-brain-at-child-of-index) cname)
((org-brain-at-top-index) "general knowledge")
(t "general knowledge")))
(setq path
(if for-external-searching
(org-brain-remove-irrelevant-names-from-path path)
path))
(let ((topic (chomp (apply 'cmd path))))
(if (not (sor topic))
(setq topic "general knowledge"))
(if (interactive-p)
(etv topic)
topic))))
;; TODO Clean this up.
;; I don't want org-template-gen involved.
;; I also don't want to use extensions to org-brain that I have made.
(defun org-brain-describe-topic ()
(interactive)
(let* ((p (sor (org-brain-parent-name)))
(pretext)
(question (if (and p (not (org-brain-at-child-of-index)))
(concat "Could you please explain what " (pen-topic t) " is in the context of " p " and why it is important?")
(concat "Could you please explain what " (pen-topic t) " is and why it is important?")))
(final-question
(if (sor pretext)
(concat pretext " " question)
question)))
(let ((description (org-brain-asktutor final-question)))
(if (sor description)
(progn
(let ((cb (current-buffer)))
(my-org-brain-goto-current)
(let ((block-name (concat (org-brain-current-name) "-description")))
(if (not (org-babel-find-named-block block-name))
(progn
(insert
(snc (cmd "org-template-gen" "brain-description" block-name) description))
(call-interactively 'save-buffer)
(call-interactively 'my/revert-kill-buffer-and-window))))
(with-current-buffer cb
(revert-buffer))))))))
;; TODO Fix this.
;; Replace ttp with a much simpler thing.
;; I want to incorporate spaCy at some point anyway.
(defun org-brain-asktutor (question)
(interactive (list (read-string-hist (concat "asktutor about " (pen-topic) ": "))))
(let ((topic (pen-org-brain-current-topic)))
(let ((answer
(snc "ttp" (pen-pf-generic-tutor-for-any-topic topic question))))
(if (interactive-p)
(etv answer)
answer))))
;; TODO
;; j:org-brain-asktutor
(provide 'pen-brain)