-
Notifications
You must be signed in to change notification settings - Fork 1
/
org-verse-capture.el
93 lines (73 loc) · 3.14 KB
/
org-verse-capture.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
;;; org-verse-capture.el --- Capture functionality -*- lexical-binding: t; -*-
;; Copyright (C) 2022 Matthias David
;; Author: Matthias David <darkbuffalo@gnu.re>
;; ______ __ _______ ___ ___ __
;; | _ \ .---.-.----| |--| _ .--.--.’ _.’ _.---.-| .-----.
;;^_/-...-\_^ | \| _ | _| <|. 1 | | | _| _| _ | | _ |
;;\__/> o\__/ | |___._|__| |__|__|. _ |_____|__| |__| |___._|__|_____|
;; \ / |: 1 / |: 1 \
;; (^_^) |::.. . / |::.. . /
;; ‘------’ ‘-------’
;; 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/>.
;;; Commentary:
;;
;;; Code:
(require 'org-verse)
(defun org-verse-note-f ()
"Define capture file."
(expand-file-name "notes.org" org-verse-directory))
(defun add-org-capture-templates (capture-templates)
"Add capture from CAPTURE-TEMPLATES."
(setq org-capture-templates
(append org-capture-templates
capture-templates)))
(defun capture-get-destination-headline ()
"Fonction de capture."
(let* ((buf (org-capture-get :original-buffer))
(headline (buffer-local-value 'org-verse-current-verse buf))
(file (find-file (org-verse-note-f))))
(switch-to-buffer file)
(if (string= headline nil) ;;appel de org-capture en dehors du sidebar
(org-verse-search-headline (org-verse-complete))
(org-verse-search-headline headline))))
(defun org-verse-search-headline (headline)
"Create headline from HEADLINE."
(goto-char (point-min))
(if (re-search-forward (format org-complex-heading-regexp-format
(regexp-quote headline))
nil t)
(beginning-of-line)
(goto-char (point-max))
(unless (bolp) (insert "\n"))
(insert "* " headline "\n")
(beginning-of-line 0)))
(add-org-capture-templates
(doct `(("Org Verse" :keys "v"
:file org-verse-note-f
:function capture-get-destination-headline
:type entry
:children (("Org verse note"
:keys "n"
:template ("* %?")))))))
(defun org-verse-capture ()
"Capture verse."
(interactive)
(org-capture nil "vn"))
;; fix error org-capture with sidebar
(defun my-org-capture-place-template-dont-delete-windows (oldfun &rest args)
"Dont delete sidebar when capture. OLDFUN and ARGS are requis."
(cl-letf (((symbol-function 'delete-other-windows) 'ignore))
(apply oldfun args)))
(with-eval-after-load "org-capture"
(advice-add 'org-capture-place-template :around 'my-org-capture-place-template-dont-delete-windows))
(provide 'org-verse-capture)
;;; org-verse-capture.el ends here