Rename variavbles
This commit is contained in:
parent
545eb6ed08
commit
60d0540aca
1 changed files with 34 additions and 19 deletions
|
@ -42,15 +42,30 @@
|
||||||
(require 'org-element)
|
(require 'org-element)
|
||||||
|
|
||||||
|
|
||||||
(defvar anki-editor-note-tag "note")
|
(defconst anki-editor-prop-note-type :ANKI_NOTE_TYPE)
|
||||||
(defvar anki-editor-deck-tag "deck")
|
(defconst anki-editor-prop-note-tags :ANKI_TAGS)
|
||||||
(defvar anki-editor-note-type-prop :ANKI_NOTE_TYPE)
|
(defconst anki-editor-prop-note-id :ANKI_NOTE_ID)
|
||||||
(defvar anki-editor-note-tags-prop :ANKI_TAGS)
|
(defconst anki-editor-prop-failure-reason :ANKI_FAILURE_REASON)
|
||||||
(defvar anki-editor-note-id-prop :ANKI_NOTE_ID)
|
(defconst anki-editor-buffer-html-output "*anki-editor HTML Output*")
|
||||||
(defvar anki-editor-note-failure-reason-prop :ANKI_FAILURE_REASON)
|
|
||||||
(defvar anki-editor-html-output-buffer-name "*anki-editor html output*")
|
(defcustom anki-editor-note-tag
|
||||||
(defvar anki-editor-anki-connect-listening-address "127.0.0.1")
|
"note"
|
||||||
(defvar anki-editor-anki-connect-listening-port "8765")
|
"Headings with this tag will be considered as notes."
|
||||||
|
:group 'anki-editor)
|
||||||
|
(defcustom anki-editor-deck-tag
|
||||||
|
"deck"
|
||||||
|
"Headings with this tag will be considered as decks."
|
||||||
|
:group 'anki-editor)
|
||||||
|
|
||||||
|
(defcustom anki-editor-anki-connect-listening-address
|
||||||
|
"127.0.0.1"
|
||||||
|
"The network address anki-connect is listening."
|
||||||
|
:group 'anki-editor)
|
||||||
|
|
||||||
|
(defcustom anki-editor-anki-connect-listening-port
|
||||||
|
"8765"
|
||||||
|
"The port number anki-connect is listening."
|
||||||
|
:group 'anki-editor)
|
||||||
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
|
@ -119,7 +134,7 @@ that correspond to fields."
|
||||||
(org-do-demote)
|
(org-do-demote)
|
||||||
(insert note-heading)
|
(insert note-heading)
|
||||||
(anki-editor--set-tags-fix anki-editor-note-tag)
|
(anki-editor--set-tags-fix anki-editor-note-tag)
|
||||||
(org-set-property (substring (symbol-name anki-editor-note-type-prop) 1) note-type)
|
(org-set-property (substring (symbol-name anki-editor-prop-note-type) 1) note-type)
|
||||||
(seq-each (lambda (field)
|
(seq-each (lambda (field)
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(org-insert-heading-respect-content)
|
(org-insert-heading-respect-content)
|
||||||
|
@ -149,9 +164,9 @@ that correspond to fields."
|
||||||
|
|
||||||
(setq contents (buffer-substring-no-properties (org-element-property :contents-begin tree)
|
(setq contents (buffer-substring-no-properties (org-element-property :contents-begin tree)
|
||||||
(org-element-property :contents-end tree)))
|
(org-element-property :contents-end tree)))
|
||||||
(when (buffer-live-p (get-buffer anki-editor-html-output-buffer-name))
|
(when (buffer-live-p (get-buffer anki-editor-buffer-html-output))
|
||||||
(kill-buffer anki-editor-html-output-buffer-name))
|
(kill-buffer anki-editor-buffer-html-output))
|
||||||
(switch-to-buffer-other-window (get-buffer-create anki-editor-html-output-buffer-name))
|
(switch-to-buffer-other-window (get-buffer-create anki-editor-buffer-html-output))
|
||||||
(insert (anki-editor--generate-html contents)))))
|
(insert (anki-editor--generate-html contents)))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
|
@ -219,7 +234,7 @@ bugfixes or new features of anki-connect."
|
||||||
(result (alist-get 'result response))
|
(result (alist-get 'result response))
|
||||||
(err (alist-get 'error response)))
|
(err (alist-get 'error response)))
|
||||||
(if result
|
(if result
|
||||||
(org-set-property (substring (symbol-name anki-editor-note-id-prop) 1)
|
(org-set-property (substring (symbol-name anki-editor-prop-note-id) 1)
|
||||||
(format "%d" (alist-get 'result response)))
|
(format "%d" (alist-get 'result response)))
|
||||||
(error (or err "Sorry, the operation was unsuccessful and detailed information is unavailable.")))))
|
(error (or err "Sorry, the operation was unsuccessful and detailed information is unavailable.")))))
|
||||||
|
|
||||||
|
@ -245,16 +260,16 @@ bugfixes or new features of anki-connect."
|
||||||
("tags" . ,(mapconcat #'identity removed-tags " ")))))))
|
("tags" . ,(mapconcat #'identity removed-tags " ")))))))
|
||||||
|
|
||||||
(defun anki-editor--set-failure-reason (reason)
|
(defun anki-editor--set-failure-reason (reason)
|
||||||
(org-set-property (substring (symbol-name anki-editor-note-failure-reason-prop) 1) reason))
|
(org-set-property (substring (symbol-name anki-editor-prop-failure-reason) 1) reason))
|
||||||
|
|
||||||
(defun anki-editor--clear-failure-reason ()
|
(defun anki-editor--clear-failure-reason ()
|
||||||
(org-delete-property (substring (symbol-name anki-editor-note-failure-reason-prop) 1)))
|
(org-delete-property (substring (symbol-name anki-editor-prop-failure-reason) 1)))
|
||||||
|
|
||||||
(defun anki-editor--heading-to-note (heading)
|
(defun anki-editor--heading-to-note (heading)
|
||||||
(let (note-id note-type tags fields)
|
(let (note-id note-type tags fields)
|
||||||
(setq note-id (org-element-property anki-editor-note-id-prop heading)
|
(setq note-id (org-element-property anki-editor-prop-note-id heading)
|
||||||
note-type (org-element-property anki-editor-note-type-prop heading)
|
note-type (org-element-property anki-editor-prop-note-type heading)
|
||||||
tags (org-element-property anki-editor-note-tags-prop heading)
|
tags (org-element-property anki-editor-prop-note-tags heading)
|
||||||
fields (mapcar #'anki-editor--heading-to-note-field (anki-editor--get-subheadings heading)))
|
fields (mapcar #'anki-editor--heading-to-note-field (anki-editor--get-subheadings heading)))
|
||||||
|
|
||||||
(unless note-type (error "Missing note type"))
|
(unless note-type (error "Missing note type"))
|
||||||
|
|
Loading…
Reference in a new issue