Closed marienz closed 3 years ago
I have the same problem:
If I use counsel-find-file
directly after starting emacs, it works. But if I call eshell-command
before, it fails to switch directories, with the error that company-frontend is void. When I use company-mode before calling eshell-command
, everything works fine.
I was trying to make spacemacs//eshell-switch-company-frontend
work without (auto)loading company, but that is a little silly. It's only used by shell/pre-init-company
, which adds it to eshell-mode-hook
. But it calls spacemacs|add-company-backends
with :modes eshell-mode
immediately before, which adds company-mode
to eshell-mode-hook
.
And sure enough, changing the add-hook call to (add-hook 'eshell-mode-hook 'spacemacs//eshell-switch-company-frontend t)
fixes it, by putting it after company-mode
on eshell-mode-hook
. That's a nicer fix because we don't need to worry about setq-local
running while the wrong buffer is current, but it could potentially break the same way it currently does if the order in which eshell-mode-hook
is populated changes.
So adding an explicit (require 'company)
to spacemacs//eshell-switch-company-frontend
to make sure the global version of company-frontends
is set (either instead of or in addition to adding the function to the end of eshell-mode-hook
) seems wise. Worst case for that is some unnecessary load time, and currently we're incurring that load anyway (immediately afterwards, without the reordering).
Is there a patch or PR for this issue?
I haven't sent a PR / attached a patch mostly because I can't make up my mind on which fix is better. But if you make one or both of the following changes, that should fix it:
layers/+tools/shell/packages.el
, change (add-hook 'eshell-mode-hook 'spacemacs//eshell-switch-company-frontend)
to (add-hook 'eshell-mode-hook 'spacemacs//eshell-switch-company-frontend t)
layers/+tools/shell/funcs.el
, add (require 'company)
above (setq-local company-frontends '(company-preview-frontend))
I have this too. I'll try out the fix above.
I unexpectedly ran into this bug this morning, and went ahead and made a patch. See #9360
@marienz good research work, thank you. I prefer requiring company
directly, because it's a 100% solution and doesn't rely on the functions' order in the hook (that may change in the future because of other reasons, who knows). @benjamreynolds I've commented on the PR accordingly.
Now fixed in develop. The fix will arrive in master branch in the next release.
Still running into this.
@xe Are you running the current version of the develop
branch? This should be fixed there (assuming new changes didnt cause a regression to my patch) but still occurring on master.
I am running git master. How do you switch to develop?
From your .emacs.d
directory run git checkout develop
, but I would be careful with this and probably run spacemacs/ediff-dotfile-and-template
. The develop branch is pretty far ahead of master at this point, but I do believe we are getting close to the 0.300
release. (Friendly ping @syl20bnr, is there a tracking issue or milestone for the nest release?)
I can still reproduce this.
This still happens
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!
Description :octocat:
Spacemacs breaks if eshell is used before
company
is loaded.Reproduction guide :beetle:
shell
andauto-completion
layers loaded (may also needivy
, I did not test with helm).SPC '
in my configuration,SPC SPC eshell RET
probably works too).SPC b h
to open the*spacemacs*
buffer should do).SPC b b
), usedescribe-variable
, or one of many other things.Observed behaviour: :eyes: :broken_heart: Most commands fail with "void-variable company-frontends".
Using
featurep
anddescribe-variable
from eshell immediately after opening eshell shows company did load, but the global value for company-frontends did not get set:I think what happened is that
spacemacs//eshell-switch-company-frontend
setcompany-frontends
buffer-locally, and thencompany
got autoloaded while that buffer-local binding was in effect. defcustom and defvar warn against this (they recommend loading files containing defvar or defcustom outside of any local bindings, which seems not very practical for autoloads). The value ofeshell-mode-hook
fits:spacemacs//init-company-eshell-mode
presumably triggers autoloading ofcompany
and comes afterspacemacs//eshell-switch-company-frontend
.I've tried adding a
with-eval-after-load 'company
around thesetq-local
inspacemacs//eshell-switch-company-frontend
, and that fixed it.company-frontend
in the eshell buffer is now:However, I'm not sure if that fix is entirely correct. If company is not immediately autoloaded (while eshell is still the current buffer), the
setq-local
would presumably run on the wrong buffer.Expected behaviour: :heart: :smile: No errors.
System Info :computer:
Backtrace :paw_prints: