changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > core / emacs/lib/graph.el

changeset 623: a304c9713a51
child: 6c0e4a44c082
author: Richard Westhaver <ellis@rwest.io>
date: Sun, 25 Aug 2024 00:14:17 -0400
permissions: -rw-r--r--
description: init graph.el
1 ;;; graph.el --- Graph-oriented Extensions -*- lexical-binding: t; -*-
2 
3 ;; Copyright (C) 2024 The Compiler Company
4 ;; Version: "0.2.0"
5 ;; Author: Richard Westhaver <richard.westhaver@gmail.com>
6 ;; Keywords: docs, maint, outlines, extensions
7 
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
12 
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
17 
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
20 
21 ;;; Commentary:
22 
23 ;;
24 
25 ;;; Code:
26 (require 'org)
27 (require 'org-agenda)
28 (require 'default)
29 (require 'ulang)
30 
31 (defgroup graph nil
32  "CC Graph")
33 
34 (defcustom org-graph-db-directory (join-paths user-org-stash-directory "graph")
35  "graph database storage directory."
36  :type 'directory
37  :group 'graph)
38 
39 (defcustom org-graph-locations (list (join-paths company-org-directory "notes"))
40  "List of directories to check for nodes."
41  :type '(list directory)
42  :group 'graph)
43 
44 (defcustom org-graph-include-agenda-files nil
45  "When non-nil, include `org-agenda-files' in the graph."
46  :type 'boolean
47  :group 'graph)
48 
49 (defcustom org-graph-include-archive nil
50  "When non-nil, include `org-arhive-location' in the graph."
51  :type 'boolean
52  :group 'graph)
53 
54 (defcustom org-graph-include-org-directory nil
55  "When non-nil, include `org-directory' files in the graph."
56  :type 'boolean
57  :group 'graph)
58 
59 (defcustom org-graph-compaction-hook nil
60  "Hook run when a graph is compacted to `org-graph-db'."
61  :type 'hook
62  :group 'graph)
63 
64 (defcustom org-graph-capture-hook nil
65  "Hook run when a node is added to the graph."
66  :type 'hook
67  :group 'graph)
68 
69 (defvar-local org-graph nil
70  "The currently active graph of org nodes.")
71 
72 (defcustom org-graph-db-init-script (join-paths company-source-directory "infra/scripts/org-db-init.lisp")
73  "Path to a lisp script responsible for initializing the `org-graph-db-directory'.")
74 
75 (cl-defstruct org-graph-db-handle
76  (type :rocksdb)
77  (name "org-graph-db")
78  get
79  put
80  delete
81  merge
82  compact
83  shutdown)
84 
85 (defcustom org-graph-db (make-org-graph-db-handle)
86  "A handle to the database backend which stores nodes and edges."
87  :type 'org-graph-db-handle
88  :group 'graph)
89 
90 (defun org-graph-from-id-locations ()
91  "Populate the `org-graph' from `org-id-locations', filtering out any
92 entries not under a member of `org-graph-locations'."
93  (setq-local org-graph (copy-hash-table (org-id-locations-load)))
94  (maphash
95  (lambda (k v)
96  (mapc
97  (lambda (x)
98  (unless (string-prefix-p x (file-truename v))
99  (remhash k org-graph)))
100  org-graph-locations))
101  org-graph))
102 
103 (provide 'graph)
104 ;; graph.el ends here
105