-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathorg-project-capture-backend.el
88 lines (62 loc) · 3.01 KB
/
org-project-capture-backend.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
;;; org-project-capture-backend.el --- Repository todo capture and management for org-mode -*- lexical-binding: t; -*-
;; Copyright (C) 2023 Ivan Malison
;; 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/>.
;; Version: 3.1.1
;;; Commentary:
;; An interface for defining backends for org-project-capture.
;;; Code:
(require 'cl-lib)
(require 'eieio)
(require 'project)
(defun org-project-capture-category-from-project-root (project-root)
(when project-root
(file-name-nondirectory (directory-file-name project-root))))
(defclass org-project-capture-backend nil nil :abstract t)
(cl-defmethod org-project-capture-get-all-project-paths
((_backend org-project-capture-backend)))
(cl-defmethod org-project-capture-switch-to-project
((_backend org-project-capture-backend) _directory))
(cl-defmethod org-project-capture-project-root-of-filepath
((_backend org-project-capture-backend) _filepath))
(cl-defmethod org-project-capture-current-project
((_backend org-project-capture-backend)))
(cl-defmethod org-project-capture-build-category-to-project-path
((backend org-project-capture-backend))
(mapcar
(lambda (path)
(cons (org-project-capture-category-from-project-root path) path))
(org-project-capture-get-all-project-paths backend)))
(cl-defmethod org-project-capture-category-from-file
((backend org-project-capture-backend) filepath)
(org-project-capture-category-from-project-root
(org-project-capture-project-root-of-filepath backend filepath)))
(cl-defmethod org-project-capture-get-all-categories
((backend org-project-capture-backend))
(mapcar 'org-project-capture-category-from-project-root
(org-project-capture-get-all-project-paths backend)))
;; project.el backend
(defclass org-project-capture-project-backend (org-project-capture-backend) nil)
(cl-defmethod org-project-capture-get-all-project-paths
((_ org-project-capture-project-backend))
(project-known-project-roots))
(cl-defmethod org-project-capture-project-root-of-filepath
((_ org-project-capture-project-backend) filepath)
(cdr (project-current nil filepath)))
(cl-defmethod org-project-capture-switch-to-project
((_ org-project-capture-project-backend) directory)
(when directory
(project-switch-project directory)))
(cl-defmethod org-project-capture-current-project
((_backend org-project-capture-project-backend))
(project-current))
(provide 'org-project-capture-backend)
;;; org-project-capture-backend.el ends here