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 08:08:01 +0200 Message-ID: <871r48qpuv.fsf@gnu.org> References: <875ytkqt4x.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="28964"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.7.4; emacs 29.0.50 Cc: help-gnu-emacs@gnu.org To: Hongyi Zhao Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Oct 26 08:13:22 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 1mfFi5-0007MM-49 for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 26 Oct 2021 08:13:21 +0200 Original-Received: from localhost ([::1]:48390 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfFi3-000660-Kj for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 26 Oct 2021 02:13:19 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48072) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfFeO-0005Oj-Rp for help-gnu-emacs@gnu.org; Tue, 26 Oct 2021 02:09:32 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:42230) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfFeO-0002Zf-JS; Tue, 26 Oct 2021 02:09: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=GUyu3eKzezAZo+tstk6pPdoZXzo8NtrsOgT9gKs2pN0=; b=gNUt+2ZtzkEaHL kiDQI5dM3y+ByO22EAMfyWCaAabruKetHEJ22wE+zmRNGDzxI+CzhP4kcFZqFOfK9KPzBr6IztNKV bZYCf7ePIzX94sdXF9Lgy6FmBCZ7ndBsFohstLhXzfxc8jwseuL7zujJ6NO9HQIXz2fB5Mqmxynd6 jQYTsD0BOyp+nAYk2LCYiAHGhWaHa0/S5wyvQl9KG0jf24+lqa9KJukKsr02Cz9GNiEnziMMnPWWT t4wKnQm/N3K2ss/YBbo8A865Nj6o7Qla91W2yhEpdzTYw5b9xMjz9mxJPsPxhEnsuT6SdPhOiRSoO BhYwVWCIJMC3Fa4st5Yg==; Original-Received: from auth2-smtp.messagingengine.com ([66.111.4.228]:53751) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfFeN-0001hR-Sr; Tue, 26 Oct 2021 02:09:32 -0400 Original-Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailauth.nyi.internal (Postfix) with ESMTP id A0FEB27C0054; Tue, 26 Oct 2021 02:09:30 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Tue, 26 Oct 2021 02:09:30 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrvdefiedgleegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfhgfhffvufffjgfkgggtsehttdertddtredtnecuhfhrohhmpefvrghsshhi lhhoucfjohhrnhcuoehtshguhhesghhnuhdrohhrgheqnecuggftrfgrthhtvghrnhepve evieekteekveeigfefffeivdetgeduvdffueeuudevgedttdehvdfhueevfffhnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepthhhohhrnhdomh gvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqkeeijeefkeejkeegqdeifeehvdel kedqthhsughhpeepghhnuhdrohhrghesfhgrshhtmhgrihhlrdhfmh X-ME-Proxy: Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 26 Oct 2021 02:09: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:134181 Archived-At: Hongyi Zhao writes: >> > > How can I add/remove an element into/from a cons, taking the >> > > following one as an example: >> > > >> > > ```emacs-lisp >> > > (setq company-backends '((company-tabnine :separate company-capf >> > > company-dabbrev company-keywords company-files company-ispell))) >> > > ``` >> > > >> > > How can I remove `company-ispell` from and re-add it into the >> > > company-backends defined above? >> > >> > You can use `setf' with the place being the alist entry like this >> > (company-backends replaced with th/test in my example): >> > >> > --8<---------------cut here---------------start------------->8--- >> > (setq th/test '(( company-tabnine :separate company-capf company-dabbrev >> > company-keywords company-files company-ispell))) >> > >> > (let ((place (assoc 'company-tabnine th/test))) >> > (setf place (remove 'company-ispell place))) >> > --8<---------------cut here---------------end--------------->8--- >> >> Yes. It does the trick: >> >> `C-j' (setq th/test '((company-tabnine :separate company-capf company-dabbrev >> company-keywords company-ispell company-files))) >> >> ;; ((company-tabnine :separate company-capf company-dabbrev >> company-keywords company-ispell company-files)) >> >> >> `C-j' (setq th/test (let ((place (assoc 'company-tabnine th/test))) >> (setf place (remove 'company-ispell place)))) >> >> ;; (company-tabnine :separate company-capf company-dabbrev >> company-keywords company-files) >> >> But how to add it back to the alist? > > I mean: But how to add it back to its original position in the list? This would add it again as the last element: --8<---------------cut here---------------start------------->8--- (let ((place (assoc 'company-tabnine th/test))) (setf place (append place '(company-ispell)))) --8<---------------cut here---------------end--------------->8--- Bye, Tassilo