eyeinsky / org-anki

Sync org notes to Anki via AnkiConnect
BSD 3-Clause "New" or "Revised" License
180 stars 28 forks source link

Field templating #58

Closed eyeinsky closed 1 year ago

eyeinsky commented 1 year ago

Attempting to solve adding backlinks issue: https://github.com/eyeinsky/org-anki/issues/18

One can now do:

(customize-set-variable
 'org-anki-field-templates
 '(("Basic"
    ("Back" . (lambda (it)
                (let ((path (buffer-file-name)))
                  (concat it (format "<p><a href='%s'>%s</a></p>" path path))))))))

to add a backlink or any other content to the field value. (The it in the lambda is the original string, and the backlink html is concatenated to the end of it.)

@panmengguan, @hwiorn Please test if you feel like it :)

eyeinsky commented 1 year ago

And if you have any ideas on how to make this more ergonomic, then ideas welcome. (I.e applying a function to the field content is the most powerful way to do this, but perhaps there is something more elegant?)

I did also try to have the lambda anaphoric (how the ---prefixed functions work in dash), but couldn't make it work. Something like this:

(customize-set-variable
 'org-anki-field-templates
 '(("Basic"
    ("Back" . (-let [path (buffer-file-name)]
                (concat it (format "<p><a href='%s'>%s</a></p>" path path)))))))