Expose and document some functions
This commit is contained in:
parent
683c48dfec
commit
20d61f4c63
2 changed files with 47 additions and 34 deletions
|
@ -4,6 +4,7 @@ anki-editor -- Emacs minor mode for making Anki cards with Org
|
||||||
|
|
||||||
/Since I'm not a native English speaker, feel free to correct me if
|
/Since I'm not a native English speaker, feel free to correct me if
|
||||||
there were any ambiguity or grammatical mistakes ;-)/
|
there were any ambiguity or grammatical mistakes ;-)/
|
||||||
|
|
||||||
* Installation
|
* Installation
|
||||||
|
|
||||||
*Requirements*
|
*Requirements*
|
||||||
|
@ -61,6 +62,13 @@ there were any ambiguity or grammatical mistakes ;-)/
|
||||||
| =anki-editor-export-subtree-to-html= | Export the subtree at point to HTML. |
|
| =anki-editor-export-subtree-to-html= | Export the subtree at point to HTML. |
|
||||||
| =anki-editor-convert-region-to-html= | Convert and replace region to HTML. |
|
| =anki-editor-convert-region-to-html= | Convert and replace region to HTML. |
|
||||||
|
|
||||||
|
** Functions
|
||||||
|
|
||||||
|
| Name | Description |
|
||||||
|
|------------------------------+------------------------------------------------------------|
|
||||||
|
| anki-editor-map-note-entries | Simple wrapper that calls =org-map-entries=. |
|
||||||
|
| anki-editor-note-at-point | Construct an alist representing a note from current entry. |
|
||||||
|
|
||||||
* Limitations
|
* Limitations
|
||||||
|
|
||||||
** Tags between Anki and Org
|
** Tags between Anki and Org
|
||||||
|
|
|
@ -311,9 +311,12 @@ The implementation is borrowed and simplified from ox-html."
|
||||||
|
|
||||||
;;; Core Functions
|
;;; Core Functions
|
||||||
|
|
||||||
(defun anki-editor--process-note-heading ()
|
(defun anki-editor-map-note-entries (func &optional match scope &rest skip)
|
||||||
"Process note heading at point."
|
"Simple wrapper that calls `org-map-entries' with `&ANKI_NOTE_TYPE<>\"\"' appended to MATCH."
|
||||||
(anki-editor--push-note (anki-editor-note-at-point)))
|
;; disable property inheritance temporarily, or all subheadings of a
|
||||||
|
;; note heading will be counted as note headings as well
|
||||||
|
(let ((org-use-property-inheritance nil))
|
||||||
|
(org-map-entries func (concat match "&" anki-editor-prop-note-type "<>\"\"") scope skip)))
|
||||||
|
|
||||||
(defun anki-editor--insert-note-skeleton (prefix deck heading note-type fields)
|
(defun anki-editor--insert-note-skeleton (prefix deck heading note-type fields)
|
||||||
"Insert a note subtree (skeleton) with HEADING, NOTE-TYPE and FIELDS.
|
"Insert a note subtree (skeleton) with HEADING, NOTE-TYPE and FIELDS.
|
||||||
|
@ -480,22 +483,27 @@ Do nothing when JUST-ALIGN is non-nil."
|
||||||
(field-name (substring-no-properties
|
(field-name (substring-no-properties
|
||||||
(org-element-property
|
(org-element-property
|
||||||
:raw-value
|
:raw-value
|
||||||
field-heading))))
|
field-heading)))
|
||||||
(push (cons field-name
|
(contents-begin (org-element-property :contents-begin field-heading))
|
||||||
(or (org-export-string-as
|
(contents-end (org-element-property :contents-end field-heading)))
|
||||||
(buffer-substring
|
|
||||||
(org-element-property :contents-begin field-heading)
|
|
||||||
;; in case the buffer is narrowed,
|
|
||||||
;; e.g. by `org-map-entries' when
|
|
||||||
;; scope is `tree'
|
|
||||||
(min (point-max) (org-element-property :contents-end field-heading)))
|
|
||||||
anki-editor--ox-anki-html-backend t '(:with-toc nil))
|
|
||||||
|
|
||||||
;; 8.2.10 version of
|
(push (cons field-name
|
||||||
;; `org-export-filter-apply-functions'
|
(cond
|
||||||
;; returns nil for an input of empty string,
|
((and contents-begin contents-end) (or (org-export-string-as
|
||||||
;; which will cause AnkiConnect to fail
|
(buffer-substring
|
||||||
""))
|
contents-begin
|
||||||
|
;; in case the buffer is narrowed,
|
||||||
|
;; e.g. by `org-map-entries' when
|
||||||
|
;; scope is `tree'
|
||||||
|
(min (point-max) contents-end))
|
||||||
|
anki-editor--ox-anki-html-backend t '(:with-toc nil))
|
||||||
|
|
||||||
|
;; 8.2.10 version of
|
||||||
|
;; `org-export-filter-apply-functions'
|
||||||
|
;; returns nil for an input of empty string,
|
||||||
|
;; which will cause AnkiConnect to fail
|
||||||
|
""))
|
||||||
|
(t "")))
|
||||||
fields)
|
fields)
|
||||||
(org-forward-heading-same-level nil t))))
|
(org-forward-heading-same-level nil t))))
|
||||||
(reverse fields))))
|
(reverse fields))))
|
||||||
|
@ -558,26 +566,23 @@ of that heading."
|
||||||
((equal arg '(16)) 'file)
|
((equal arg '(16)) 'file)
|
||||||
((equal arg '(64)) 'agenda)
|
((equal arg '(64)) 'agenda)
|
||||||
(t nil))))
|
(t nil))))
|
||||||
(setq match (concat match "&" anki-editor-prop-note-type "<>\"\""))
|
|
||||||
|
|
||||||
;; disable property inheritance temporarily, or all subheadings of a
|
(let* ((total (progn
|
||||||
;; note heading will be counted as note headings as well
|
|
||||||
(let* ((org-use-property-inheritance nil)
|
|
||||||
(total (progn
|
|
||||||
(message "Counting notes...")
|
(message "Counting notes...")
|
||||||
(length (org-map-entries t match scope))))
|
(length (anki-editor-map-note-entries t match scope))))
|
||||||
(acc 0)
|
(acc 0)
|
||||||
(failed 0))
|
(failed 0))
|
||||||
(org-map-entries (lambda ()
|
(anki-editor-map-note-entries
|
||||||
(message "[%d/%d] Processing notes in buffer \"%s\", wait a moment..."
|
(lambda ()
|
||||||
(cl-incf acc) total (buffer-name))
|
(message "[%d/%d] Processing notes in buffer \"%s\", wait a moment..."
|
||||||
(anki-editor--clear-failure-reason)
|
(cl-incf acc) total (buffer-name))
|
||||||
(condition-case err
|
(anki-editor--clear-failure-reason)
|
||||||
(anki-editor--process-note-heading)
|
(condition-case err
|
||||||
(error (cl-incf failed)
|
(anki-editor--push-note (anki-editor-note-at-point))
|
||||||
(anki-editor--set-failure-reason (error-message-string err)))))
|
(error (cl-incf failed)
|
||||||
match
|
(anki-editor--set-failure-reason (error-message-string err)))))
|
||||||
scope)
|
match
|
||||||
|
scope)
|
||||||
|
|
||||||
(message (if (= 0 failed)
|
(message (if (= 0 failed)
|
||||||
(format "Successfully pushed %d notes to Anki." acc)
|
(format "Successfully pushed %d notes to Anki." acc)
|
||||||
|
|
Loading…
Reference in a new issue