summaryrefslogtreecommitdiff
path: root/org-gnosis.el
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2024-11-21 01:15:43 +0200
committerThanos Apollo <[email protected]>2024-11-21 01:15:43 +0200
commitbe05c7153040243a48fc43471c9e815abc2781b6 (patch)
treec548ebb8f8fded21c83dcb4b5bff6b422da225f0 /org-gnosis.el
parentcf35fc5bd89f7ac44ee6ff1122cf1897cc42ad73 (diff)
Add org-gnosis-mode & org-gnosis-insert
Diffstat (limited to 'org-gnosis.el')
-rw-r--r--org-gnosis.el29
1 files changed, 25 insertions, 4 deletions
diff --git a/org-gnosis.el b/org-gnosis.el
index 6815c50..b330501 100644
--- a/org-gnosis.el
+++ b/org-gnosis.el
@@ -289,10 +289,31 @@ Removes all contents of FILE in database, adding them anew."
(org-gnosis-select 'title 'nodes))))
(file (caar (org-gnosis-select 'file 'nodes `(= title ,title))))
(id (caar (org-gnosis-select 'id 'nodes `(= title ,title)))))
- (find-file
- (expand-file-name file org-gnosis-dir)
- ;;
- (ignore-errors (org-id-goto id)))))
+ (cond ((null file)
+ (org-gnosis--create-file title))
+ ((file-exists-p (expand-file-name file org-gnosis-dir))
+ (find-file
+ (expand-file-name file org-gnosis-dir))
+ (ignore-errors (org-id-goto id))
+ (org-gnosis-mode 1)))))
+
+(defun org-gnosis-insert ()
+ "Insert gnosis node."
+ (interactive)
+ (let* ((node (completing-read "Select gnosis node: "
+ (org-gnosis-select 'title 'nodes '1=1 t)))
+ (id (concat "id:" (car (org-gnosis-select 'id 'nodes `(= ,node title) '1=1)))))
+ (org-insert-link nil id node)))
+
+(define-minor-mode org-gnosis-mode
+ "Org gnosis mode."
+ :lighter " org-gnosis"
+ :keymap nil
+ :global nil
+ :group 'org-gnosis
+ (if org-gnosis-mode
+ (add-hook 'after-save-hook #'org-gnosis-update-file nil t) ;; buffer local hook
+ (remove-hook 'after-save-hook #'org-gnosis-update-file)))
;; Org-Gnosis Database