* global-company-mode and company-mode @ 2022-08-02 10:26 wilnerthomas--- via Users list for the GNU Emacs text editor 2022-08-02 11:09 ` thibaut.verron 0 siblings, 1 reply; 5+ messages in thread From: wilnerthomas--- via Users list for the GNU Emacs text editor @ 2022-08-02 10:26 UTC (permalink / raw) To: Help Gnu Emacs 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. Why 'after-init-hook is used, cannot there just be (global-company-mode 1)? When using `add-hook', how would I disable `global-company-mode' later? ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: global-company-mode and company-mode 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 2022-08-02 11:15 ` wilnerthomas--- via Users list for the GNU Emacs text editor 0 siblings, 1 reply; 5+ messages in thread From: thibaut.verron @ 2022-08-02 11:09 UTC (permalink / raw) To: help-gnu-emacs 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 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: global-company-mode and company-mode 2022-08-02 11:09 ` thibaut.verron @ 2022-08-02 11:15 ` wilnerthomas--- via Users list for the GNU Emacs text editor 2022-08-02 11:23 ` Dmitry Gutov 0 siblings, 1 reply; 5+ messages in thread From: wilnerthomas--- via Users list for the GNU Emacs text editor @ 2022-08-02 11:15 UTC (permalink / raw) To: thibaut.verron; +Cc: help-gnu-emacs 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? ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: global-company-mode and company-mode 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 0 siblings, 1 reply; 5+ messages in thread From: Dmitry Gutov @ 2022-08-02 11:23 UTC (permalink / raw) To: wilnerthomas, thibaut.verron; +Cc: help-gnu-emacs On 02.08.2022 14:15, wilnerthomas--- via Users list for the GNU Emacs text editor wrote: > Right. Is there the command (global-company-mode -1) available? What if I want to enable global-company-mode, would I use the hook? Just 'M-x global-company-mode' in both cases. It toggles. ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: global-company-mode and company-mode 2022-08-02 11:23 ` Dmitry Gutov @ 2022-08-02 11:41 ` Thibaut Verron 0 siblings, 0 replies; 5+ messages in thread From: Thibaut Verron @ 2022-08-02 11:41 UTC (permalink / raw) To: Dmitry Gutov, wilnerthomas; +Cc: help-gnu-emacs On 02/08/2022 13:23, Dmitry Gutov wrote: > On 02.08.2022 14:15, wilnerthomas--- via Users list for the GNU Emacs > text editor wrote: >> Right. Is there the command (global-company-mode -1) available? >> What if I want to enable global-company-mode, would I use the hook? > > Just 'M-x global-company-mode' in both cases. It toggles. Or evaluate (global-company-mode 1), or customize the value of the variable global-company-mode (with M-x customize-group). Really, the after-init-hook should only run when starting emacs, so changing it will only have an effect when restarting emacs (provided that the changes are saved between sessions), or using run-hook manually (but this might have undesirable side-effects with whatever else is done in the hook). It is really not meant to make changes to the status of a running emacs. Best wishes, Thibaut ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-08-02 11:41 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 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
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).