help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: global-company-mode and company-mode


From: thibaut . verron
Subject: Re: global-company-mode and company-mode
Date: Tue, 2 Aug 2022 13:09:21 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0

On 02/08/2022 12:26, wilnerthomas--- via Users list for the GNU Emacs text editor 
<help-gnu-emacs@gnu.org> wrote:

I do not understand how to enable `company-mode'.  Because there is 
(company-mode 1)
and `(add-hook 'after-init-hook 'global-company-mode)'.

What is the difference between the two. 

(company-mode 1) only turns the mode on in the current buffer, 
(global-company-mode 1) turns it on in every existing buffer, and will turn it 
on in every future buffer (except for buffers not visiting a file and with the 
fundamental-mode).

https://www.gnu.org/software/emacs/manual/html_node/elisp/Defining-Minor-Modes.html

Why 'after-init-hook is used, cannot there just be
(global-company-mode 1)?

I am not sure, but I suspect it is to make sure that all packages which might 
change the way company-mode works are already loaded at the time of activation.

But then again, the main effect of (global-company-mode 1) at that point is to tell future buffers to activate company-mode, which would be after initialization anyway. Even the *scratch* buffer (usually the only editable buffer created at initialization) should be in fundamental-mode at the time of running of the hook, so it isn't affected by global-company-mode.

So the two calls might not be strictly equivalent, but I believe that they 
would be indistinguishable in most use-cases.



When using `add-hook', how would I disable `global-company-mode' later?


The hook is run only once, when starting emacs, so it doesn't matter in a 
running emacs.
Just call (global-company-mode -1) to disable it later. Note that it should 
also disable company-mode in all buffers where the global setting was applied 
(and not overridden by a local (company-mode 1)). (I think, at least. I always 
end up confused by the semantics of disabling global vs local modes.)

Best wishes,
Thibaut



reply via email to

[Prev in Thread] Current Thread [Next in Thread]