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: Wed, 27 Oct 2021 12:54:30 +0800 Message-ID: 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; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17689"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs , Stefan Monnier To: Tassilo Horn Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Oct 27 06:57:18 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 1mfb01-0004Pg-GC for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 27 Oct 2021 06:57:17 +0200 Original-Received: from localhost ([::1]:41248 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfb00-0004st-F8 for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 27 Oct 2021 00:57:16 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52988) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfaxa-0003UW-Su for help-gnu-emacs@gnu.org; Wed, 27 Oct 2021 00:54:46 -0400 Original-Received: from mail-ua1-x932.google.com ([2607:f8b0:4864:20::932]:44590) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mfaxY-00044K-2v; Wed, 27 Oct 2021 00:54:46 -0400 Original-Received: by mail-ua1-x932.google.com with SMTP id e5so2588832uam.11; Tue, 26 Oct 2021 21:54:43 -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=wh0cAhAFIkzqX+DrLyCOXVfPUcCQWp+D/H474KBnf4I=; b=jtjsGXNl6h4tuYIlHMu3pFavBwNo8y5JeDAJ1qLZw8PNZsXH34z+tEa4yLT/EBCFHl fIxUUM/qzkRqJ4LzmleAnxSucey8JN3vqKobbFLsPJdQt6koytTlv4IvXkNNjqUFD5lg /yWFLwm/Ilp6RahmNxVSgoG703Pj8eTAjQFbxD+2OtFsCf0u/oow4CK59JsHtHv1k/hu ZpijXO1e6/2gVyLXG2KOCTC27hwS5HiIBB6v53eIzD3VsxiHEXC6vJUwpO66PwnMS8HI JWzdI8/GfBPNFrXFu0ryg/Y5trn665KGChzV2VG+HW+GhuA3ESL3kgspk7JfSjwhajEc CVRQ== 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=wh0cAhAFIkzqX+DrLyCOXVfPUcCQWp+D/H474KBnf4I=; b=rDBp4yd7OLEtn8M2wfqm630w+L/62lFaY/okwMLBVuVfnHDFiEM3B/8Gc4HVdYQphd MLugSQ4yMUkj7NuFE588QKPfyA8/aQPXve5Lw+cAF+LLwWQTN3YJ+9OrGTqFNMze0X5f BwOJlvqrjgT29g0uBROFL/965NSNaLVSobaVPrR8ooTZRyS2SJoxGyp0S/yqjByEoz1V wwkX2xeqPWXDsMBzP7tjFdrXXx7YE5od7IgVS9szn9s2CIJ5EOC/ssTIRpETlx0VHH/x EsIi5ihvw3Fs1Fw6u/pZyqI1dLvx5AtxsU6Nk3xy8uelSGfEVNtNCFczyu2yQfbW8Mej hUeA== X-Gm-Message-State: AOAM531B/fA3nLkVZerkiGqZIUXW8A4UOKIuWMhg9PPShDHGmWD6/ia2 ywlntTDJpEnrpxtRHWXHd095V0/CSlwiW6UlZxmrtJgVNnxpxWru X-Google-Smtp-Source: ABdhPJx/ztN7LwLc0R8PoFE/Usveur4NzecAWxUVTwuMXed3WJHwty9v7++Kv0tPelfQrlZfxfFO1hDtR7sABmq+5vI= X-Received: by 2002:a05:6102:3a4c:: with SMTP id c12mr13919960vsu.10.1635310482011; Tue, 26 Oct 2021 21:54:42 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::932; envelope-from=hongyi.zhao@gmail.com; helo=mail-ua1-x932.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:134227 Archived-At: On Wed, Oct 27, 2021 at 9:39 AM Hongyi Zhao wrote: > > On Wed, Oct 27, 2021 at 3:19 AM Tassilo Horn wrote: > > > > 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 can't reproduce this now. > > > > 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. > > I have changed the original function to the following form: > > ```emacs-lisp > (defun hz/company-tabnine-remove-company-ispell () > (setq-local company-backends > '((company-tabnine :separate company-capf company-dabbrev > company-keywords company-files)))) > ``` > > Based on my tries, your above suggest code will set and append the > following value to the current buffer's company-backends: > > (company-tabnine :separate company-capf company-dabbrev > company-keywords company-files) 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) HZ