summaryrefslogtreecommitdiff
path: root/suweren/home/emacs-roam.el
blob: 4e0673ddd106cba6ba8b0bfcd59b6e43c769a978 (plain)
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
(require 'org-roam)

(defun org-roam-db-query-tasks ()
  (concat "The query constructor to receive a list of files with tasks.")
  (org-roam-db-query [:select
		      :distinct [file]
		      :from nodes
		      :where (like todo "TODO")
		      :or (like todo "DONE")]))

(defun org-roam-dailies-with-tasks ()
  (concat "List of distinct Org Roam files with tasks,\n"
	  "obtained with Roam’s SQLite database query.\n"
	  "\n"
	  "The application of append is necessary to unpack the query result.")
  (apply 'append
	 (funcall #'org-roam-db-query-tasks)))

(defvar org-roam-merged-agenda-files
  (append org-agenda-files
	  (org-roam-dailies-with-tasks))
  (concat "List of Roam’s agenda files merged with agenda files set earlier."))

(defun org-roam-update-agenda-files (&rest _)
  (concat "Refresh the list of agenda files before opening the agenda.")
  (setq org-agenda-files (org-roam-dailies-with-tasks)))

(use-package org-roam
  :init
  (setq org-roam-v2-ack t)

  :config
  (require 'org-roam-dailies)
  (org-roam-db-autosync-mode)
  (advice-add 'org-agenda
	      :before
	      #'org-roam-update-agenda-files)
  (advice-add 'org-todo-list
	      :before
	      #'org-roam-update-agenda-files)

  :bind
  (("C-c n f" . org-roam-node-find)
   ("C-c n i" . org-roam-node-insert)
   ("C-c n l" . org-roam-buffer-toggle)
   :map
   org-roam-dailies-map
   ("T" . org-roam-dailies-capture-tomorrow)
   ("Y" . org-roam-dailies-capture-yesterday))

  :bind-keymap
  ("C-c n d" . org-roam-dailies-map)

  :custom
  (org-roam-directory "~/Dokumenty/Baza")
  (org-roam-dailies-directory "Dziennik/")
  (org-roam-capture-templates '(("d" "default" plain "%?"
				 :target (file+head "${slug}.org"
						    "#+title: ${title}\n")
				 :unnarrowed t)))

  :ensure t)