louietan / anki-editor

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

Custom faces for Anki's cloze syntax #80

Open bnjmnt4n opened 3 years ago

bnjmnt4n commented 3 years ago

I'm pretty new to Emacs, so please correct my understanding if I make any mistakes.

Currently inserting clozes using Anki's cloze deletion syntax {{c1::....}} leads to a lot of extra noise in the Org file. It would be great if there were some sort of way to mark this syntax as an Anki-related face, so they can be de-emphasized if desired. My understanding is that Emacs has a faces mechanism for this. I'll do a bit of reading to see how something like this can be done, but just wanted to post this on the issue tracker to see if anyone has done anything similar or has any suggestions.

meedstrom commented 2 years ago

I agree about visual noise. Here's a basic approach, though it'll affect all modes.

(font-lock-add-keywords nil '(("{{c.::" . font-lock-comment-face)
                                             ("}}" . font-lock-comment-face)))

An alternative is to use prettify-symbols-alist to hide these parts entirely. Side note, prettify-symbols doesn't allow regexps, so you'd you need a rule for each of c1::, c2::, c3::... up to some appropriate max (c30?).

A second alternative is to just make square brackets [] a shorthand that anki-editor will automatically turn into {{cN:: in incrementing order upon push, so it has the same look and feel as org-drill. Of course it'd be clumsy if you want to reuse the same N in several sentences, but the user could just type out the proper syntax in those cases. It'd also be unclean when editing a mature note and removing some clozes, as the numbers will change. I wouldn't be concerned if I did this as part of a fork aimed at minimal visual clutter (e.g.: cloze is the only note type allowed, with only one field, so you need no subheadings).