From c7ed5f352bfbe3e69b9e4bb5227e3b6094680946 Mon Sep 17 00:00:00 2001 From: louie Date: Tue, 16 Jan 2018 20:00:19 +0800 Subject: [PATCH] Add a command to insert tags --- README.org | 1 + anki-editor.el | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/README.org b/README.org index 5779fc3..d7ade25 100644 --- a/README.org +++ b/README.org @@ -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. | diff --git a/anki-editor.el b/anki-editor.el index 4b3d17c..c310dbd 100644 --- a/anki-editor.el +++ b/anki-editor.el @@ -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