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.

GergelyPolonkai
  • 758
  • 6
  • 12

1 Answers1

11

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.

Aaron Harris
  • 2,684
  • 17
  • 22
  • 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 09:15