summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2024-02-20 02:58:33 +0200
committerThanos Apollo <[email protected]>2024-02-20 02:58:33 +0200
commit4b4746dce42361be8d817da35e00f3668dfe7ed6 (patch)
treefbc44dc9d65a736459530103614805221fbccd12
parentf2d56ebcec73817f97561cbb7c2048c0d4952559 (diff)
Refactor gnosis-export-note
- Rewrite suboptimal code - Add export of ef & ff
-rw-r--r--gnosis.el37
1 files changed, 10 insertions, 27 deletions
diff --git a/gnosis.el b/gnosis.el
index fb13b5c..cf2e6a3 100644
--- a/gnosis.el
+++ b/gnosis.el
@@ -1250,33 +1250,16 @@ quotes.
The final exported note is indented using the `indent-region' function
to improve readability."
- (let ((type (gnosis-get 'type 'notes `(= id ,id)))
- (main (gnosis-get 'main 'notes `(= id ,id)))
- (options (gnosis-get 'options 'notes `(= id ,id)))
- (answer (gnosis-get 'answer 'notes `(= id ,id)))
- (tags (gnosis-get 'tags 'notes `(= id ,id)))
- (extra-notes (gnosis-get 'extra-notes 'extras `(= id ,id)))
- (image (gnosis-get 'images 'extras `(= id ,id)))
- (second-image (gnosis-get 'extra-image 'extras `(= id ,id))))
- (cl-loop for (field . value) in `((type . ,type)
- (main . ,main)
- (options . ,options)
- (answer . ,answer)
- (tags . ,tags)
- (extra-notes . ,extra-notes)
- (image . ,image)
- (second-image . ,second-image))
- do (cond ((member field '(extra-notes image second-image))
- (insert (format ":%s \"%s\"\n" field value)))
- ((numberp value)
- (insert (format ":%s %s\n" field value)))
- ((listp value)
- (insert (format ":%s %s\n" field (format "%s" (cl-loop for item in value
- collect (format "\"%s\"" item))))))
- ((equal value nil)
- (insert (format ":%s %s\n" field 'nil)))
- (t (insert (format ":%s \"%s\"\n" field value))
- (indent-region (point-min) (point-max)))))))
+ (let ((values (append (gnosis-select '[id main options answer tags] 'notes `(= id ,id) t)
+ (gnosis-select '[extra-notes images extra-image] 'extras `(= id ,id) t)
+ (gnosis-select '[ef ff] 'review `(= id ,id) t)))
+ (fields '(:id :main :options :answer :tags :extra-notes :image :second-image :ef :ff)))
+ (cl-loop for value in values
+ for field in fields
+ do (insert
+ (if (listp value)
+ (format "\n%s '%s" (symbol-name field) (prin1-to-string value))
+ (format "\n%s %s" (symbol-name field) (prin1-to-string value)))))))
(defun gnosis-export-deck (filename)
"Export notes for deck in FILENAME.