-
Notifications
You must be signed in to change notification settings - Fork 0
/
oca.el
78 lines (58 loc) · 2.44 KB
/
oca.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
;;; oca.el --- Org Capture for non Org storage -*- lexical-binding: t; -*-
;; Copyright (c) 2021 Abhinav Tushar
;; Author: Abhinav Tushar <[email protected]>
;; Version: 0.0.1
;; Package-Requires: ((emacs "27"))
;; URL: https://github.com/lepisma/oca
;;; Commentary:
;; Org Capture for non Org storage
;; This file is not a part of GNU Emacs.
;;; License:
;; 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 <https://www.gnu.org/licenses/>.
;;; Code:
(require 'org)
(defvar-local oca-push-function nil
"Function taking the parsed Org entry and pushing to the final
destination. This is set locally by the oca function while
capturing.")
(defcustom oca-buffer-prefix "oca-"
"Prefix for oca-buffer names.")
(defun oca-visit (push-function)
"Visiting function for capturing."
(find-file (make-temp-file oca-buffer-prefix))
(erase-buffer)
(org-mode)
(setq-local oca-push-function push-function))
(defun oca--buffer-p (buffer)
(string-prefix-p oca-buffer-prefix (buffer-name buffer)))
(defun oca-prepare-finalize-fn ()
"Function to be added to `org-capture-prepare-finalize-hook'.
This runs the buffer-local push function first item parsed from
`org-element-parse-buffer'."
(if (null oca-push-function)
(error "`oca-push-function' not set for the current buffer.")
(funcall oca-push-function (car (org-element-contents (org-element-parse-buffer))))))
(defun oca-after-finalize-fn ()
"Cleanup function to be added to `org-capture-after-finalize-hook'."
(dolist (buf (buffer-list))
(when (oca--buffer-p buf)
(kill-buffer buf))))
(defun oca-push-message (element)
"Simple push function to print the element."
(print element))
;;;###autoload
(defun oca-setup ()
"Set up hooks needed for oca to work."
(add-hook 'org-capture-prepare-finalize-hook #'oca-prepare-finalize-fn)
(add-hook 'org-capture-after-finalize-hook #'oca-after-finalize-fn))
(provide 'oca)
;;; oca.el ends here