org-anki icon indicating copy to clipboard operation
org-anki copied to clipboard

Cannot convert file-level headings

Open brosasaki opened this issue 1 year ago • 5 comments

While working on #80, I found that trying to call org-anki-sync-entry on "file level" entries (i.e. entries at the top of the file where their names are given by #+TITLE) does not work, with the message wrong type argument: number-or-marker-p, nil. org-anki-sync-all also excludes file-level headings. Support for this style of heading would allow for better support for org-roam, making it an even greater addition to workflows which use that package, as well as more comprehensive use-case coverage in general.

To replicate, call org-anki-sync-entry/org-anki-sync-all on the following buffer, with org-anki-default-deck set or an #+ANKI_DECK line:

#+Title: What color is a leaf?
Green

brosasaki avatar Oct 06 '23 18:10 brosasaki

While hacking at this for a bit, it seems that the treatment of the file-level as a "node"/entry in itself is something unique to org-roam and not org as a whole. Most critically, org-map-entries does not consider the file-level as a node, and neither does org-entry-get; org-current-level returns nil at the file level instead of 0.

What this means is that getting org-anki to follow the org-roam convention would require either a lot of reinventing the wheel or the integration of functions from org-roam into the package. Maybe the latter could be done in such a way as to make org-roam an optional dependency?

brosasaki avatar Oct 06 '23 23:10 brosasaki

The main hurdle for this seems to be the need for an alternative to org-map-entries that includes the file-level, i.e. an org-roam-map-nodes. The other functions have org-roam analogues that can typically be fit in via the ((or (ignore-errors (org-function)) (ignore-errors (roam-function))) pattern; please tell me if this is bad practice.

brosasaki avatar Oct 07 '23 01:10 brosasaki

I don't know how org-roam works, is it so that one file should become one Anki note, where the #+TITLE attribute would give the Anki note front (question) and the entire body of the file would be the note back?

eyeinsky avatar Oct 09 '23 12:10 eyeinsky

@brosasaki Is the idea with issue to consider the file-level title similar to regular org entries are now? So for example in this org document:

#+title: File level title

Top level content

* First entry heading

First entry content

Would become these Anki notes:

FrontBack
File level titleTop level content
First entry headingFirst entry content

eyeinsky avatar Apr 27 '24 12:04 eyeinsky

Yes, that's the idea. I've been working on a branch https://github.com/brosasaki/org-anki/tree/org-roam-compatibility which implements these ideas, though it's still a bit hacky and certain features (skip and match functionality) aren't fully there for file-level headings.

brosasaki avatar Apr 28 '24 18:04 brosasaki