[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: global-company-mode and company-mode
From: |
wilnerthomas |
Subject: |
Re: global-company-mode and company-mode |
Date: |
Tue, 2 Aug 2022 13:15:30 +0200 (CEST) |
Aug 2, 2022, 11:09 by thibaut.verron@gmail.com:
> 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.)
>
Right. Is there the command (global-company-mode -1) available? What if I
want to enable global-company-mode, would I use the hook?