[Top][All Lists]

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

Re: Add/remove an element into/from a cons.

From: Tassilo Horn
Subject: Re: Add/remove an element into/from a cons.
Date: Wed, 27 Oct 2021 20:43:04 +0200
User-agent: mu4e 1.7.4; emacs 29.0.50

Hongyi Zhao <> 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---

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

  (add-hook 'company-mode-hook

Or maybe there is also some `company-tabnine-*-hook' that runs after
that package has done its setup in a buffer?


reply via email to

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