Add a command to insert tags

This commit is contained in:
louie 2018-01-16 20:00:19 +08:00
parent e3196d3554
commit c7ed5f352b
2 changed files with 12 additions and 0 deletions

View file

@ -57,6 +57,7 @@ anki-editor -- an Emacs package that helps you create Anki cards in Org-mode
| =anki-editor-submit= | C-c a s | Send notes in current buffer to Anki. |
| =anki-editor-insert-deck= | C-c a i d | Insert a deck heading with the same level as current heading. |
| =anki-editor-insert-note= | C-c a i n | Insert the skeleton of a note. |
| =anki-editor-insert-tags= | C-c a i t | Insert a tag at point with autocompletion. |
| =anki-editor-export-heading-contents-to-html= | C-c a e | Export the contents of the heading at point to HTML. |
| =anki-editor-convert-region-to-html= | N/A | Convert and replace region to HTML. |
| =anki-editor-anki-connect-upgrade= | N/A | Upgrade anki-connect to the latest version. |

View file

@ -139,6 +139,16 @@ that correspond to fields."
(end-of-line)
(newline-and-indent)))
;;;###autoload
(defun anki-editor-insert-tags ()
"Insert a tag at point with autocompletion."
(interactive)
(let* ((response (anki-editor--anki-connect-invoke "getTags" 5))
(result (alist-get 'result response))
(err (alist-get 'error response)))
(when err (error err))
(while t (insert (format " %s" (completing-read "Choose a tag: " result))))))
;;;###autoload
(defun anki-editor-export-heading-contents-to-html ()
"Export the contents of the heading at point to HTML."
@ -167,6 +177,7 @@ that correspond to fields."
(setq anki-editor--key-map `((,(kbd "C-c a s") . ,#'anki-editor-submit)
(,(kbd "C-c a i d") . ,#'anki-editor-insert-deck)
(,(kbd "C-c a i n") . ,#'anki-editor-insert-note)
(,(kbd "C-c a i t") . ,#'anki-editor-insert-tags)
(,(kbd "C-c a e") . ,#'anki-editor-export-heading-contents-to-html)))
;;;###autoload