diff --git a/README.md b/README.md index 0ba67349..eef527d5 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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. diff --git a/org-roam-ui.el b/org-roam-ui.el index 3ba3e214..0fc7d684 100644 --- a/org-roam-ui.el +++ b/org-roam-ui.el @@ -38,6 +38,7 @@ (require 'org-roam) (require 'websocket) +;;;; Customization (defgroup org-roam-ui nil "UI in Org-roam." :group 'org-roam @@ -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." @@ -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))) @@ -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."