From: Tassilo Horn <tsdh@gnu.org>
To: Hongyi Zhao <hongyi.zhao@gmail.com>
Cc: help-gnu-emacs@gnu.org, Stefan Monnier <monnier@iro.umontreal.ca>
Subject: Re: Add/remove an element into/from a cons.
Date: Tue, 26 Oct 2021 20:56:16 +0200 [thread overview]
Message-ID: <87ee87wq47.fsf@gnu.org> (raw)
In-Reply-To: <CAGP6PO+zu-g9=Bc9DVnsoJVWrx_S5QSSkwC-2Ed82FyLvMZdbA@mail.gmail.com>
Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>> You mean, the above function changes the value not only in *scratch*
>> but all buffers?
>
> After using the above function, it disables me to check the value of
> `company-backends' when I switch from scratch to other buffers.
What?
> The following message will be triggered when I call `C-h v
> company-backends RET':
>
> Type "q" to restore previous buffer, SPC to scroll help.
Yes, but how does that message hinder you from checking the value of
`company-backends'?
> I'm using company-tabnine package and the following company-backends
> setting:
>
> (setq company-backends '((company-tabnine :separate company-dabbrev
> company-keywords company-files company-ispell company-capf)))
>
> I want to disable the company-ispell backend when I'm in
> emacs-lisp-mode. The following function will do the trick:
>
> (defun hz/scratch-init ()
> (with-current-buffer "*scratch*"
> (setq-local company-backends
> '((company-tabnine :separate company-capf
> company-dabbrev company-keywords company-files)))
> ))
>
> (add-hook 'emacs-lisp-mode-hook #'hz/scratch-init)
Well, your function will always run when `emacs-lisp-mode' or a mode
derived from it, like `lisp-interaction-mode', the major-mode of
*scratch*, is activated. But it evaluates that code always in *scratch*
which defeats the purpose of disabling company-ispell in every buffer
having `emacs-lisp-mode' as major-mode.
> But as I've posted here, considering that I've also had a definite
> company-backends setting, so I want to remove the company-ispell from
> it programmatically.
>
> I hope this time I've clearly stated my intention.
I guess so. In certain modes, you would like to have `company-ispell'
removed from the company-tabnine entry of company-backends. Right?
In that respect, I think a function like
--8<---------------cut here---------------start------------->8---
(defun hz/company-tabnine-remove-company-ispell ()
(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---
should do the trick. 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.
Bye,
Tassilo
next prev parent reply other threads:[~2021-10-26 18:56 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 [this message]
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
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=87ee87wq47.fsf@gnu.org \
--to=tsdh@gnu.org \
--cc=help-gnu-emacs@gnu.org \
--cc=hongyi.zhao@gmail.com \
--cc=monnier@iro.umontreal.ca \
/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).