You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given the plethora of note-taking packages available for Emacs, having a single graphical front-end for zettelkasten-style note taking systems—whether it's denote, org-roam, or a new project such as org-gnosis that I'm working on—would greatly benefit the entire ecosystem.
Decoupling org-roam-ui from org-roam would be advantageous for both projects, as it would facilitate adjustments to future versions without hard-coding schema details or dependency on specific functions. This separation would enhance customization and streamline future development.
Example solution
Allowing users to have defcustom function variables to be used with org-roam-ui--send-graphdata, which they should default to org-roam specific functions
Adjust how node names work, by that I mean if it's essential to include (level pos olp properties) since AFAIK they are not essential for the graphical interface. We could just require (id file title tags)and read the contents of the file.
An example diff with suggested changes that I've been playing with today:
NOTE: This needs further adjustment on org-roam-ui-nodes-function, since it expects a format of node-names as (id file title level pos olp properties tags). To make it possible to use other note taking systems it'd be better to use (id file title tags) and optionally provide level pos olp properties.
diff --git a/org-roam-ui.el b/org-roam-ui.el
index e13349b..3a23057 100644
--- a/org-roam-ui.el+++ b/org-roam-ui.el@@ -36,30 +36,22 @@
(require 'simple-httpd)
(require 'org-roam)
(require 'websocket)
-(require 'org-roam-dailies)+;; (require 'org-roam-dailies)
(defgroup org-roam-ui nil
"UI in Org-roam."
- :group 'org-roam+ :group 'org-roam-ui
:prefix "org-roam-ui-"
:link '(url-link :tag "Github" "https://github.com/org-roam/org-roam-ui"))
-(defvar org-roam-ui-root-dir- (concat (file-name-directory- (expand-file-name (or- load-file-name- buffer-file-name)))- ".")- "Root directory of the org-roam-ui project.")--(defvar org-roam-ui-app-build-dir- (expand-file-name "./out/" org-roam-ui-root-dir)- "Directory containing org-roam-ui's web build.")+(defcustom org-roam-ui-directory org-roam-directory+ "Directory of org-roam-ui notes."+ :group 'org-roam-ui+ :type 'directory)-;; TODO: make into defcustom-(defvar org-roam-ui-port- 35901- "Port to serve the org-roam-ui interface.")+(defcustom org-roam-ui-port 35901+ :group 'org-roam-ui+ :type 'number)
(defcustom org-roam-ui-sync-theme t
"If true, sync your current Emacs theme with `org-roam-ui'.
@@ -68,6 +60,11 @@ Ignored if a custom theme is provied for variable 'org-roam-ui-custom-theme'."
:group 'org-roam-ui
:type 'boolean)
+(defcustom org-roam-ui-dailies-directory org-roam-dailies-directory+ "Dailies/Journaling directory."+ :group 'org-roam-ui+ :type 'directory)+
(defcustom org-roam-ui-custom-theme nil
"Custom theme for `org-roam-ui'.
Blocks 'org-roam-ui-sync-theme from syncing your current theme,
@@ -131,6 +128,21 @@ Defaults to #'browse-url."
:group 'org-roam-ui
:type 'function)
+(defcustom org-roam-ui-tags-function #'org-roam-ui-get-tags+ "Function that returns all tags as a list."+ :group 'org-roam-ui+ :type 'function)++(defcustom org-roam-ui-nodes-function #'org-roam-ui-get-nodes+ "Function that returns nodes."+ :group 'org-roam-ui+ :type 'function)++(defcustom org-roam-ui-links-function #'org-roam-ui-get-links+ "Function that returns links."+ :group 'org-roam-ui+ :type 'function)+
;;Hooks
(defcustom org-roam-ui-before-open-node-functions nil
@@ -154,6 +166,18 @@ Format as, i.e. with double backslashes for a single backslash:
;; Internal vars
+(defvar org-roam-ui-root-dir+ (concat (file-name-directory+ (expand-file-name (or+ load-file-name+ buffer-file-name)))+ ".")+ "Root directory of the org-roam-ui project.")++(defvar org-roam-ui-app-build-dir+ (expand-file-name "./out/" org-roam-ui-root-dir)+ "Directory containing org-roam-ui's web build.")+
(defvar org-roam-ui--ws-current-node nil
"Var to keep track of which node you are looking at.")
@@ -400,61 +424,56 @@ unchanged."
("FILELESS" . t))
'nil))
-(defun org-roam-ui--send-graphdata ()- "Get roam data, make JSON, send through websocket to org-roam-ui."- (let* ((nodes-names- [id- file- title- level- pos- olp- properties- tags])- (old (not (fboundp 'org-roam-db-map-citations)))- (links-db-rows (if old- (org-roam-ui--separate-ref-links- (org-roam-ui--get-links old))- (seq-concatenate- 'list- (org-roam-ui--separate-ref-links- (org-roam-ui--get-cites))- (org-roam-ui--get-links))))- (links-with-empty-refs (org-roam-ui--filter-citations links-db-rows))- (empty-refs (delete-dups (seq-map- (lambda (link)- (nth 1 link))- links-with-empty-refs)))- (nodes-db-rows (org-roam-ui--get-nodes))- (fake-nodes (seq-map #'org-roam-ui--create-fake-node empty-refs))- ;; Try to update real nodes that are reference with a title build- ;; from their bibliography entry. Check configuration here for avoid- ;; unneeded iteration though nodes.- (retitled-nodes-db-rows (if org-roam-ui-retitle-ref-nodes- (seq-map #'org-roam-ui--retitle-node- nodes-db-rows)- nodes-db-rows))- (complete-nodes-db-rows (append retitled-nodes-db-rows fake-nodes))+(defun org-roam-ui-get-links (&optional old-db)+ "Fetch links from the org-roam database.+If OLD-DB is non-nil, use the older method of getting links."+ (if old-db+ (org-roam-ui--separate-ref-links+ (org-roam-ui--get-links t))+ (nconc (org-roam-ui--separate-ref-links+ (org-roam-ui--get-cites))+ (org-roam-ui--get-links))))++(defun org-roam-ui-get-tags ()+ "Fetch tags from the org-roam database."+ (seq-mapcat #'seq-reverse+ (org-roam-db-query+ [:select :distinct tag :from tags])))++(defun org-roam-ui-get-nodes (&optional nodes links-db)+ "Fetch nodes and create fake nodes based on LINKS-DB.+If NODES is provided, use it directly."+ (let* ((nodes-db (or nodes (org-roam-ui--get-nodes)))+ (fake-nodes (seq-map #'org-roam-ui--create-fake-node+ (delete-dups+ (mapcar #'cadr+ (org-roam-ui--filter-citations links-db))))))+ (append (if org-roam-ui-retitle-ref-nodes+ (seq-map #'org-roam-ui--retitle-node nodes-db)+ nodes-db)+ fake-nodes)))++(defun org-roam-ui--send-graphdata (&optional nodes links tags)+ "Prepare and send graph data to org-roam-ui, optionally using NODES, LINKS, and TAGS.+If not provided, data is retrieved from the org-roam database."+ (let* ((links-db (or links (funcall org-roam-ui-links-function)))+ (nodes-db (or nodes (funcall org-roam-ui-nodes-function)))+ (tags-db (or tags (funcall org-roam-ui-tags-function)))+ (nodes-names '(id file title level pos olp properties tags))+ ;; (node-names '(id file title tags))
(response `((nodes . ,(mapcar
(apply-partially
#'org-roam-ui-sql-to-alist
- (append nodes-names nil))- complete-nodes-db-rows))+ nodes-names)+ nodes-db))
(links . ,(mapcar
(apply-partially
#'org-roam-ui-sql-to-alist
'(source target type))
- links-db-rows))- (tags . ,(seq-mapcat- #'seq-reverse- (org-roam-db-query- [:select :distinct tag :from tags]))))))- (when old- (message "[org-roam-ui] You are not using the latest version of org-roam.-This database model won't be supported in the future, please consider upgrading."))- (websocket-send-text org-roam-ui-ws-socket (json-encode- `((type . "graphdata")- (data . ,response))))))+ links-db))+ (tags . ,tags-db))))+ (websocket-send-text org-roam-ui-ws-socket+ (json-encode `((type . "graphdata") (data . ,response))))))
(defun org-roam-ui--filter-citations (links)
@@ -465,21 +484,21 @@ This database model won't be supported in the future, please consider upgrading.
links))
(defun org-roam-ui--get-nodes ()
- "."+ "Nodes to display in org-roam-ui."
(org-roam-db-query [:select [id
- file- title- level- pos- olp- properties- (funcall group-concat tag- (emacsql-escape-raw \, ))]- :as tags- :from nodes- :left-join tags- :on (= id node_id)- :group :by id]))+ file+ title+ level+ pos+ olp+ properties+ (funcall group-concat tag+ (emacsql-escape-raw \, ))]+ :as tags+ :from nodes+ :left-join tags+ :on (= id node_id)+ :group :by id]))
(defun org-roam-ui--get-links (&optional old)
"Get the cites and links tables as rows from the org-roam db.
@@ -574,13 +593,7 @@ from all other links."
(defun org-roam-ui--send-variables (ws)
"Send miscellaneous org-roam variables through the websocket WS."
- (let ((daily-dir (if (boundp 'org-roam-dailies-directory)- (if (file-name-absolute-p org-roam-dailies-directory)- (expand-file-name org-roam-dailies-directory)- (expand-file-name- org-roam-dailies-directory- org-roam-directory))- "/dailies"))+ (let ((daily-dir org-roam-ui-dailies-directory)
(attach-dir (if (boundp 'org-attach-id-dir)
org-attach-id-dir
(expand-file-name ".attach/" org-directory)))
@@ -600,7 +613,7 @@ from all other links."
,attach-dir)
("useInheritance" .
,use-inheritance)
- ("roamDir" . ,org-roam-directory)+ ("roamDir" . ,org-roam-ui-directory)
("katexMacros" . ,org-roam-ui-latex-macros))))))))
(defun org-roam-ui-sql-to-alist (column-names rows)
@@ -639,7 +652,7 @@ ROWS is the sql result, while COLUMN-NAMES is the columns to use."
TODO: Exclude org-attach dirs."
(seq-filter
(lambda (file) (and (file-directory-p file) (org-roam-ui-allowed-directory-p file)))
- (directory-files-recursively org-roam-directory+ (directory-files-recursively org-roam-ui-directory
".*" t #'org-roam-ui-allowed-directory-p)))
(defun org-roam-ui-allowed-directory-p (dir)
The text was updated successfully, but these errors were encountered:
Description
Given the plethora of note-taking packages available for Emacs, having a single graphical front-end for zettelkasten-style note taking systems—whether it's denote, org-roam, or a new project such as org-gnosis that I'm working on—would greatly benefit the entire ecosystem.
Decoupling
org-roam-ui
fromorg-roam
would be advantageous for both projects, as it would facilitate adjustments to future versions without hard-coding schema details or dependency on specific functions. This separation would enhance customization and streamline future development.Example solution
org-roam-ui--send-graphdata
, which they should default to org-roam specific functions(level pos olp properties)
since AFAIK they are not essential for the graphical interface. We could just require(id file title tags)
and read the contents of the file.An example diff with suggested changes that I've been playing with today:
The text was updated successfully, but these errors were encountered: