(feat): upgrade org-roam-graph-exclude-matcher to accept a list (#296)

Closes #295
This commit is contained in:
Jethro Kuan
2020-03-14 01:17:32 +08:00
committed by GitHub
parent d28a83c992
commit 486ba9c5a8
3 changed files with 63 additions and 19 deletions

View File

@@ -8,6 +8,7 @@
* [#284][gh-284], [#289][gh-289] Configurable `org-roam-completion-system` with options `'default`, `'ido`, `'ivy` and `'helm`. * [#284][gh-284], [#289][gh-289] Configurable `org-roam-completion-system` with options `'default`, `'ido`, `'ivy` and `'helm`.
* [#289][gh-289] Add customizable `org-roam-fuzzy-match` to allow fuzzy-matching of candidates * [#289][gh-289] Add customizable `org-roam-fuzzy-match` to allow fuzzy-matching of candidates
* [#290][gh-290] Add `org-roam-date-title-format` and `org-roam-date-filename-format` for customizing Org-roam's date files * [#290][gh-290] Add `org-roam-date-title-format` and `org-roam-date-filename-format` for customizing Org-roam's date files
* [#296][gh-296] Allow multiple exclusion matchers in `org-roam-graph-exclude-matcher`
## Bugfixes ## Bugfixes
* [#293][gh-293] Fix capture templates not working as expected for `org-roam-find-file` * [#293][gh-293] Fix capture templates not working as expected for `org-roam-find-file`
@@ -141,6 +142,7 @@ Mostly a documentation/cleanup release.
[gh-289]: https://github.com/jethrokuan/org-roam/pull/289 [gh-289]: https://github.com/jethrokuan/org-roam/pull/289
[gh-290]: https://github.com/jethrokuan/org-roam/pull/290 [gh-290]: https://github.com/jethrokuan/org-roam/pull/290
[gh-293]: https://github.com/jethrokuan/org-roam/pull/293 [gh-293]: https://github.com/jethrokuan/org-roam/pull/293
[gh-296]: https://github.com/jethrokuan/org-roam/pull/296
# Local Variables: # Local Variables:
# eval: (auto-fill-mode -1) # eval: (auto-fill-mode -1)

View File

@@ -115,15 +115,28 @@ SVG, you may choose to set it to any compatible program:
(setq org-roam-graph-viewer "/path/to/image-viewer") (setq org-roam-graph-viewer "/path/to/image-viewer")
``` ```
### Excluding Nodes and Edges
One may want to exclude certain files to declutter the graph. You can do so by setting `org-roam-graph-exclude-matcher`.
```
(setq org-roam-graph-exclude-matcher '("private" "dailies"))
```
This setting excludes all files whose path contain "private" or "dailies".
## Org-roam Completion System ## Org-roam Completion System
Org-roam offers completion when choosing note titles etc. Org-roam offers completion when choosing note titles etc.
The completion system is configurable. The default setting, The completion system is configurable. The default setting,
``` ```
(setq org-roam-completion-system 'default) (setq org-roam-completion-system 'default)
``` ```
uses Emacs' standard `completing-read`. If you prefer [Helm](https://emacs-helm.github.io/helm/), use uses Emacs' standard `completing-read`. If you prefer [Helm](https://emacs-helm.github.io/helm/), use
``` ```
(setq org-roam-completion-system 'helm) (setq org-roam-completion-system 'helm)
``` ```
Other options included `'ido`, and `'ivy'`.

View File

@@ -1222,10 +1222,17 @@ Example:
:group 'org-roam) :group 'org-roam)
(defcustom org-roam-graph-exclude-matcher nil (defcustom org-roam-graph-exclude-matcher nil
"String for excluding nodes from the generated graph. "Matcher for excluding nodes from the generated graph.
Any nodes and links for file paths matching this string is Any nodes and links for file paths matching this string is
excluded from the graph." excluded from the graph.
:type 'string
If value is a string, the string is the only matcher.
If value is a list, all file paths matching any of the strings
are excluded."
:type '(choice
(string :tag "Matcher")
(list :tag "Matchers"))
:group 'org-roam) :group 'org-roam)
(defcustom org-roam-graph-node-shape "ellipse" (defcustom org-roam-graph-node-shape "ellipse"
@@ -1234,6 +1241,34 @@ excluded from the graph."
:group 'org-roam) :group 'org-roam)
;;;; Functions ;;;; Functions
(defmacro org-roam--graph-expand-matcher (col &optional negate where)
"Return the exclusion regexp from `org-roam-graph-exclude-matcher'.
COL is the symbol to be matched against. if NEGATE, add :not to sql query.
set WHERE to true if WHERE query already exists."
(declare (indent 0) (debug t))
(let ((matchers (cond ((null org-roam-graph-exclude-matcher)
nil)
((stringp org-roam-graph-exclude-matcher)
(cons (concat "%" org-roam-graph-exclude-matcher "%") nil))
((listp org-roam-graph-exclude-matcher)
(mapcar (lambda (m)
(concat "%" m "%"))
org-roam-graph-exclude-matcher))
(t
(error "Invalid org-roam-graph-exclude-matcher"))))
res)
(dolist (match matchers)
(if where
(push :and res)
(push :where res)
(setq where t))
(push col res)
(when negate
(push :not res))
(push :like res)
(push match res))
(cons 'list (nreverse res))))
(defun org-roam--build-graph () (defun org-roam--build-graph ()
"Build the Graphviz string. "Build the Graphviz string.
The Org-roam database titles table is read, to obtain the list of titles. The Org-roam database titles table is read, to obtain the list of titles.
@@ -1241,22 +1276,16 @@ The file-links table is then read to obtain all directed links, and formatted
into a digraph." into a digraph."
(org-roam--db-ensure-built) (org-roam--db-ensure-built)
(org-roam--with-temp-buffer (org-roam--with-temp-buffer
(let* ((matcher (concat "%" org-roam-graph-exclude-matcher "%")) (let* ((re (org-roam--graph-get-exclude-regexp))
(nodes (if org-roam-graph-exclude-matcher (node-query `[:select [file titles]
(org-roam-sql [:select [file titles]
:from titles :from titles
:where file :not :like $s1] ,@(org-roam--graph-expand-matcher 'file t)])
matcher) (nodes (org-roam-sql node-query))
(org-roam-sql [:select [file titles] (edges-query `[:select :distinct [file-to file-from]
:from titles])))
(edges (if org-roam-graph-exclude-matcher
(org-roam-sql [:select :distinct [file-to file-from]
:from file-links :from file-links
:where file-to :not :like $s1 ,@(org-roam--graph-expand-matcher 'file-to t)
:and file-from :not :like $s1] ,@(org-roam--graph-expand-matcher 'file-from t t)])
matcher) (edges (org-roam-sql edges-query)))
(org-roam-sql [:select :distinct [file-to file-from]
:from file-links]))))
(insert "digraph \"org-roam\" {\n") (insert "digraph \"org-roam\" {\n")
(dolist (option org-roam-graphviz-extra-options) (dolist (option org-roam-graphviz-extra-options)
(insert (concat (car option) (insert (concat (car option)