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: Thu, 28 Oct 2021 12:14:54 +0800 Message-ID: References: <875ytkqt4x.fsf@gnu.org> <871r48qpuv.fsf@gnu.org> <87sfwop8iu.fsf@gnu.org> <87o87cp3fs.fsf@gnu.org> <87ee87wq47.fsf@gnu.org> <8735omfggk.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="31591"; 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 Thu Oct 28 06:16:01 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 1mfwpc-0007yc-3H for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 28 Oct 2021 06:16:00 +0200 Original-Received: from localhost ([::1]:52320 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mfwpa-00080z-Rh for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 28 Oct 2021 00:15:58 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46132) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mfwoo-00080U-4a for help-gnu-emacs@gnu.org; Thu, 28 Oct 2021 00:15:10 -0400 Original-Received: from mail-ua1-x936.google.com ([2607:f8b0:4864:20::936]:38761) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mfwol-000359-CV; Thu, 28 Oct 2021 00:15:09 -0400 Original-Received: by mail-ua1-x936.google.com with SMTP id o26so9094035uab.5; Wed, 27 Oct 2021 21:15:05 -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=kyVQqr/axSnu15C9BiyzKNJS5LcONHpII+K4sHHy2qA=; b=ID/yjGw3phUc33i6F9Hv3OmlY5KORcNM87eqv6uNJkopkKzTr2laA05ycCwit8TGl/ BxnMj+0E+ZDGZ4vKLhTmnPgckJaMTS7MqVl9/8FnQcpcOoT3E/mxsTHMuaOeZTggbxXU 94unDSrs4j9D9mNjJaMpesHTVyTY7O5ZU4ZR3j4TB3T9lsKburlIchUXTBfS9fCr16v3 wZV6PUzryIo4QSm7DctVePBb6KsWtERkfJpI0EAHFNY2mEhhOuaTsKj6qZqS3ik1qmNr QNlu3hoKdthQCAjA5g3tiBDRQp8uQIu4YqJfnxBySBM+UdGRppdM1mGbrcuWafz0F1wD cVDQ== 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=kyVQqr/axSnu15C9BiyzKNJS5LcONHpII+K4sHHy2qA=; b=fH/j6NrQ4CbOD7Z1G6epyVZ4st5QP1I6brAjz+BJKqzkSyxMw3ZOQFBN0MOFsN+jDT HI6j+cBC1t9v5H+H2MSARbMy41w2iXfXTbptf/PhB9XR4ytsQvvyeJnhnsah9eaGRGaY Hp2/2P+4ub37Vg11bjx9te0UvjOYpLwaHMiqfm/DhZFj0EK8PBzNmRIAd7bso+QOf0WW MEf7ENCM32LPrP/O5T159i+c7EnxJ1X5tWVWc3OhHhseET7c3ZSXwz9EhS3umjEdl15J 1fJX/hcIxWFeHw3NseehIMnoXzdlQixs2IHYjulZ4Kq83E51s0TZ0qjJ6CVroFG/pEfp Vvpw== X-Gm-Message-State: AOAM533ysP/+J/QkhoBh5ArvdYvP53SsvouaBSwYCO6NDuOKDieAjjEh mXc+C0dTCnDDEdtdCKdaZZXYOz1dceb8dRUKMaqwJo31JmIGGjm9 X-Google-Smtp-Source: ABdhPJxwAPRwZu37mV1WDgn8DoepoEHvoIyeBqJcpQsNnHFknolnYOeUbe1Se/msyXqx9TLc6gbEgaRX1s/hqrw1XmA= X-Received: by 2002:a67:f1ca:: with SMTP id v10mr2066627vsm.55.1635394505193; Wed, 27 Oct 2021 21:15:05 -0700 (PDT) In-Reply-To: <8735omfggk.fsf@gnu.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::936; envelope-from=hongyi.zhao@gmail.com; helo=mail-ua1-x936.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:134243 Archived-At: On Thu, Oct 28, 2021 at 2:52 AM Tassilo Horn wrote: > > 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--- A very strange result based on the above code is that it will remove company-ispell in all modes, say, LaTeX mode. But the following code works as expected: (defun hz/company-tabnine-remove-company-ispell () (when (derived-mode-p 'emacs-lisp-mode) (setq-local company-backends '((company-tabnine :separate company-capf company-dabbrev company-keywords company-files)) ))) > 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) This works. Thank you for pointing this out. > Or maybe there is also some `company-tabnine-*-hook' that runs after > that package has done its setup in a buffer? Unfortunately, it doesn't supply these type hooks. HZ