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

anki-editor-push-notes ignores source block headers on execution

Open omidmnz opened this issue 6 years ago • 3 comments

I use Noweb reference syntax to embed some code in all my source blocks, which needs :noweb yes in the source blocks' headers. The code works perfectly fine when I execute the block myself, but anki-editor-push-notes executes the blocks without the header, which leads to wrong outputs. I tried :cache yes to avoid the problem, but anki-editor-push-notes seems to ignore that too. Here is a minimal example:

* Noweb Test                                                       :noexport:
  #+name: enable_noweb
  #+begin_src python
    noweb = True
  #+end_src

* Noweb Test
  :PROPERTIES:
  :ANKI_NOTE_TYPE: Basic
  :ANKI_DECK: OrgTestDeck
  :ANKI_NOTE_ID: 1536670156877
  :END:

** Front
   Noweb Enabled?

** Back
  #+begin_src python :exports results :results output :noweb yes
    noweb = False
    <<enable_noweb>>
    print("Noweb {0}.".format("enabled" if noweb else "not enabled"))
  #+end_src

  #+RESULTS:
  : Noweb enabled.

The result of manual execution is Noweb enabled. as expected, but the pushed card reads Noweb not enabled.. I am using Emacs 26.1, with Org Mode 9.1.14, and the latest anki-editor on Melpa.

omidmnz avatar Sep 11 '18 12:09 omidmnz

This "unexpected behavior" involves the way anki-editor works, that when it is building the content of a field, it does the exporting on the region of subtree of that field entry, this way Org has no idea where that noweb block is defined, but when you evaluate the source block, Org will search backward the buffer for the definition of the noweb block.

louietan avatar Sep 23 '18 19:09 louietan

Thanks for clarification. Should I consider this as a "Won't Fix" tag?

omidmnz avatar Sep 28 '18 15:09 omidmnz

This also prevents globally set headers (#+PROPERTY: header-args ..., see https://orgmode.org/manual/Property-Syntax.html ) from working properly. Interestingly, interactively calling anki-editor-export-subtree-to-html (which is defined but never used in anki-editor.el) with the point inside the respective body returns the correct result for me (i.e. respects the global header args) - is there a reason to prefer using org-export-string-as in anki-editor--build-fields over using this (or the method used there)?

marzipankaiser avatar Nov 01 '20 21:11 marzipankaiser