all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: thibaut.verron@gmail.com
To: help-gnu-emacs@gnu.org
Subject: Re: global-company-mode and company-mode
Date: Tue, 2 Aug 2022 13:09:21 +0200	[thread overview]
Message-ID: <48e6e2a9-7cb2-1899-47f7-188c49125f1b@gmail.com> (raw)
In-Reply-To: <N8T4wgJ--3-2@tutanota.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.)

Best wishes,
Thibaut



  reply	other threads:[~2022-08-02 11:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-02 10:26 global-company-mode and company-mode wilnerthomas--- via Users list for the GNU Emacs text editor
2022-08-02 11:09 ` thibaut.verron [this message]
2022-08-02 11:15   ` wilnerthomas--- via Users list for the GNU Emacs text editor
2022-08-02 11:23     ` Dmitry Gutov
2022-08-02 11:41       ` Thibaut Verron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=48e6e2a9-7cb2-1899-47f7-188c49125f1b@gmail.com \
    --to=thibaut.verron@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.