reddit / emacs

Why does company-mode need to be restarted even though its loaded?

metacontent · 2022-01-31 00:08
After restarting Emacs, company-mode doesn't provide completions until I restart it. I have `global-company-mode` set to `t` in my init.el file. After restarting, if I run `M-x global-company-mode` the minibuffer responds "global company mode disabled" Then when I run `M-x global-company-mode` again the minibuffer responds "global company mode enabled" which seems to indicate global-company-mode is enabled when I restart Emacs, but it just doesn't give completions. Once company-mode is restarted, then it runs exactly as expected. This isn't a big deal because I don't restart Emacs that often, but it's annoying, and I can't figure out what is wrong. Any suggestions? Below are the relevant parts of my init.el file. The entire file can be found [here](https://github.com/metacontent/emacs.d/blob/main/init.el). Edit: This is fixed now. (use-package company :ensure t :bind (:map company-active-map ("C-n" . company-select-next) ("C-p" . company-select-previous)) :config (setq company-show-quick-access 'left) (setq company-backends '((company-capf company-dabbrev-code))) (setq company-tooltip-flip-when-above t) :custom ;;use M-[asdfg] keys for quick completions (company-quick-access-keys '("a" "s" "d" "f" "g")) (company-quick-access-modifier 'meta) :custom-face ;; set the face manually to fixed-width (company-tooltip ((t (:family "Source Code Pro")))) :hook (prog-mode . company-mode))
izut · 2022-01-31 00:12
Try loading the mode after you've configured it.
metacontent · 2022-01-31 00:23
I have tried putting it at the bottom of the :config section, but there is no change.
izut · 2022-01-31 00:26
There are differences between :config and :init in use-package; I'd look it's documentation. It seems that the global mode gets enabled before it gets configured, so it works when you disable and enable it again manually since the right configuration is now in place.
metacontent · 2022-01-31 03:30
That was basically it. I'm not sure exactly what the problem was, but I've managed to fix the issue by turning off `global-company-mode` and then putting ":hook (prog-mode . company-mode)" at the very end, this way company only gets loaded once I actually start to edit a prog-mode file, and as you said, by then the configuration is in place. Thanks for the help.
gulpgaming · 2022-01-31 13:35
Your issue is that instead of `(setq global-company-mode t)` you need to run `(global-company-mode)`. Reason being: that *variable* is used as an indicator to check if it's turned on or off, and isn't used to actually toggle it.