dictionary-overlay icon indicating copy to clipboard operation
dictionary-overlay copied to clipboard

(sit-for 1) needed for dictionary-overlay-start to finish loading?

Open qingshuizheng opened this issue 2 years ago • 2 comments

Not sure how you usually use this package.

I usually go to the target buffer, and "M-x dictionary-overlay-render-buffer RET", and wait for magic to happen.

There's a hiccup for this method, when dictionary-overlay has not started, and dictionary-overlay-refresh-buffer is chasing after, this happens:

image

https://github.com/ginqi7/dictionary-overlay/blob/47edbebccfed9f60db85cc767d85292c868c4629/dictionary-overlay.el#L249-L255

As a workaround, I add (sit-for 1) to make it wait for .py to finish loading, but quite ugly. Wondering if there's an elegant way to address it.

(defun dictionary-overlay-render-buffer ()
  "Render current buffer."
  (interactive)
  (when (not (member "dictionary-overlay" websocket-bridge-app-list))
    (dictionary-overlay-start)
    ;; wait 1 sec for "dictionary-overlay.py" to finish loading
    (sit-for 1))
  (setq-local dictionary-overlay-active-p t)
  (dictionary-overlay-refresh-buffer))

qingshuizheng avatar Nov 28 '22 06:11 qingshuizheng

This is a troublesome issue. Emacs calls the python function asynchronous. When the python function finishes, Emacs don't know the result of python.

I thought we could do this:

  1. When the python function finishes, call the emacs function to tell emacs that it is ready.(with a variable save the status)
  2. Add a checker to check if a websocket-bridge-app is ready. If not, send a message to the user, please wait.

and you could add (dictionary-overlay-start) in your init config, so it has been finished when you need it.

Maybe sleeping 1 second is too extreme, it will stick Emacs.

ginqi7 avatar Nov 28 '22 09:11 ginqi7

Maybe sleeping 1 second is too extreme

It is.

you could add (dictionary-overlay-start)

Stupid me, with this configured, nothing more.

I thought we could do this: with a variable save the status.

I'm gonna leave that to you. 😀 Not something urgent, take your time.

qingshuizheng avatar Nov 28 '22 10:11 qingshuizheng