4

I used global-company-mode from my .emacs like this:

(add-hook 'after-init-hook 'global-company-mode)

Now I’m trying to move to use-package, like this:

(use-package company
  :config
  (global-company-mode))

Now if I check with C-h m, company-mode is said to be active, but it’s not listed on my modeline (I don’t use anything that would hide it). And it actually works, as I get the company popup, when I start typing a function or variable name.

whitespace-mode is much worse, though:

(use-package whitespace
  :ensure t  ;; I also tried without this line
  :config
    (global-whitespace-mode)
  :bind
  (([f10] . whitespace-mode)
   ([(shift f10)] . global-whitespace-mode)))

Now WS doesn’t appear on my modeline as expected (again, I don’t hide anything) and I cannot see its effects like the end-of-line marker $ characters, and it’s not even listed when I press C-h m. But when I press shift f10, it says

Global Whitespace mode disabled

and when I press it again, I get the message that it got enabled, and I can also see the effects in all my buffers (and in C-h m).

What am I missing?

Edit: I just realised that diminish is actually installed as a dependency (I’m trying to figure out what pulled it in). However, diminished-mode-alist is nil, so I don’t think that’s the reason of mode names not displaying in my mode line (correct me if I’m wrong).

Edit2: deferring loading the diminish package solved the company problem, but the whitespace related one still persists.

  • that is strange. Try putting this in your .emacs and see if company-mode is not appearing in mode-line :- (use-package diminish :defer t). You'd have to restart emacs after you modify .emacs – Chakravarthy Raghunandan Oct 12 '16 at 15:09
  • that solved the company-related problem, but the whitespace thing still remains… – GergelyPolonkai Oct 12 '16 at 17:15
  • how about enabling whitespace-mode like so :- (add-hook 'prog-mode-hook 'whitespace-mode) ? – Chakravarthy Raghunandan Oct 12 '16 at 17:41
  • I actually used after-init-hook before switching to use-package; it worked fine. The strange thing here is that the global-whitespace-mode is t, yet, its effects are not visible unless I toggle it twice. – GergelyPolonkai Oct 12 '16 at 20:38
8

I don't know why company-mode is getting diminished, but I think I know what's going on with whitespace-mode. Your block

(use-package whitespace
  :ensure t  ;; I also tried without this line
  :config
    (global-whitespace-mode)
  :bind
  (([f10] . whitespace-mode)
   ([(shift f10)] . global-whitespace-mode)))

will automatically defer loading the whitespace package because it includes a :bind. So nothing happens until you press S-<f10>, at which time the package gets loaded, your :config block runs, and global-whitespace-mode is enabled. Then your keypress is processed, and the mode is promptly disabled again. There are three solutions that occur to me:

  1. You could change your :config into an :init and rely on the fact that global-whitespace-mode is autoloaded to load the package for you.

  2. You could add a :demand t line, to cancel :bind's deferment.

  3. You could add :defer N, where N is an integer. This will trigger loading whenver Emacs is idle for N seconds.

All of these options are detailed in the C-h f help for the use-package macro, for further reference.

  • Indeed, and it is actually in the docstring, thanks for pointing me towards it. I wasn’t checking all the options I can pass to use-package, and :demand slipped my eye. Maybe it would worth it to update the :bind documentation so it tells you about this deferring. – GergelyPolonkai Oct 13 '16 at 9:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.