-
Notifications
You must be signed in to change notification settings - Fork 4
/
guess-word-org.el
47 lines (43 loc) · 1.64 KB
/
guess-word-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
(require 'org)
(require 'outline)
(defcustom guess-word-org-file
(f-expand "./guess-word.org" (file-name-directory (f-this-file)))
"guess-word output org file"
:group 'guess-word
:type 'file
)
(defun guess-word-current-buffer-to-org (word)
"Save current word to org file"
(let (
(content (buffer-substring-no-properties (point-min) (point-max)))
(headlines (make-hash-table :test 'equal))
)
(with-current-buffer
(find-file-noselect guess-word-org-file nil nil)
(org-mode)
(let ((ast (org-element-parse-buffer))
(done nil))
(org-element-map ast 'headline
(lambda (ele)
(let ((headlinetext (car (plist-get (plist-get ele 'headline) ':title)))
(content-region (plist-get ele 'headline))
(hasset nil))
(when (equal word headlinetext)
(save-excursion
(narrow-to-region (plist-get content-region ':begin) (plist-get content-region ':end))
(org-element-set-contents ele content)
(org-element-set-element ele (org-element-put-property ele :todo-keyboard "DONE"))
(delete-region (point-min) (point-max))
(goto-char (point-min))
(insert (org-element-interpret-data ele))
(widen))
(setq done t)
))))
(unless done
(goto-char (point-max))
(insert (format "\n* TODO %s \n %s" word content)))
(save-buffer)
(goto-char (point-max))
(current-buffer)))))
(provide 'guess-word-org)
;;; guess-word-org ends here . xx