Optimize tag command

This commit is contained in:
louie 2018-02-10 21:28:57 +08:00
parent 46461874b3
commit 7270842948
2 changed files with 28 additions and 15 deletions

View file

@ -51,18 +51,19 @@ anki-editor -- Make Anki Cards in Org-mode
** Command Cheatsheet ** Command Cheatsheet
| Command | Brief Description | | Command | Brief Description |
|-----------------------------------------------+------------------------------------------------------| |-----------------------------------------------+---------------------------------------------------------------------|
| =anki-editor-submit= | Send notes in current buffer to Anki. | | =anki-editor-submit= | Send notes in current buffer to Anki. |
| =anki-editor-insert-deck= | Insert a deck heading. | | =anki-editor-insert-deck= | Insert a deck heading. |
| =anki-editor-insert-note= | Insert the skeleton of a note. | | =anki-editor-insert-note= | Insert the skeleton of a note. |
| =anki-editor-insert-tags= | Insert tags at point with autocompletion. | | =anki-editor-add-tags= | Add tags to property drawer of current heading with autocompletion. |
| =anki-editor-cloze-region= | Cloze region. | | =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-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. | | =anki-editor-convert-region-to-html= | Convert and replace region to HTML. |
Note that =anki-editor-submit= will fail if the deck does not exist
yet. New decks must be created in Anki first.
Note that =anki-editor-submit= will fail if the deck does not exist
yet. New decks must be created in Anki first.
*Since I'm not a native English speaker, let me know if there's any ambiguity or grammatical mistakes.* *Since I'm not a native English speaker, let me know if there's any ambiguity or grammatical mistakes.*

View file

@ -303,11 +303,23 @@ Otherwise, it's inserted below current heading at point."
(anki-editor--insert-note-skeleton note-heading note-type fields))))) (anki-editor--insert-note-skeleton note-heading note-type fields)))))
;;;###autoload ;;;###autoload
(defun anki-editor-insert-tags () (defun anki-editor-add-tags ()
"Insert tags at point with autocompletion." "Add tags to property drawer of current heading with autocompletion."
(interactive) (interactive)
(let ((tags (sort (anki-editor--anki-connect-invoke-result "getTags" 5) #'string-lessp))) (let ((tags (sort (anki-editor--anki-connect-invoke-result "getTags" 5) #'string-lessp))
(while t (insert (format " %s" (completing-read "Choose a tag: " tags)))))) (prop (substring (symbol-name anki-editor-prop-note-tags) 1)))
(while t
(let ((existing (or (org-entry-get nil prop) "")))
(org-entry-put
nil prop
(concat
existing
(format " %s"
(completing-read "Choose a tag: "
(cl-set-difference
tags
(split-string existing " ")
:test #'string-equal)))))))))
;;;###autoload ;;;###autoload
(defun anki-editor-cloze-region (&optional arg) (defun anki-editor-cloze-region (&optional arg)