nick91700 · 2022-08-02 21:36
I am an avid anki user who has a large collection of cards in anki. I've looked into org drill but I don't want to use it as I'd like to stick with anki for spaced repitition. But oftentimes, I'll be in emacs and would like to search my anki collection. I also know about anki-editor to export org mode "cards" to anki, which in the future can work to search the cards I created in org, but what I'd really like to be able to search my current anki collection from emacs to see if a fact exists in one of my anki decks.
​
Is this possible? I've seen anki2org package that can convert anki cards to org mode, and maybe this could work but I'd like to have org mode be able to just read my .apkg files without having to constantly convert it manually.
french_pressed · 2022-08-03 02:03
At one point I was working on a package to do this. The approach was to use [Anki Connect](https://ankiweb.net/shared/info/2055492159) to do all of the interaction with Anki and then just display things in Emacs.
I don't think I really ever got it to a polished state but I can take a look for the code tomorrow and share what I have.
organic-bookworm · 2022-08-03 06:12
Didn't try myself, but read about [org-anki](https://github.com/eyeinsky/org-anki/). It provides `org-anki-import-deck` and `org-anki-sync-all` commands to round-trip cards.
nick91700 · 2022-08-04 17:29
thanks for the suggestion. I checked it out, but because I have a lot of different card types I keep getting the error "unsupported card type"
orgtre · 2022-08-15 13:06
I'd also be interested in this!
french_pressed · 2022-08-15 13:47
Apologies for the delayed response. I did take a look for the code and it's not on my computer. It should be on a hard drive, i just haven't had a chance to check. I hope to look today and will share.
orgtre · 2022-08-15 14:12
Thanks. I'm interested since I wrote some similar code a year or so ago, which however didn't work too well. Edit: I shared that code at top level now.
orgtre · 2022-08-15 21:30
Some time back I faced a similar problem when I wanted to migrate all my existing Anki notes to Emacs anki-editor (and also sync back and forth between them). It ended up being quite the undertaking and was never published – until now: [https://github.com/orgtre/ankiorg](https://github.com/orgtre/ankiorg).
Its main command `ankiorg-pull-notes` works on a per-deck basis, but to get all notes you could use the following:
(defun ankiorg-pull-all-notes ()
"Pull all notes from Anki to org."
(interactive)
(let ((note-ids (if anki-editor-use-sql-api
(anki-editor-sql-get-ids-in-anki)
(anki-editor-api-call-result 'findNotes :query "deck:*"))))
(anki-editor-create-org-notes note-ids)))
Much of the code is for other things like converting the Anki note from html to org and bringing it in anki-editor form, so for your purposes somethings smaller would probably suffice, but it should work for getting all notes (which can then be searched from Emacs). It also gives you the option to either interface via Anki-Connect or more directly with Anki's SQL database.
To search notes directly, without first loading all of them into Emacs, change the query above to a custom search query, e.g.:
(defun ankiorg-search-all-notes (query)
"Search all notes in Anki and pull matches to org."
(interactive (list (read-string "query: ")))
(let ((note-ids (anki-editor-api-call-result 'findNotes :query query)))
(anki-editor-create-org-notes note-ids)))
Originally this was intended as a pull request to anki-editor, but due to the messy code (this is among the first elisp I've written), the lack of maintenance, and the emergence of [org-anki](https://github.com/eyeinsky/org-anki) it never happened.
french_pressed · 2022-08-18 14:31
Okay, finally threw it into a repository [here](https://github.com/kevinjfoley/anki-emacs/blob/main/anki.el).
It's been two years since I touched it but the main features are `anki-create-note` and `anki-edit-note`, which let's you work with notes in an org mode format and then submit them to Anki.
I thought I had also worked on a tabulated list of notes based on a search but it looks like I hadn't.
c.c. /u/nick91700