Add a command to cloze region

This commit is contained in:
louie 2018-01-31 23:08:24 +08:00
parent 971181df30
commit 8523ddb9c1
2 changed files with 15 additions and 0 deletions

View file

@ -55,6 +55,7 @@ anki-editor -- Make Anki Cards in Org-mode
| =anki-editor-insert-deck= | Insert a deck heading. |
| =anki-editor-insert-note= | Insert the skeleton of a note. |
| =anki-editor-insert-tags= | Insert a tag at point with autocompletion. |
| =anki-editor-cloze-region= | Cloze region. |
| =anki-editor-export-heading-contents-to-html= | Export the contents of the heading at point to HTML. |
| =anki-editor-convert-region-to-html= | Convert and replace region to HTML. |

View file

@ -279,6 +279,20 @@ Otherwise, it's inserted at point."
(let ((tags (sort (anki-editor--anki-connect-invoke-result "getTags" 5) #'string-lessp)))
(while t (insert (format " %s" (completing-read "Choose a tag: " tags))))))
;;;###autoload
(defun anki-editor-cloze-region (&optional arg)
"Cloze region with number ARG."
(interactive "p")
(unless (region-active-p) (error "No active region"))
(let ((region (buffer-substring (region-beginning) (region-end)))
(hint (read-from-minibuffer "Hint (optional): ")))
(save-excursion
(delete-region (region-beginning) (region-end))
(insert (with-output-to-string
(princ (format "{{c%d::%s" (or arg 1) region))
(unless (string-empty-p (string-trim hint)) (princ (format "::%s" hint)))
(princ "}}"))))))
;;;###autoload
(defun anki-editor-export-heading-contents-to-html ()
"Export the contents of the heading at point to HTML."