Giter VIP home page Giter VIP logo

Comments (6)

hwiorn avatar hwiorn commented on September 17, 2024 1

How did you come about in running in to this, do you run an elisp script to sync certain files without having the files themselves open?

Yes. I'm writing the code to generate and sync anki cards from part of my org files which have :ANKI: tag automatically without user interaction. I, sometimes, forget to sync anki after editing bunch of my prompts following org-roam backlinks. I figure out batch ankifying is really useful if prompts are prepared already in the org files. You can see the test code is just simplyfing the error case. It's not real usecase.

I think I did manage to reproduce it by having test.org closed, then running the test code above from the M-: (eval-expression) minibuffer prompt.

Yes. Ensure the test file is closed and call the test code from scratch buffer or M-x <org-anki-sync-batch>(if you defined as an interactive function).

from org-anki.

threddast avatar threddast commented on September 17, 2024 1

I'm running into the same problem: even though calling org-anki-sync-entry succeeds and the note is created in anki, no ANKI_NOTE_ID property is created at the header.

I'm on emacs 29, org-mode 9.6-??-bed47b4

from org-anki.

hwiorn avatar hwiorn commented on September 17, 2024

After some digging, I found the cause of this issue is that org-anki uses anki-connect API request as asynchronous call. So, org-anki-sync-entry can't org-set-property in the buffer which is closed already.

@eyeinsky Is there any other way to solve this? emacs-request provides :sync keyword only. I feel buffer-local variable is a more reasonable option for this issue.

from org-anki.

hwiorn avatar hwiorn commented on September 17, 2024

I thought adding sync buffer-local variables fix this issue simply. But I found that org-anki is using emacs-promise as well as emacs-request.

Actually buffer-name is changed to *scratch* from test.org when then clause of promise-chain is executed.

org-anki/org-anki.el

Lines 434 to 443 in dda524d

(defun org-anki--sync-notes (notes)
;; :: [Note] -> IO ()
"Syncronize NOTES."
(if notes
(promise-chain
(org-anki--existing-tags notes)
(then
(lambda (all-existing-tags)
(let*

In addition, I found this chuntaro/emacs-promise#13

According to the above issue, The below with-current-buffer clause has a same potential issue.

org-anki/org-anki.el

Lines 542 to 548 in dda524d

(defun org-anki-sync-all (&optional buffer)
;; :: Maybe Buffer -> IO ()
"Syncronize all entries in optional BUFFER."
(interactive)
(with-current-buffer (or buffer (buffer-name))
(org-anki--sync-notes
(org-map-entries 'org-anki--note-at-point (org-anki--get-match) nil org-anki-skip-function))))

from org-anki.

eyeinsky avatar eyeinsky commented on September 17, 2024

How did you come about in running in to this, do you run an elisp script to sync certain files without having the files themselves open?

I think I did manage to reproduce it by having test.org closed, then running the test code above from the M-: (eval-expression) minibuffer prompt.

from org-anki.

hwiorn avatar hwiorn commented on September 17, 2024

I managed to handle this. In order to solve this issue, it needs the synchronous emacs-promise and the synchronous emacs-request. sync request can be solved by #56. But emacs-promise side, it needs await of the async-await module.
async-await doesn't block main thread. I think async-await can be applied into org-anki.

After applying #56, You can make an anki card using below code.

(require 'async-await)
(funcall (async-lambda () 
                      (with-current-buffer (find-file-noselect "~/test.org")
                        (org-mode)
                        (setq org-anki-sync-request t)
                          (save-excursion
                            (goto-char (point-max))
                            (await (org-anki-sync-entry)))
                          (save-buffer)
                          (kill-buffer))
                        (message "done")))

from org-anki.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.