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: Wed, 27 Oct 2021 20:43:04 +0200 Message-ID: <8735omfggk.fsf@gnu.org> References: <875ytkqt4x.fsf@gnu.org> <871r48qpuv.fsf@gnu.org> <87sfwop8iu.fsf@gnu.org> <87o87cp3fs.fsf@gnu.org> <87ee87wq47.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="32961"; 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 Wed Oct 27 21:26:38 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 1mfoZK-0008P0-00 for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 27 Oct 2021 21:26:38 +0200 Original-Received: from localhost ([::1]:51226 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfoZI-0008T9-Q4 for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 27 Oct 2021 15:26:36 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60752) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfo2K-000354-WF for help-gnu-emacs@gnu.org; Wed, 27 Oct 2021 14:52:33 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:48694) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfo2K-0001ts-Jz; Wed, 27 Oct 2021 14:52:32 -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=QB/oMYg+5o2rJ2M6p4CjfxN96oj6KxuzW68BwUeaIF0=; b=ZbRErhng8ZU13P I6CssTxg2e/xSda1xESGfClrWDOFouGz0f0vhDr7y2URIGAi18eTJyt+iJmOm8V+ILRvhCNpmTGko 2zdGHSsDKTUbD5f8PxBgiVkbaZrs5/8HeohC8NX7xu9FC8rksTXQA5KbugIHoNfeRyVCu/mE1vYlz FxBdbLTiswUSnvlUPZm3oqmVsRw+2y7yD/G8wAwwsvhtpgfsqtC0nr1kzOo2BfQk6YDUEZh83mVhS Ag9lHbVjDWQ1MyQ3tHYjz9AsR/eah8KK7Q8aTyxeunt2bXFc1vOWcumOuezAmUO88PaD2gF65ztAS WvC9rjPg3WY5WY0Rlv3g==; Original-Received: from auth2-smtp.messagingengine.com ([66.111.4.228]:36111) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfo2K-0004UO-Bw; Wed, 27 Oct 2021 14:52:32 -0400 Original-Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailauth.nyi.internal (Postfix) with ESMTP id 6DAB627C0054; Wed, 27 Oct 2021 14:52:31 -0400 (EDT) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 27 Oct 2021 14:52:31 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrvdegtddguddutdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpehffgfhvffuffgjkfggtgesthdtredttdertdenucfhrhhomhepvfgrshhs ihhlohcujfhorhhnuceothhsughhsehgnhhurdhorhhgqeenucggtffrrghtthgvrhhnpe evveeikeetkeeviefgfeffiedvteeguddvffeuueduveegtddthedvhfeuveffhfenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehthhhorhhnod hmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdekieejfeekjeekgedqieefhedv leekqdhtshguhheppehgnhhurdhorhhgsehfrghsthhmrghilhdrfhhm X-ME-Proxy: Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 27 Oct 2021 14:52:29 -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:134236 Archived-At: 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 `company-mode-hook'. (add-hook 'company-mode-hook #'hz/company-tabnine-remove-company-ispell) Or maybe there is also some `company-tabnine-*-hook' that runs after that package has done its setup in a buffer? Bye, Tassilo