louietan / anki-editor

Emacs minor mode for making Anki cards with Org
699 stars 87 forks source link

Number Cloze deletions with consecutive IDs automatically #86

Open abvbv opened 3 years ago

abvbv commented 3 years ago

If we have the next note:

anki-editor – Emacs minor mode for making Anki cards with Org

I'd like to have two Cloze deletions:

{{c1::anki-editor::what mode}} – {{c2::Emacs minor mode for making Anki cards with Org::what does it do}}

Currently anki-editor-cloze-region and anki-editor-cloze-dwim commands insert c1 deletions by default. So we can:

1) Create two deletions with either command and then manually change the ID of the second deletion from c1 to c2. 2) Use optional argument before invoking a command to set a particular ID.

The problem with both approaches is that they're error prone and quite laborious, if we have more deletions.

It would be nice to have a way to insert consecutively numbered deletions automatically.

I think (but don't have any proofs) it's more common to have deletions with different, not identical, IDs. So maybe it'd be nice to change the default behavior to automatic numbering.

P.S. Thank you for anki-editor! It's an amazing tool. It makes Anki note management a much more pleasant experience.

teeann commented 3 years ago

Hi, here's my quick fix for this. You just need to call my-anki-cloze-dwim like anki-editor-cloze-dwim

(defun my-anki-cloze-arg ()
      "Return appropriate cloze arg of current anki entry"
      (interactive)
      (let ((index 1))
    (save-excursion
      (goto-char (org-entry-beginning-position))
      (while
          (search-forward (format "{{c%d::" index) (org-entry-end-position) t)
        (cl-incf index)
        (goto-char (org-entry-beginning-position)))
      index)))

(defun my-anki-cloze-dwim ()
  (interactive)
  (let ((current-prefix-arg (my-anki-cloze-arg)))
    (call-interactively 'anki-editor-cloze-dwim)
    )
  )