diff options
author | Thanos Apollo <[email protected]> | 2024-08-27 02:14:35 +0300 |
---|---|---|
committer | Thanos Apollo <[email protected]> | 2024-08-27 02:16:08 +0300 |
commit | 48ca4aa6f2420676de468f3ce43608d4cab41fca (patch) | |
tree | 1fe76b286b786673232178dbe4f2fe4a7d370b03 /gnosis-org.el | |
parent | 907308c45e8221fedb8c34596cd57497c2736c01 (diff) |
[Refactor] Rewrite org-insert-heading
* Adjust for list answers.
* Use gnosis-id.
Diffstat (limited to 'gnosis-org.el')
-rw-r--r-- | gnosis-org.el | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/gnosis-org.el b/gnosis-org.el index e194e88..e977083 100644 --- a/gnosis-org.el +++ b/gnosis-org.el @@ -64,24 +64,29 @@ BUFFER defaults to the current buffer if not specified." (if results (reverse results) (message "No custom properties found for %s" property) nil)))) - -(cl-defun gnosis-org-insert-custom-heading (&key main id body type (buffer (current-buffer))) - "Insert an Org heading in BUFFER. +;; TODO: Add support for tags. +(cl-defun gnosis-org-insert-heading (&key main id answer type) + "Insert an Org heading in current buffer. - MAIN as the title. -- ID as CUSTOM_ID. -- BODY as the content. +- ID as GNOSIS_ID. +- ANSWER as the subheading. - TYPE as the note type. If BUFFER is not specified, defaults to the current buffer." (cl-assert (stringp main) nil "MAIN must be a string representing the heading title.") - (cl-assert (stringp id) nil "ID must be a string representing the CUSTOM_ID.") - (cl-assert (stringp body) nil "BODY must be a string representing the content.") + (cl-assert (stringp id) nil "ID must be a string representing the GNOSIS_ID.") (cl-assert (stringp type) nil "TYPE must be a string representing the TYPE property.") - (with-current-buffer buffer + (let ((main (if (string-match-p "\n" main) (replace-regexp-in-string "\n" "\\\\n" main) main)) + (answer (cond ((stringp answer) + answer) + ((numberp answer) + (number-to-string answer)) + (t (mapconcat 'identity answer ", "))))) (goto-char (point-max)) ;; Ensure we're at the end of the buffer - (insert (format "* %s\n:PROPERTIES:\n:CUSTOM_ID: %s\n:TYPE: %s\n:END:\n%s\n" main id type body)) - (message "Inserted heading: %s with CUSTOM_ID %s and TYPE %s" main id type))) + (insert (format "* %s\n:PROPERTIES:\n:GNOSIS_ID: %s\n:TYPE: %s\n:END:\n** %s\n" + main id type answer)) + (message "Inserted heading: %s with GNOSIS_ID %s and TYPE %s" main id type))) (provide 'gnosis-org) ;;; gnosis-org.el ends here. |