summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--org-gnosis-ui.el118
1 files changed, 66 insertions, 52 deletions
diff --git a/org-gnosis-ui.el b/org-gnosis-ui.el
index 84c10af..291b236 100644
--- a/org-gnosis-ui.el
+++ b/org-gnosis-ui.el
@@ -72,26 +72,39 @@ Ignored if a custom theme is provied for variable `org-gnosis-ui-custom-theme'."
:group 'org-gnosis-ui
:type 'directory)
+;; Default theme previously provided:
+;; '((bg . "#1E2029")
+;; (bg-alt . "#282a36")
+;; (fg . "#f8f8f2")
+;; (fg-alt . "#6272a")
+;; (red . "#ff5555")
+;; (orange . "#f1fa8c")
+;; (yellow ."#ffb86c")
+;; (green . "#50fa7b")
+;; (cyan . "#8be9fd")
+;; (blue . "#ff79c6")
+;; (violet . "#8be9fd")
+;; (magenta . "#bd93f9")).
(defcustom org-gnosis-ui-custom-theme nil
"Custom theme for `org-gnosis-ui'.
-Blocks 'org-gnosis-ui-sync-theme from syncing your current theme,
+Blocks `org-gnosis-ui-sync-theme' from syncing your current theme,
instead sync this theme.
-Provide a list of cons with the following values:
-bg, bg-alt, fg, fg-alt, red, orange, yellow, green, cyan, blue, violet, magenta.
-E.g. '((bg . \"#1E2029\")
-\(bg-alt . \"#282a36\")
-\(fg . \"#f8f8f2\")
-\(fg-alt . \"#6272a\")
-\(red . \"#ff5555\")
-\(orange . \"#f1fa8c\")
-\(yellow .\"#ffb86c\")
-\(green . \"#50fa7b\")
-\(cyan . \"#8be9fd\")
-\(blue . \"#ff79c6\")
-\(violet . \"#8be9fd\")
-\(magenta . \"#bd93f9\"))."
+Provide a list of cons with the following keys:
+bg, bg-alt, fg, fg-alt, red, orange, yellow, green, cyan, blue, violet, magenta."
:group 'org-gnosis-ui
- :type 'list)
+ :type '(alist :key-type (choice (const bg)
+ (const bg-alt)
+ (const fg)
+ (const fg-alt)
+ (const red)
+ (const orange)
+ (const yellow)
+ (const green)
+ (const cyan)
+ (const blue)
+ (const violet)
+ (const magenta))
+ :value-type (color)))
(defcustom org-gnosis-ui-follow t
"If true, `org-gnosis-ui' will follow you around in the graph."
@@ -129,24 +142,17 @@ capture `%^{...}' are supported."
:type 'string)
(defcustom org-gnosis-ui-browser-function #'browse-url
- "When non-nil launch org-gnosis-ui with a different browser function.
-Takes a function name, such as #'browse-url-chromium.
-Defaults to #'browse-url."
+ "Function launch browser."
:group 'org-gnosis-ui
:type 'function)
-(defcustom org-gnosis-ui-tags-function #'(lambda () (org-gnosis-select '* 'tags '1=1 t))
- "Function that returns all tags as a list."
- :group 'org-gnosis-ui
- :type 'function)
-
-(defcustom org-gnosis-ui-nodes-function #'org-gnosis-ui-get-nodes
- "Function that returns nodes."
+(defcustom org-gnosis-ui-tags-function #'org-gnosis-ui-get-tags
+ "Function that returns all unique tags."
:group 'org-gnosis-ui
:type 'function)
(defcustom org-gnosis-ui-node-query #'org-gnosis-ui-query
- "Function that returns as ='(id file title level tag).
+ "Function that returns node metadata as ='(id file title level tag).
Output of this function is then used by `org-gnosis-ui-get-nodes' to be
formatted properly for json data."
@@ -154,7 +160,9 @@ formatted properly for json data."
:type 'function)
(defcustom org-gnosis-ui-links-function #'(lambda () (org-gnosis-select '* 'links))
- "Function that returns links."
+ "Function that returns links.
+
+Output struct: ='((source dest))"
:group 'org-gnosis-ui
:type 'function)
@@ -450,14 +458,13 @@ unchanged."
(defun org-gnosis-ui-get-tags ()
"Fetch tags from the org-roam database."
- (seq-mapcat #'seq-reverse
- (org-roam-db-query
- [:select :distinct tag :from tags])))
+ (org-gnosis-select '* 'tags '1=1 t))
(defun org-gnosis-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-gnosis-ui--get-nodes)))
+ ;; Is there a reason to keep this?
(fake-nodes (seq-map #'org-gnosis-ui--create-fake-node
(delete-dups
(mapcar #'cadr
@@ -468,10 +475,14 @@ If NODES is provided, use it directly."
fake-nodes)))
(defun org-gnosis-ui--send-graphdata (&optional nodes links tags)
- "Prepare and send graph data to org-gnosis-ui, optionally using NODES, LINKS, and TAGS.
-If not provided, data is retrieved from the org-roam database."
+ "Prepare and send graph data to org-gnosis-ui.
+
+Optionally using customs NODES, LINKS, and TAGS.
+
+Nodes defaults to `org-gnosis-ui-node-query' formatted by
+`org-gnosis-ui-get-nodes'."
(let* ((links-db (or links (funcall org-gnosis-ui-links-function)))
- (nodes-db (or nodes (funcall org-gnosis-ui-nodes-function)))
+ (nodes-db (or nodes (org-gnosis-ui-get-nodes)))
(tags-db (or tags (funcall org-gnosis-ui-tags-function)))
(nodes-alist '())
(links-alist '()))
@@ -502,7 +513,6 @@ If not provided, data is retrieved from the org-roam database."
(string-match-p "cite" (nth 2 link)))
links))
-;; Query for gnosis
(defun org-gnosis-ui-query ()
"Query to get nodes from org-gnosis db."
(emacsql org-gnosis-db
@@ -530,11 +540,14 @@ If not provided, data is retrieved from the org-roam database."
level
1 ;; Assume priority or similar static position value
nil ;; This corresponds to the `position` from your desired output
- ;; Properties
+
+ ;; Properties, to fit with the previous implemention of org-roam-ui.
+ ;; TODO: To make it easier to use 3rd party note
+ ;; taking systems, this part should be removed.
(list (cons "CATEGORY" (file-name-base file))
(cons "ID" id)
(cons "BLOCKED" "")
- (cons "ALLTAGS" (propertize (concat ":" tags ":") 'face 'org-tag)) ;; Assuming tags need to be formatted this way
+ (cons "ALLTAGS" (propertize (concat ":" tags ":") 'face 'org-tag))
(cons "FILE" file)
(cons "PRIORITY" "B"))
tags))) ;; Put tags at the last position as per your requirement
@@ -602,8 +615,10 @@ If not provided, data is retrieved from the org-roam database."
("katexMacros" . ,(or org-gnosis-ui-latex-macros '())))))))))
(defun org-gnosis-ui-sql-to-alist (column-names rows)
- "Convert sql result to alist for json encoding.
-ROWS is the sql result, while COLUMN-names is the columns to use."
+ "Convert SQL result to an alist for json encoding.
+
+ROWS: the SQL output.
+COLUMN-NAMES: columns to use."
(let (res)
(while rows
(cond
@@ -620,6 +635,7 @@ ROWS is the sql result, while COLUMN-names is the columns to use."
(setq rows nil))))
res))
+;; TODO: Customize themes.
(defun org-gnosis-ui-get-theme ()
"Attempt to bring the current theme into a standardized format."
(list `(bg . ,(face-background hl-line-face))
@@ -648,8 +664,6 @@ TODO: Exclude org-attach dirs."
Hides . directories."
(not (string-match-p "\\(\/\\|\\\\\\)\\..*?" dir)))
-;;;; interactive commands
-
;;;###autoload
(defun org-gnosis-ui-open ()
"Ensure `org-gnosis-ui' is running, then open the `org-gnosis-ui' webpage."
@@ -661,7 +675,8 @@ Hides . directories."
;;;###autoload
(defun org-gnosis-ui-node-zoom (&optional id speed padding)
"Move the view of the graph to current node.
-or optionally a node of your choosing.
+
+Optionally a node of your choosing.
Optionally takes three arguments:
The ID of the node you want to travel to.
The SPEED in ms it takes to make the transition.
@@ -693,7 +708,9 @@ Optionally with ID (string), SPEED (number, ms) and PADDING (number, px)."
(defun org-gnosis-ui-change-local-graph (&optional id manipulation)
- "Add or remove current node to the local graph. If not in local mode, open local-graph for this node."
+ "Add or remove current node to the local graph.
+
+If not in local mode, open local-graph for this node."
(interactive)
(if-let ((node (or id (org-gnosis-get-id))))
(websocket-send-text org-gnosis-ui-ws-socket
@@ -705,13 +722,17 @@ Optionally with ID (string), SPEED (number, ms) and PADDING (number, px)."
;;;###autoload
(defun org-gnosis-ui-add-to-local-graph (&optional id)
- "Add current node to the local graph. If not in local mode, open local-graph for this node."
+ "Add current node to the local graph.
+
+If not in local mode, open local-graph for this node."
(interactive)
(org-gnosis-ui-change-local-graph id "add"))
;;;###autoload
(defun org-gnosis-ui-remove-from-local-graph (&optional id)
- "Remove current node from the local graph. If not in local mode, open local-graph for this node."
+ "Remove current node for ID from the local graph.
+
+If not in local mode, open local-graph for this node."
(interactive)
(org-gnosis-ui-change-local-graph id "remove"))
@@ -722,13 +743,6 @@ Optionally with ID (string), SPEED (number, ms) and PADDING (number, px)."
(websocket-send-text org-gnosis-ui-ws-socket
(json-encode `((type . "theme")
(data . ,(org-gnosis-ui--update-theme))))))
-
-;;; Obsolete commands
-(define-obsolete-function-alias #'orui-open #'org-gnosis-ui-open "0.1")
-(define-obsolete-function-alias #'orui-node-local #'org-gnosis-ui-node-local "0.1")
-(define-obsolete-function-alias #'orui-node-zoom #'org-gnosis-ui-node-zoom "0.1")
-(define-obsolete-function-alias #'orui-sync-theme #'org-gnosis-ui-sync-theme "0.1")
-
;;;###autoload
(define-minor-mode org-gnosis-ui-follow-mode
"Set whether ORUI should follow your every move in Emacs."