From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Hongyi Zhao Newsgroups: gmane.emacs.help Subject: Re: Add/remove an element into/from a cons. Date: Tue, 26 Oct 2021 14:07:08 +0800 Message-ID: References: <875ytkqt4x.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28463"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs To: Tassilo Horn Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Oct 26 08:29:27 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 1mfFxe-0007BV-PC for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 26 Oct 2021 08:29:26 +0200 Original-Received: from localhost ([::1]:56846 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfFxd-000482-QF for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 26 Oct 2021 02:29:25 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47594) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfFcS-0004I8-U3 for help-gnu-emacs@gnu.org; Tue, 26 Oct 2021 02:07:32 -0400 Original-Received: from mail-ua1-x934.google.com ([2607:f8b0:4864:20::934]:46788) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mfFcI-0001vj-9b; Tue, 26 Oct 2021 02:07:31 -0400 Original-Received: by mail-ua1-x934.google.com with SMTP id x3so7711126uar.13; Mon, 25 Oct 2021 23:07:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=vHIsxkaeYgt7uFxZ+w+bqQFUa63jiaUuQ6FUU2xHy50=; b=LoYuXbmbEURnYm8Ta+8tct14MRfi7M/buby3ylSU3oe7e+g90d+OtlaFLvKT31D/cy opDXAjpTIpPf6aE+wSk3JikDP5lH7Chvq6z5H+kR81ky5KgWQMHiLnBF+oEamlBxJjiy WzVdYoRilxCf3/uIwGy+yW1eABng1MxjxSb3LymD/mBUOvU8id+Hris7Rumg+fUkoxp4 I4adeSc33CCLCT28lyPdMCjn8VvoDWV/dMWh+L5ZJJUJ2Al2UPIuf7MirDRsFmZv3j59 DTiXj3o7AlhohFa+QnKkkl+KwJh08TRzqiznZSGYlZT5MinE49q7aeY/zTcWp+xmVOIS wP9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=vHIsxkaeYgt7uFxZ+w+bqQFUa63jiaUuQ6FUU2xHy50=; b=JRorDb1aGYo1C4yP83m8pL80QRPSsWABXkkdxh8m2LJ5MlQG0O5+iz963XeiPhBuDm onrATYxZWIn4/AmzbUvTwHsXwey/1wCevqqPRpD0708ZQv8FGK3wAYNOoQJrTea9K18b iBEQ0caWbR4/9bR189TLnxULZcjHyrjwLmAivic8npySJ0YDp3z47t0ssAWQ+H6Ji6gv yQPfWmgMdcgqwRcP+Vv9eOO7w37WISk97vae8h4rYgMyOrNfseueE6PszD4f4V1bYGWB fgQjGJ04YZbl0L7Qr2P5oyFEOsbo6TZhyUvN+rZTRWeV56nAp4aGfUQcoq1tZRDxOI7L Aq8w== X-Gm-Message-State: AOAM533pHeuxjl/yqMZcVABMkxqSu+tXabgK7D/T6zG9RG6w68bf5EKn mYbFQoThQQLRbe8nq958kdZ23Mgxy3cn6F+LQs2lvOpMVa/EQ/fv X-Google-Smtp-Source: ABdhPJzOuePCVt+ZP5GcKp2bgQhZ2+rQL89gqcEFaLWRtKpA7tMRRalPvQ8p8rDi1xFUUIcidXHdkgg8jGmZBBqMrk0= X-Received: by 2002:ab0:3c94:: with SMTP id a20mr13542526uax.60.1635228439490; Mon, 25 Oct 2021 23:07:19 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::934; envelope-from=hongyi.zhao@gmail.com; helo=mail-ua1-x934.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:134182 Archived-At: On Tue, Oct 26, 2021 at 1:42 PM Hongyi Zhao wrote: > > On Tue, Oct 26, 2021 at 1:40 PM Hongyi Zhao wrote: > > > > On Tue, Oct 26, 2021 at 12:58 PM Tassilo Horn wrote: > > > > > > 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? BTW, I want to use the above trick to simplify the following function but failed: (setq company-backends '((company-tabnine :separate company-dabbrev company-keywords company-files company-ispell company-capf))) (defun my-scratch-init () (with-current-buffer "*scratch*" (setq-local company-backends '((company-tabnine :separate company-capf company-dabbrev company-keywords company-files))) )) ==> (defun my-scratch-init () (with-current-buffer "*scratch*" (setq-local company-backends (let ((place (assoc 'company-tabnine company-backends))) (setf place (remove 'company-ispell place)))) )) HZ