czqhurricnae / emacs-anki-helper

Manage your Anki cards in Emacs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Anki-helper

Manage your Anki cards in Emacs 中文文档

Why Anki-helper

Currently, the main packages for creating Anki cards are eyeinsky/org-anki and louietan/anki-editor.

anki-editor requires the use of dedicated header lines to mark the front and back sides of the cards. This first leads to the inability to quickly convert existing notes into cards, requiring manual conversion; secondly, the created cards can only be used by anki-editor and cannot be integrated into existing workflows, requiring a dedicated file to store them.

org-anki solves the above shortcomings well. It uses the headline as the front side and its content as the back side. But org-anki has its own drawbacks:

Speed

Taking examples/headings.org as an example, the time comparison for synchronizing and deleting all cards (422 in total) between org-anki and anki-helper is as follows:

(benchmark 1 ‘(xxx-sync-all))(benchmark 1 ‘(xxx-delete-all))
org-anki123.855104s (35.423518s in 5 GCs)150.862886s (21.709634s in 8 GCs)
anki-helper0.410945s0.098308s

Customizability

Another issue with the org-anki is that it only applies to entries and does not provide an API for adding custom card-making functions. One advantage of having one card per entry is that it can save card information, such as card ID and whether it has been modified, making it convenient for future modifications. Another advantage is that different operations can be performed on different entries. However, some types of cards do not require this type of additional information, such as vocabulary cards. I only need to collect new words and then synchronize them with Anki, with very few modifications afterwards. Obviously, having one entry per word is quite wasteful.

The org-anki supports only two ways of filling fields: one is using the title line as the front side of the card and the content as the back side; the other is using subheadings to differentiate fields. The latter approach is similar to anki-editor. The problem here is that everyone has different habits and custom templates can be very diverse, so it is necessary to provide a set of flexible APIs to facilitate users in creating their own field filling functions.

Support for media file

The PR for image processing of org-anki has not been merged yet, and other multimedia content is also not supported.

anki-helper supports including images and audio file links in cards. These original files will be copied to the media folder of Anki.

Respect original text

For Cloze type cards, the usual practice is to use the format {{c1:xxx}}, but this will disrupt the original content and is not conducive to other operations. This is actually a kind of exclusivity.

Anki-helper uses the built-in rich text markup of org-mode as the indicator for cloze deletion. Assuming we have the following text:

*Canberra* was founded in *1913*.

will be converted into the following format while exporting to Anki:

{{c1::Canberra}} was founded in {{c2::1913}}.

Note: Following cloze deletions are not supported for now.

{{c1::Canberra}} was founded in {{c1::1913}}.

Installation

Use package.el

M-x package-vc-install RET https://github.com/Elilif/emacs-anki-helper RET

Manually

(add-to-list 'load-path "path-to-anki-helper")
(require 'anki-helper)

Usage

Variables

Global variables

  1. anki-helper-cloze-use-emphasis

    If the value is a symbol, such as bold, then the following text

    *Canberra* was founded in *1913*.
        

    will be converted into the following format while exporting to Anki:

    {{c1::Canberra}} was founded in {{c2::1913}}.
        

    Note: Following cloze deletions are not supported for now.

    {{c1::Canberra}} was founded in {{c1::1913}}.
        
  2. anki-helper-default-note-type

    Default note type.

  3. anki-helper-default-deck

    Default deck name.

  4. anki-helper-default-tags

    Default card tags.

  5. anki-helper-default-match

    Default match used in org-map-entries for sync all.

  6. anki-helper-skip-function

    Function used to skip entries.

  7. anki-helper-inherit-tags

    Inherit tags, set to nil to turn off.

  8. anki-helper-media-directory

    Default Anki media directory.

  9. anki-helper-note-types

    Default fields for note types.

file-local variables

  1. #+ANKI_DECK:
  2. #+ANKI_MATCH:
  3. #+ANKI_NOTE_TYPE:
  4. #+ANKI_TAGS:

The above keywords correspond to their respective global variables.

Properties

  1. ANKI_NOTE_TYPE
  2. ANKI_DECK

Each entry can have its own properties. The priority of the variables mentioned above is Properties > file-local variables > global variables.

Cards that are entries

A series of functions are provided by default to operate on cards of the entry type (more operations will be added later):

Functions

  1. anki-helper-entry-sync

    Turn the entry under the cursor into a card, if it is already a card, ignore it.

  2. anki-helper-entry-sync-all

    Create cards for all entries in the current buffer that meet the condition, and ignore those that are already cards.

  3. anki-helper-entry-delete

    Delete the entry under the cursor if it is a card and meets the condition.

  4. anki-helper-entry-delete-all

    Delete all cards in the current buffer that meet the specified condition.

  5. anki-helper-entry-update

    Update the entry under the cursor if it is a card and is modified.

  6. anki-helper-entry-update-all

    Update all cards in the current buffer that are modified.

Card that are not entries.

anki-helper provides several APIs:

  1. anki-helper-request
  2. anki-helper-create-note
  3. anki-helper-create-notes

Please refer to the function documentation for specific usage details.

As an example, you can refer to the functions anki-helper-set-front-region and anki-helper-make-two-sided-card, which provide an interactive card-making method:

examples/make-card-interactively.gif

Change the default behavior

Modify template field filling method

anki-helper-fields-get-alist sets two basic filed-filling functions:

  1. anki-helper-fields-get-alist

    This function is used for the “Bacis” note type of Anki, which use the raw value of the headline as the front and the content of the entry as the back.

  2. anki-helper-fields-get-cloze

    This functions is used for the “Cloze” note type of Anki, which use the content of the entry to fill the “Text” field and use the raw value of the headline to fill the “Back Extra” field.

Modify callback functions

See anki-helper-callback-alist for details.

More customization

Add backlinks to cards

See: GitHub - hwiorn/anki-open-org-note

About

Manage your Anki cards in Emacs.


Languages

Language:Emacs Lisp 100.0%