2021-03-26 04:20:04 +01:00
|
|
|
|
;;; oni-org-roam.el --- Configuration for org-roam -*- lexical-binding: t; -*-
|
|
|
|
|
|
|
|
|
|
;; Copyright (C) 2021 Tom Willemse
|
|
|
|
|
|
|
|
|
|
;; Author: Tom Willemse <tom@ryuslash.org>
|
|
|
|
|
;; Keywords: local
|
2024-02-15 21:58:02 +01:00
|
|
|
|
;; Version: 2024.0212.234817
|
2021-09-24 10:14:05 +02:00
|
|
|
|
;; Package-Requires: (oni-org org-roam)
|
2021-03-26 04:20:04 +01:00
|
|
|
|
|
|
|
|
|
;; 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:
|
|
|
|
|
|
2021-07-20 10:15:47 +02:00
|
|
|
|
;; Configuration specific to ‘org-roam’. Add the following to your init file if
|
|
|
|
|
;; you want to use this configuration:
|
|
|
|
|
;;
|
|
|
|
|
;; (with-eval-after-load 'org-roam (require 'oni-org-roam))
|
2021-03-26 04:20:04 +01:00
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
|
|
(require 'org-roam)
|
2021-11-17 06:38:33 +01:00
|
|
|
|
(require 'seq)
|
2021-03-26 04:20:04 +01:00
|
|
|
|
|
2021-09-24 10:14:05 +02:00
|
|
|
|
(setq org-roam-completion-everywhere t)
|
2024-02-15 21:57:14 +01:00
|
|
|
|
(setq org-roam-directory (expand-file-name "~/documents/exocortex-novus/reference/"))
|
2022-01-04 07:57:27 +01:00
|
|
|
|
|
|
|
|
|
(add-hook 'org-roam-mode-hook 'visual-line-mode)
|
|
|
|
|
|
2021-09-24 10:14:05 +02:00
|
|
|
|
(mkdir org-roam-directory t)
|
2021-03-26 04:20:04 +01:00
|
|
|
|
|
2022-09-22 08:43:07 +02:00
|
|
|
|
(defun oni-org-roam-auto-toggle-roam-buffer (&optional _)
|
|
|
|
|
"Show the ‘org-roam-buffer' if the current buffer is part of Roam."
|
|
|
|
|
(if (or (string-prefix-p org-roam-directory (buffer-file-name))
|
|
|
|
|
(string= (buffer-name) org-roam-buffer))
|
|
|
|
|
(unless (get-buffer-window org-roam-buffer)
|
|
|
|
|
(org-roam-buffer-toggle))
|
|
|
|
|
(when (and (get-buffer-window org-roam-buffer)
|
|
|
|
|
(not (window-minibuffer-p)))
|
|
|
|
|
(org-roam-buffer-toggle))))
|
|
|
|
|
|
2023-03-26 06:40:39 +02:00
|
|
|
|
(defun oni-org-roam--books-to-read ()
|
2023-08-01 20:02:56 +02:00
|
|
|
|
(org-roam-db-query (concat "select properties, file, title, group_concat(tag) as node_tags "
|
|
|
|
|
"from nodes "
|
|
|
|
|
"left join tags on node_id=id "
|
|
|
|
|
"group by id "
|
|
|
|
|
"having node_tags like '%%\"book\"%%' "
|
|
|
|
|
"and node_tags like '%%\"unread\"%%' "
|
|
|
|
|
"order by title")))
|
2023-03-26 06:40:39 +02:00
|
|
|
|
|
|
|
|
|
(defun oni-org-roam-list-books-to-read ()
|
|
|
|
|
(interactive)
|
|
|
|
|
(let ((buffer (get-buffer-create "*books-to-read*")))
|
|
|
|
|
(with-current-buffer buffer
|
|
|
|
|
(erase-buffer)
|
2023-03-26 07:33:29 +02:00
|
|
|
|
(save-excursion
|
|
|
|
|
(mapc (lambda (item) (insert "- [["(cadr item) "]["
|
|
|
|
|
(caddr item) "]]\n"))
|
|
|
|
|
(oni-org-roam--books-to-read))
|
2023-03-31 07:26:59 +02:00
|
|
|
|
(org-mode)
|
|
|
|
|
(view-mode)))
|
2023-03-26 06:40:39 +02:00
|
|
|
|
(switch-to-buffer buffer)))
|
|
|
|
|
|
|
|
|
|
(defun oni-org-roam-random-book-to-read ()
|
|
|
|
|
(interactive)
|
|
|
|
|
(find-file (cadr (seq-random-elt (oni-org-roam--books-to-read)))))
|
|
|
|
|
|
2022-11-23 08:14:44 +01:00
|
|
|
|
(add-to-list 'display-buffer-alist
|
|
|
|
|
`(,(rx string-start "*org-roam*" string-end)
|
|
|
|
|
display-buffer-in-side-window
|
|
|
|
|
(side . right)
|
|
|
|
|
(slot . 0)
|
|
|
|
|
(window-width . 66)))
|
|
|
|
|
|
2022-01-04 07:57:55 +01:00
|
|
|
|
;;; These two properties are used a lot when working in ‘org-roam'. ‘ROAM_REFS'
|
|
|
|
|
;;; is used to specify a URL that (if pointed to) should be considered a
|
|
|
|
|
;;; reference to a particular note. ‘ROAM_ALIASES' sets up additional names for
|
|
|
|
|
;;; a note.
|
|
|
|
|
(add-to-list 'org-default-properties "ROAM_REFS")
|
|
|
|
|
(add-to-list 'org-default-properties "ROAM_ALIASES")
|
|
|
|
|
|
2021-09-24 10:14:05 +02:00
|
|
|
|
;;;###autoload
|
|
|
|
|
(setq org-roam-v2-ack t)
|
2021-03-26 04:20:04 +01:00
|
|
|
|
|
2023-03-26 08:16:15 +02:00
|
|
|
|
(setq org-roam-node-display-template
|
|
|
|
|
(concat "${title:*} "
|
|
|
|
|
(propertize "${tags:10}" 'face 'org-tag)))
|
|
|
|
|
|
2023-03-31 07:26:41 +02:00
|
|
|
|
;; Only display unique references in the org-roam buffer.
|
|
|
|
|
(setq org-roam-mode-sections
|
|
|
|
|
(cons '(org-roam-backlinks-section :unique t)
|
|
|
|
|
(delete 'org-roam-backlinks-section org-roam-mode-sections)))
|
|
|
|
|
|
2024-02-15 21:58:02 +01:00
|
|
|
|
;; Show only the current element, not the whole heading for the org-roam-buffer
|
|
|
|
|
;; preview.
|
|
|
|
|
(defun oni-org-roam-preview-element-function ()
|
|
|
|
|
(let ((element (org-element-at-point)))
|
|
|
|
|
(buffer-substring-no-properties (org-element-property :begin element)
|
|
|
|
|
(org-element-property :end element))))
|
|
|
|
|
|
|
|
|
|
(setq org-roam-preview-function #'oni-org-roam-preview-element-function)
|
|
|
|
|
|
2021-10-29 05:00:02 +02:00
|
|
|
|
(org-roam-db-autosync-mode)
|
|
|
|
|
|
2021-03-26 04:20:04 +01:00
|
|
|
|
(provide 'oni-org-roam)
|
|
|
|
|
;;; oni-org-roam.el ends here
|