emacs-import-js icon indicating copy to clipboard operation
emacs-import-js copied to clipboard

Save on window switch writes fixed import result to other window

Open leoc opened this issue 7 years ago • 2 comments

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

leoc avatar Jul 09 '18 07:07 leoc

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:

  • Wait to switch until the update is complete (not ideal, since it blocks your flow, and I don't think we want that)
  • Guess the buffer name from the import-js output filename, set the local current buffer before writing data
  • Somehow associate the buffer under operation with the command?

kevinkehl avatar Jul 09 '18 18:07 kevinkehl

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?

leoc avatar Mar 13 '19 15:03 leoc