emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/gnosis 48ca4aa6f2 07/19: [Refactor] Rewrite org-insert-hea


From: ELPA Syncer
Subject: [nongnu] elpa/gnosis 48ca4aa6f2 07/19: [Refactor] Rewrite org-insert-heading
Date: Thu, 5 Sep 2024 13:00:30 -0400 (EDT)

branch: elpa/gnosis
commit 48ca4aa6f2420676de468f3ce43608d4cab41fca
Author: Thanos Apollo <public@thanosapollo.org>
Commit: Thanos Apollo <public@thanosapollo.org>

    [Refactor] Rewrite org-insert-heading
    
    * Adjust for list answers.
    * Use gnosis-id.
---
 gnosis-org.el | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/gnosis-org.el b/gnosis-org.el
index e194e88bc7..e977083e58 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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]