Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Large amount of *gocode* buffers when company-go--invoke-autocomplete has an error #435

Closed
bmag opened this issue Mar 3, 2017 · 7 comments

Comments

@bmag
Copy link

bmag commented Mar 3, 2017

In company-go--invoke-autocomplete, if call-process-region encounters an error then the temporary *gocode* buffer isn't killed, resulting in many *gocode* temporary buffers accumulating in the background. It seems that using with-temp-buffer instead of generate-new-buffer or condition-case instead of prog2 (and suitable refactoring) should fix this.

Original report: syl20bnr/spacemacs#7979

@bmag bmag changed the title Large amount of *gocode* when company-go--invoke-autocomplete has an error Large amount of *gocode* buffers when company-go--invoke-autocomplete has an error Mar 3, 2017
@nsf
Copy link
Owner

nsf commented Mar 3, 2017

The question is - why. Script has kill-buffer at the end there. And it worked well for years. What changed?

@bmag
Copy link
Author

bmag commented Mar 3, 2017

In the particular case reported to Spacemacs, the user didn't have a necessary program installed, causing an (expected) error in the call to apply. It seems to me the code doesn't have any error handling.

@nsf
Copy link
Owner

nsf commented Mar 3, 2017

Makes sense. Will try using with-temp-buffer then.

@nsf
Copy link
Owner

nsf commented Mar 3, 2017

I think I fixed it, but please take a look at the code. I'm not very good with elisp. Also maybe there is a simpler way to do it? It's just a bit messy. I need to get args from current buffer, stuff like cursor position, then I need to create a temporary buffer and get its name for call-process-region destination, then I switch to the code buffer (because call-process-region uses its contents), but I had to remember its name before that. And I return the contents of the temporary buffer. Looks like a giant mess. Cleanup patches are welcome.

@bmag
Copy link
Author

bmag commented Mar 3, 2017

I looked at it, I'm not sure there's a cleaner way to write the code with with-temp-buffer. However, we can replace prog2 with unwind-protect (I know I mentioned condition-case earlier, but that's because I forgot about unwind-protect):

(unwind-protect
    (progn
      (apply #'call-process-region
             (point-min)
             (point-max)
             company-go-gocode-command
             nil
             temp-buffer
             nil
             gocode-args)
      (with-current-buffer temp-buffer (buffer-string)))
  (kill-buffer temp-buffer))

What this code does, is that it calls kill-buffer even if there's an error inside the progn.

@nsf
Copy link
Owner

nsf commented Mar 3, 2017

Well, ok, let's keep it this way then, feel free to close the issue if with-temp-buffer one works for you.

@bmag
Copy link
Author

bmag commented Mar 4, 2017

I'm closing the issue because I'm fairly certain the issue is solved. I haven't actually test it because I wasan't affected by it. @InvisibleTech @rbrtl @nyxwulf if you can confirm this works it'd be nice (this only fixes the *gocode* buffers, not the *go-eldoc* buffers)

@bmag bmag closed this as completed Mar 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants