(ehancement): Improve org-roam-graph (#559)

Allow showing/building the whole graph from any buffer.
Allow programatically specifying connected component path.
This commit is contained in:
N V
2020-05-03 18:03:02 -04:00
committed by GitHub
parent 69d4f05a13
commit 1bbfb0cdc9

View File

@ -271,15 +271,16 @@ ARG may be any of the following values:
- `\\[universal-argument]' - build the graph for FILE. - `\\[universal-argument]' - build the graph for FILE.
- `\\[universal-argument]' -N build the graph for FILE limiting nodes to N steps." - `\\[universal-argument]' -N build the graph for FILE limiting nodes to N steps."
(interactive "P") (interactive "P")
(let ((file (or file (buffer-file-name)))) (let ((file (or file (buffer-file-name (buffer-base-buffer)))))
(unless file (unless (or (not arg) (equal arg '(16)))
(user-error "Cannot build graph for nil file. Is current buffer visiting a file?")) (unless file
(unless (org-roam--org-roam-file-p file) (user-error "Cannot build graph for nil file. Is current buffer visiting a file?"))
(user-error "\"%s\" is not an org-roam file" file)) (unless (org-roam--org-roam-file-p file)
(user-error "\"%s\" is not an org-roam file" file)))
(pcase arg (pcase arg
('nil (org-roam-graph--open (org-roam-graph--build node-query))) ('nil (org-roam-graph--open (org-roam-graph--build node-query)))
('(4) (org-roam-graph--open (org-roam-graph--build-connected-component file))) ('(4) (org-roam-graph--open (org-roam-graph--build-connected-component file)))
((pred integerp) (let ((graph (org-roam-graph--build-connected-component (buffer-file-name) (abs arg)))) ((pred integerp) (let ((graph (org-roam-graph--build-connected-component file (abs arg))))
(when (>= arg 0) (when (>= arg 0)
(org-roam-graph--open graph)))) (org-roam-graph--open graph))))
('(16) (org-roam-graph--build node-query)) ('(16) (org-roam-graph--build node-query))