Galooshi / emacs-import-js

Emacs plugin for ImportJS
MIT License
40 stars 9 forks source link

Save on window switch writes fixed import result to other window #24

Open leoc opened 6 years ago

leoc commented 6 years ago

Hi, thanks for this awesome time saving tool!

I configured import-js-fix to be run via after-save-hook. I also have configured a hook that saves the buffer when I am switching to another buffer/window. Sometimes, when I switch to another window, the "fixed code" (of the buffer I was switching away from) is written to the newly selected window buffer.

I will see whether I find time to investigate this week. I suppose a save-excursion and a buffer switch before updating fixed imports would suffice. Maybe you have a quick idea.

Peace & Love

kevinkehl commented 6 years ago

Hmm yea I see the potential problem here.

I probably won't have time to look too deeply into this until later this week at the earliest, but definitely happy to look at a PR.

Would you mind sharing your code for the buffer switching hook to reproduce?

Just brainstorming some options:

leoc commented 5 years ago

Hey, I went with the last option as the import-js response does not contain the filename in question. So I hold the buffer filename in a global variable until the response with the resolved imports comes back from the import-js process.

I see a problem there when emacs tries to resolve imports for more than one file. Probably should fill a list of buffers and work through it as the replies come in. But I do not know if import-js daemon works through the requests asynchronously?