From: Hongyi Zhao <hongyi.zhao@gmail.com>
To: Tassilo Horn <tsdh@gnu.org>
Cc: help-gnu-emacs <help-gnu-emacs@gnu.org>,
Stefan Monnier <monnier@iro.umontreal.ca>
Subject: Re: Add/remove an element into/from a cons.
Date: Thu, 28 Oct 2021 12:36:27 +0800 [thread overview]
Message-ID: <CAGP6PO+s-YHhUuBKbyGx8=k0Vw2Cvxh5pYuQfbwMy-JZWXuYgA@mail.gmail.com> (raw)
In-Reply-To: <CAGP6POK8JGYtBv14pELkAXj5SF6CREX49WFbkaRkbBbC-R8Rcg@mail.gmail.com>
On Thu, Oct 28, 2021 at 12:14 PM Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
>
> On Thu, Oct 28, 2021 at 2:52 AM Tassilo Horn <tsdh@gnu.org> wrote:
> >
> > Hongyi Zhao <hongyi.zhao@gmail.com> writes:
> >
> > >> > However, I can imagine that you might not be able to use it in
> > >> > major-mode hooks such as `emacs-lisp-mode' due to ordering issues,
> > >> > i.e., I can easily imagine that `company-mode' (and this
> > >> > company-tabnine thingy) is initialized *after* the major-mode hook
> > >> > has run because usually, you activate minor-modes in major-mode
> > >> > hooks. In that case you would try to remove before the
> > >> > company-tabnine entry has been added to company-backends.
> > >> >
> > >> > That's all just guesswork since I don't use company.
> > >>
> > >> [...]
> > >
> > > I also tried the following snippet, but still failed:
> > >
> > > (defun hz/company-tabnine-remove-company-ispell ()
> > > (make-local-variable 'company-backends)
> > > (cond
> > > (
> > > (derived-mode-p 'emacs-lisp-mode)
> > > (setf (alist-get 'company-tabnine company-backends)
> > > (remove 'company-ispell (alist-get 'company-tabnine
> > > company-backends))))
> > > (
> > > t
> > > (setf (alist-get 'company-tabnine company-backends)
> > > (append (alist-get 'company-tabnine company-backends)
> > > '(company-ispell))))))
> > >
> > > (add-hook 'emacs-startup-hook #'hz/company-tabnine-remove-company-ispell)
> >
> > The first cond clause looks good but I don't see why you need the
> > t-clause? Isn't the thing that company-ispell is part of the default
> > value of the company-tabnine entry of company-backends? If that's the
> > case, you want to make company-backends buffer-local and remove it in
> > emacs-lisp-mode and derived modes but there is no need to add it again
> > otherwise because the default value won't be altered. So that'd be:
> >
> > --8<---------------cut here---------------start------------->8---
> > (defun hz/company-tabnine-remove-company-ispell ()
> > (when (derived-mode-p 'emacs-lisp-mode)
> > (make-local-variable 'company-backends))
> > (setf (alist-get 'company-tabnine company-backends)
> > (remove 'company-ispell
> > (alist-get 'company-tabnine company-backends))))
> > --8<---------------cut here---------------end--------------->8---
>
> A very strange result based on the above code is that it will remove
> company-ispell in all modes, say, LaTeX mode. But the following code
> works as expected:
>
> (defun hz/company-tabnine-remove-company-ispell ()
> (when (derived-mode-p 'emacs-lisp-mode)
> (setq-local company-backends
> '((company-tabnine :separate company-capf company-dabbrev
> company-keywords company-files))
> )))
>
>
> > But most importantly, `emacs-startup-hook' is not the one you want.
> > That runs once after emacs has loaded the init file. I'm even not sure
> > what buffer is current then. I guess the most logical hook is
> > `company-mode-hook'.
> >
> > (add-hook 'company-mode-hook
> > #'hz/company-tabnine-remove-company-ispell)
>
> This works. Thank you for pointing this out.
The following one, which is based on the idea here [1], also works:
(add-hook 'after-change-major-mode-hook
#'hz/company-tabnine-remove-company-ispell)
[1] https://github.com/hlissner/doom-emacs/blob/0869d28483b5d81b818b110af351fd5c4dc04dd9/modules/completion/company/config.el#L66
> > Or maybe there is also some `company-tabnine-*-hook' that runs after
> > that package has done its setup in a buffer?
>
> Unfortunately, it doesn't supply these type hooks.
>
> HZ
--
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
No. 473, Quannan West Street, Xindu District, Xingtai, Hebei province
next prev parent reply other threads:[~2021-10-28 4:36 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-26 2:05 Add/remove an element into/from a cons Hongyi Zhao
2021-10-26 4:57 ` Tassilo Horn
2021-10-26 5:40 ` Hongyi Zhao
2021-10-26 5:42 ` Hongyi Zhao
2021-10-26 6:07 ` Hongyi Zhao
2021-10-26 6:18 ` Tassilo Horn
2021-10-26 6:30 ` Hongyi Zhao
2021-10-26 6:39 ` Hongyi Zhao
2021-10-26 6:08 ` Tassilo Horn
2021-10-26 6:17 ` Hongyi Zhao
2021-10-26 6:22 ` Tassilo Horn
2021-10-26 8:12 ` Hongyi Zhao
2021-10-26 8:15 ` Tassilo Horn
2021-10-26 9:26 ` Hongyi Zhao
2021-10-26 9:31 ` Hongyi Zhao
2021-10-26 18:56 ` Tassilo Horn
2021-10-27 1:39 ` Hongyi Zhao
2021-10-27 4:54 ` Hongyi Zhao
2021-10-27 5:13 ` Hongyi Zhao
2021-10-27 18:43 ` Tassilo Horn
2021-10-28 4:14 ` Hongyi Zhao
2021-10-28 4:36 ` Hongyi Zhao [this message]
2021-10-28 5:40 ` Hongyi Zhao
2021-10-26 12:36 ` Stefan Monnier
2021-10-26 13:41 ` Hongyi Zhao
2021-10-26 6:22 ` Hongyi Zhao
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAGP6PO+s-YHhUuBKbyGx8=k0Vw2Cvxh5pYuQfbwMy-JZWXuYgA@mail.gmail.com' \
--to=hongyi.zhao@gmail.com \
--cc=help-gnu-emacs@gnu.org \
--cc=monnier@iro.umontreal.ca \
--cc=tsdh@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.
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).