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:17:13 +0800 Message-ID: References: <875ytkqt4x.fsf@gnu.org> <871r48qpuv.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="13668"; 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:34:55 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 1mfG2w-0003IS-Or for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 26 Oct 2021 08:34:54 +0200 Original-Received: from localhost ([::1]:59604 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfG2u-0006D0-Tu for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 26 Oct 2021 02:34:52 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49218) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfFm5-0000K4-Ju for help-gnu-emacs@gnu.org; Tue, 26 Oct 2021 02:17:29 -0400 Original-Received: from mail-ua1-x92f.google.com ([2607:f8b0:4864:20::92f]:44598) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mfFm3-0003Wi-HW; Tue, 26 Oct 2021 02:17:29 -0400 Original-Received: by mail-ua1-x92f.google.com with SMTP id e5so19913639uam.11; Mon, 25 Oct 2021 23:17:25 -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=J7OoNk4jSlS8/nkB+vn0qSHm7kF3NN9vDUIJC5oLUX0=; b=n7fxWF7gX9IJEhOegmKL+225IN5Lf5I8c7pE3pnjiLjsL4fFleDmNsNTH6aYz+4XFt aMZgym5+F/EPBQ84M8alnxRidUITmouM6gepj9SdpgcSuip/FL/QjI/4nyedYA6uQXWE uxmabp6pYhFmjrKcuGljptI06uGSBmqe+yoGJmcS+Q0gVKMLLuHrBPlvT7sFMUiY4k+b dVawWMHx4d5WLDkCi8qFIg/H+7qseFfZksU0oPBo7pk0+z2bJngDIrQzrTrKpV65MRfB T2iWKMNFTC/xdCeeixW09baBeEE3VqEdi3RXnPpMxBZerg2kq8bmOekg5uDsCwUFcvvh KGFA== 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=J7OoNk4jSlS8/nkB+vn0qSHm7kF3NN9vDUIJC5oLUX0=; b=NIyChdvWLkoavt/N9HqS+KcTTxc43HfdH0YbGl4LiwLrXMOYhhMthEYrOjw5YQfuIQ Pcu41y5qntLPt17Vlg+zWD2FlVsPjq6TZNjm8nRyqvt5JkTuIqsZrwLSgjYbAIk6jO/A N6/ThCuy55BxjSNTbhNV9effpfkrkyr/cvOCayU2QzW4e853uGzup83D+H2RHpRw/y+B +F0OY9TasrdVfRPK/mxtq5CgeBJntyPwr6YUkM0mZX9XRzqga1ZXjqZzJ4v2q1J3G2+1 3bZdPKegjukNMaqCEgQiXmFY1NO95iTiI86q2xRBm7lhLxjc2lvu/ZOOCzSMovbebc30 cajA== X-Gm-Message-State: AOAM533caoR4aYeP/Y8aYAuhBIaVICXOHn5Qrio+10P+dESI1gyxxsoc ei1SAaDqNOr9+fQH/YpplLPU0ZfpDHnNojpGDi4yyi+s2HT5H3wE X-Google-Smtp-Source: ABdhPJzLtRiALI51MCo62MbWQYPkYs+PN8DNlGU3Amzbo7HQLBnrfxngR4+H0g2ELN4ZKrYEsRV7abiv8I7YoShfQM0= X-Received: by 2002:a67:a60c:: with SMTP id p12mr21196541vse.25.1635229044849; Mon, 25 Oct 2021 23:17:24 -0700 (PDT) In-Reply-To: <871r48qpuv.fsf@gnu.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::92f; envelope-from=hongyi.zhao@gmail.com; helo=mail-ua1-x92f.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:134183 Archived-At: On Tue, Oct 26, 2021 at 2:09 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? > > 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--- Thanks. But the push doesn't work: (let ((place (assoc 'company-tabnine th/test))) (setf place (push place '(company-ispell)))) Debugger entered--Lisp error: (wrong-number-of-arguments (lambda (command &optional arg &rest ignored) "`company-mode' completion backend using Ispell." (interactive (list 'interactive)) (cond ((eql command 'interactive) (company-begin-backend 'company-ispell)) ((eql command 'prefix) (if (company-ispell-available) (progn (company-grab-word)))) ((eql command 'candidates) (let ((words (company-ispell--lookup-words arg ...)) (completion-ignore-case t)) (if (string= arg "") words (all-completions arg words)))) ((eql command 'kind) 'text) ((eql command 'sorted) t) ((eql command 'ignore-case) 'keep-prefix))) 0) company-ispell() (let* ((v (company-ispell))) (\(setf\ quote\) (cons place 'v) v)) (setq place (let* ((v (company-ispell))) (\(setf\ quote\) (cons place 'v) v))) (let ((place (assoc 'company-tabnine th/test))) (setq place (let* ((v (company-ispell))) (\(setf\ quote\) (cons place 'v) v)))) (progn (let ((place (assoc 'company-tabnine th/test))) (setq place (let* ((v (company-ispell))) (\(setf\ quote\) (cons place 'v) v))))) elisp--eval-last-sexp(nil) eval-last-sexp(nil) funcall-interactively(eval-last-sexp nil) command-execute(eval-last-sexp) HZ