Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add follow method: local or global #50

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,15 @@ Org-Roam-UI exposes a few variables, but most of the customization is done in th

#### Following

ORUI follows you around Emacs by default. To disable this, set
ORUI follows you around Emacs in a local view by default.

If you want to roam in a global graph, set

```emacs-lisp
(setq org-roam-ui-follow-method 'global)
```

To disable this, set

```emacs-lisp
(setq org-roam-ui-follow nil)
Expand Down Expand Up @@ -212,7 +220,7 @@ While we try to optimize the display of the graph, there is only so much we can

As much as it saddens us to say, Firefox's rendering engine is quite a bit slower than its Chromium cousins. Compare the performance of the two and see if that's the main issue first.

#### Turn of the particles
#### Turn off the particles

I know, very cool to see those little guys travel up and down your notes, but very slow, especially in 3D mode.

Expand Down
24 changes: 23 additions & 1 deletion org-roam-ui.el
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
(require 'org-roam)
(require 'websocket)

;;;; Customization
(defgroup org-roam-ui nil
"UI in Org-roam."
:group 'org-roam
Expand Down Expand Up @@ -91,6 +92,14 @@ E.g. '((bg . \"#1E2029\")
:group 'org-roam-ui
:type 'boolean)

(defcustom org-roam-ui-follow-method 'local
"The display method of follow-mode.
When equals `local', follow the node in a local view,
when equals `global', focus on the node in the global graph."
:type '(choice
(const :tag "Local" local)
(const :tag "Global" global)))

(defcustom org-roam-ui-update-on-save t
"If true, org-roam-ui will send new data when you save an org-roam-buffer.
This can lead to some jank."
Expand Down Expand Up @@ -249,8 +258,15 @@ loaded. Returns `ref' if an entry could not be found."
(tags . ,(seq-mapcat #'seq-reverse (org-roam-db-query [:select :distinct tag :from tags]))))))
(websocket-send-text oru-ws (json-encode `((type . "graphdata") (data . ,response))))))


(defun org-roam-ui--update-current-node ()
"Focus on the current node in the graph."
(cond
((eq org-roam-ui-follow-method 'local)
(org-roam-ui--update-current-node-local))
((eq org-roam-ui-follow-method 'global)
(org-roam-ui--update-current-node-global))))

(defun org-roam-ui--update-current-node-global ()
"Send the current node data to the web-socket."
(when (and (websocket-openp oru-ws) (org-roam-buffer-p) (file-exists-p (buffer-file-name)))
(let* ((node (org-roam-id-at-point)))
Expand All @@ -259,6 +275,12 @@ loaded. Returns `ref' if an entry could not be found."
(websocket-send-text oru-ws (json-encode `((type . "command") (data
. ((commandName . "follow") (id . ,node))))))))))

(defun org-roam-ui--update-current-node-local ()
"Update the local graph view of the current node."
(let* ((node (org-roam-id-at-point)))
(when (and node (websocket-openp oru-ws) (org-roam-buffer-p) (file-exists-p (buffer-file-name)))
(websocket-send-text oru-ws (json-encode `((type . "command")
(data . ((commandName . "local") (id . ,node)))))))))

;; (defun org-roam-ui-sync-theme--advice ()
;; "Function which is called after load-theme to sync your current theme with org-roam-ui."
Expand Down