summaryrefslogtreecommitdiff
path: root/org-gnosis-ui.el
diff options
context:
space:
mode:
Diffstat (limited to 'org-gnosis-ui.el')
-rw-r--r--org-gnosis-ui.el122
1 files changed, 42 insertions, 80 deletions
diff --git a/org-gnosis-ui.el b/org-gnosis-ui.el
index 291b236..6d8bd82 100644
--- a/org-gnosis-ui.el
+++ b/org-gnosis-ui.el
@@ -5,10 +5,10 @@
;; author: Kirill Rogovoy, Thomas Jorna, Thanos Apollo
;; Maintainer: Thanos Apollo <[email protected]>
-;; URL: https://git.thanosapollo.org/org-roam-ui/
+;; URL: https://thanosapollo.org/projects/org-gnosis-ui/
;; Keywords: files outlines
-;; Version: 0.1
-;; Package-Requires: ((emacs "27.1") (simple-httpd "20191103.1446") (websocket "1.13"))
+;; Version: 0.2
+;; Package-Requires: ((emacs "27.1") (simple-httpd "1.5.1") (websocket "1.13") (org-gnosis "0.0.2"))
;; This file is NOT part of GNU Emacs.
@@ -45,10 +45,9 @@
(require 'websocket)
(defgroup org-gnosis-ui nil
- "UI in Org-roam."
+ "UI for Org Gnosis."
:group 'org-gnosis-ui
- :prefix "org-gnosis-ui-"
- :link '(url-link :tag "Github" "https://github.com/org-roam/org-gnosis-ui"))
+ :prefix "org-gnosis-ui-")
(defcustom org-gnosis-ui-directory org-gnosis-dir
"Directory of org-gnosis-ui notes."
@@ -87,9 +86,6 @@ Ignored if a custom theme is provied for variable `org-gnosis-ui-custom-theme'."
;; (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,
-instead sync this theme.
-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 '(alist :key-type (choice (const bg)
@@ -107,12 +103,13 @@ bg, bg-alt, fg, fg-alt, red, orange, yellow, green, cyan, blue, violet, magenta.
:value-type (color)))
(defcustom org-gnosis-ui-follow t
- "If true, `org-gnosis-ui' will follow you around in the graph."
+ "When t, will follow you around in the graph."
:group 'org-gnosis-ui
:type 'boolean)
(defcustom org-gnosis-ui-update-on-save t
- "If true, `org-gnosis-ui' will send new data when you save an `org-roam' buffer.
+ "When t, will send new data when you save an `org-gnosis' buffer.
+
This can lead to some jank."
:group 'org-gnosis-ui
:type 'boolean)
@@ -183,7 +180,7 @@ Take ID as string as sole argument."
(defcustom org-gnosis-ui-latex-macros nil
"Alist of LaTeX macros to be passed to org-gnosis-ui.
Format as, i.e. with double backslashes for a single backslash:
-'((\"\\macro\".\"\\something{#1}\"))"
+='((\"\\macro\".\"\\something{#1}\"))"
:group 'org-gnosis-ui
:type 'alist)
@@ -276,56 +273,27 @@ Takes _WS and FRAME as arguments."
(org-gnosis-ui--on-msg-open-node data))
((string= command "delete")
(org-gnosis-ui--on-msg-delete-node data))
- ((string= command "create")
- (org-gnosis-ui--on-msg-create-node data))
(t
(message
"Something went wrong when receiving a message from org-gnosis-ui")))))
(defun org-gnosis-ui--on-msg-open-node (data)
"Open a node when receiving DATA from the websocket."
- (let* ((id (alist-get 'id data))
- (node (org-roam-node-from-id id))
- (pos (org-roam-node-point node))
- (buf (find-file-noselect (org-roam-node-file node))))
- (run-hook-with-args 'org-gnosis-ui-before-open-node-functions id)
- (unless (window-live-p org-gnosis-ui--window)
- (if-let ((windows (window-list))
- (or-windows (seq-filter
- (lambda (window)
- (when (bound-and-true-p org-gnosis-mode)
- (window-buffer window)))
- windows))
- (newest-window (car
- (seq-sort-by
- #'window-use-time #'> or-windows))))
- (setq org-gnosis-ui--window newest-window)
- (split-window-horizontally)
- (setq org-gnosis-ui--window (frame-selected-window))))
- (set-window-buffer org-gnosis-ui--window buf)
- (select-window org-gnosis-ui--window)
- (goto-char pos)
- (run-hook-with-args 'org-gnosis-ui-after-open-node-functions id)))
+ (let* ((id (cdr (assoc 'id data)))
+ (title (car (org-gnosis-select 'title 'nodes `(= id ,id) t)))
+ (file (car (org-gnosis-select 'file 'nodes `(= id ,id) t))))
+ (org-gnosis-find title file id)))
+;; TODO: Why is there no data received?
(defun org-gnosis-ui--on-msg-delete-node (data)
- "Delete a node when receiving DATA from the websocket.
-
-TODO: Be able to delete individual nodes."
- (progn
+ "Delete a node when receiving DATA from the websocket."
+ (let* ((id (cdr (assoc 'id data)))
+ (file (car (org-gnosis-select 'file 'nodes `(= id ,id) t))))
(message "Deleted %s" (alist-get 'file data))
- (delete-file (alist-get 'file data))
- (org-roam-db-sync)
+ (org-gnosis-delete-file file)
+ ;; (delete-file (alist-get 'file data))
(org-gnosis-ui--send-graphdata)))
-(defun org-gnosis-ui--on-msg-create-node (data)
- "Create a node when receiving DATA from the websocket."
- (progn
- (if (and (fboundp #'orb-edit-note) (alist-get 'ROAM_REFS data))
- (orb-edit-note (alist-get 'id data)))
- (org-roam-capture-
- :node (org-roam-node-create :title (alist-get 'title data))
- :props '(:finalize find-file))))
-
(defun org-gnosis-ui--ws-on-close (_websocket)
"What to do when _WEBSOCKET to org-gnosis-ui is closed."
(remove-hook 'after-save-hook #'org-gnosis-ui--on-save)
@@ -334,17 +302,9 @@ TODO: Be able to delete individual nodes."
(defun org-gnosis-ui--get-text (id)
"Retrieve the text from org-node ID."
- (let*
- ((node (org-roam-populate (org-roam-node-create
- :id id)))
- (file (org-roam-node-file node)))
- (org-roam-with-temp-buffer
- file
- (when (> (org-roam-node-level node) 0)
- ;; Heading nodes have level 1 and greater.
- (goto-char (org-roam-node-point node))
- (org-narrow-to-element))
- (buffer-substring-no-properties (buffer-end -1) (buffer-end 1)))))
+ (with-temp-buffer
+ (insert-file-contents (car (org-gnosis-select 'file 'nodes `(= id ,id) t)))
+ (buffer-substring-no-properties (buffer-end -1) (buffer-end 1))))
(defun org-gnosis-ui--send-text (id ws)
"Send the text from org-node ID through the websocket WS."
@@ -366,7 +326,7 @@ TODO: Be able to delete individual nodes."
(httpd-send-header t "text/plain" 200 :Access-Control-Allow-Origin "*")))
(defun org-gnosis-ui--on-save ()
- "Send graphdata on saving an org-roam buffer.
+ "Send graphdata on saving an org-gnosis buffer.
TODO: Make this only send the changes to the graph data, not the complete graph."
(when (bound-and-true-p org-gnosis-mode)
@@ -385,7 +345,7 @@ TODO: Make this only send the changes to the graph data, not the complete graph.
"Find the title of the bibtex entry keyed by `REF'.
Requires `org-roam-bibtex' and `bibtex-completion' (a dependency of `orb') to be
-loaded. Returns `ref' if an entry could not be found."
+loaded. Returns `ref' if an entry could not be found."
(if (and org-gnosis-ui-find-ref-title
(fboundp 'bibtex-completion-get-entry)
(fboundp 'orb--pre-expand-template)
@@ -411,10 +371,11 @@ loaded. Returns `ref' if an entry could not be found."
(defun org-gnosis-ui--citekey-to-ref (citekey)
"Convert a CITEKEY property (most likely with a `cite:' prefix) to just a key.
-This method is mostly taken from `org-roam-bibtex'
-see https://github.com/org-roam/org-roam-bibtex/blob/919ec8d837a7a3bd25232bdba17a0208efaefb2a/orb-utils.el#L289
-but is has been adapted to operate on a sting instead of a node. Requires
-`org-ref' to be loaded. Returns the `key' or nil if the format does not match
+This method is mostly taken from `org-roam-bibtex' see but is has been
+adapted to operate on a sting instead of a node. Requires `org-ref' to
+be loaded.
+
+Returns the `key' or nil if the format does not match
the `org-ref-cite-re'"
(if-let ((boundp 'org-ref-cite-re)
(citekey-list (split-string-and-unquote citekey)))
@@ -426,10 +387,10 @@ the `org-ref-cite-re'"
(defun org-gnosis-ui--retitle-node (node)
"Replace the title of citation NODE with associated notes.
-A new title is created using information from the bibliography and formatted
-according to `org-gnosis-ui-ref-title-template', just like the citation nodes with
-a note are. It requires `org-roam-bibtex' and it's dependencies
-\(`bibtex-completion' and `org-ref'\) to be loaded.
+A new title is created using information from the bibliography and
+formatted according to `org-gnosis-ui-ref-title-template', just like
+the citation nodes with a note are. It requires `org-roam-bibtex' and
+it's dependencies \(`bibtex-completion' and `org-ref'\) to be loaded.
Returns the node with an updated title if the current node is a reference node
and the key was found in the bibliography, otherwise the node is returned
@@ -457,7 +418,7 @@ unchanged."
'nil))
(defun org-gnosis-ui-get-tags ()
- "Fetch tags from the org-roam database."
+ "Fetch tags from the org-gnosis database."
(org-gnosis-select '* 'tags '1=1 t))
(defun org-gnosis-ui-get-nodes (&optional nodes links-db)
@@ -541,7 +502,7 @@ Nodes defaults to `org-gnosis-ui-node-query' formatted by
1 ;; Assume priority or similar static position value
nil ;; This corresponds to the `position` from your desired output
- ;; Properties, to fit with the previous implemention of org-roam-ui.
+ ;; Properties, to fit with the previous implemention of org-gnosis-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))
@@ -588,7 +549,7 @@ Nodes defaults to `org-gnosis-ui-node-query' formatted by
(defun org-gnosis-ui--send-variables (ws)
- "Send miscellaneous org-roam variables through the websocket WS."
+ "Send miscellaneous org-gnosis variables through the websocket WS."
(let ((daily-dir (or org-gnosis-ui-dailies-directory ""))
(attach-dir (or (and (boundp 'org-attach-id-dir) org-attach-id-dir)
(expand-file-name ".attach/" org-directory)))
@@ -652,8 +613,8 @@ COLUMN-NAMES: columns to use."
`(magenta . ,(face-foreground font-lock-preprocessor-face))))
(defun org-gnosis-ui-find-subdirectories ()
- "Find all the subdirectories in the org-roam directory.
-TODO: Exclude org-attach dirs."
+ "Find all the subdirectories in the org-gnosis directory.
+TODO: Exclude `org-attach' dirs."
(seq-filter
(lambda (file) (and (file-directory-p file) (org-gnosis-ui-allowed-directory-p file)))
(directory-files-recursively org-gnosis-ui-directory
@@ -708,9 +669,10 @@ 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.
+ "Add or remove current node ID to the local graph.
-If not in local mode, open local-graph for this node."
+If not in local mode, open local-graph for this node.
+MANIPULATION:"
(interactive)
(if-let ((node (or id (org-gnosis-get-id))))
(websocket-send-text org-gnosis-ui-ws-socket
@@ -722,7 +684,7 @@ If not in local mode, open local-graph for this node."
;;;###autoload
(defun org-gnosis-ui-add-to-local-graph (&optional id)
- "Add current node to the local graph.
+ "Add current node ID to the local graph.
If not in local mode, open local-graph for this node."
(interactive)