From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.help Subject: Re: Add/remove an element into/from a cons. Date: Tue, 26 Oct 2021 20:56:16 +0200 Message-ID: <87ee87wq47.fsf@gnu.org> References: <875ytkqt4x.fsf@gnu.org> <871r48qpuv.fsf@gnu.org> <87sfwop8iu.fsf@gnu.org> <87o87cp3fs.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18225"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.7.4; emacs 29.0.50 Cc: help-gnu-emacs@gnu.org, Stefan Monnier To: Hongyi Zhao Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Oct 26 21:20:28 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mfRzn-0004Wl-MU for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 26 Oct 2021 21:20:27 +0200 Original-Received: from localhost ([::1]:54628 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfRzh-0001XV-A4 for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 26 Oct 2021 15:20:22 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40242) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfRz4-0001Wa-38 for help-gnu-emacs@gnu.org; Tue, 26 Oct 2021 15:19:42 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:38496) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfRz3-0002tW-P2; Tue, 26 Oct 2021 15:19:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:In-reply-to:Date:Subject:To:From: References; bh=Ev28M5PvZq78enQ+2uQOIB6gPk9e2z5uRRB8hWaBwZE=; b=jpIP0zBKNfgXTx OvXr+m0tJ4u9kO5Qycwl00cveI975dBp0PUz0FgGRe4pWfy0H0i/F8Qhu8rx3FR/178R2HZG78Prx 0vN5F7cGbNhpY+pBIJMwB3dBa0T6l2alm2uvE8l/BLBNzmnb+864LoZNZepsOq+uZVQm9IkhBITeq a6MDgLAk9vPlmjg6HnVb3BjLJhU+zspQCQhyh97TMwgJmZF9Q6Wjq0Jl/5pYE/VLwordZrL+xdiPs cH8ucFf6i9eB7BaZmtZ4uTJqwR3j7Y0KwHXDqefmjGL0tVfMIRHC4zvhflz4r7FzZ7y7iMGjHWwUJ TLHFJD5deWuhBS5TfuiQ==; Original-Received: from auth2-smtp.messagingengine.com ([66.111.4.228]:48283) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfRz3-0002gR-HK; Tue, 26 Oct 2021 15:19:41 -0400 Original-Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailauth.nyi.internal (Postfix) with ESMTP id 3AA3127C0061; Tue, 26 Oct 2021 15:19:40 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Tue, 26 Oct 2021 15:19:40 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrvdefkedgheefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfhgfhffvufffjgfkgggtsehttdertddtredtnecuhfhrohhmpefvrghsshhi lhhoucfjohhrnhcuoehtshguhhesghhnuhdrohhrgheqnecuggftrfgrthhtvghrnhepve evieekteekveeigfefffeivdetgeduvdffueeuudevgedttdehvdfhueevfffhnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepthhhohhrnhdomh gvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqkeeijeefkeejkeegqdeifeehvdel kedqthhsughhpeepghhnuhdrohhrghesfhgrshhtmhgrihhlrdhfmh X-ME-Proxy: Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 26 Oct 2021 15:19:38 -0400 (EDT) In-reply-to: X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:134218 Archived-At: Hongyi Zhao 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