From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.devel Subject: Re: Average-user-facing interface for tree-sitter Date: Mon, 17 Oct 2022 02:07:15 -0700 Message-ID: References: <3A7E7CD1-74A7-4352-9DFE-FC982EAA398E@gmail.com> <87ilko9r9e.fsf@gnus.org> <9794E2EF-4DB5-4A04-90F0-3EB51E6BE008@gmail.com> <87977C2D-844B-4F4E-BEA4-8BCBFC8AE354@gmail.com> <6A0F847F-910D-449B-B461-466493CC9847@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6243"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Lars Ingebrigtsen , emacs-devel To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Oct 17 11:12:16 2022 Return-path: Envelope-to: ged-emacs-devel@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 1okMAQ-0001HV-Gz for ged-emacs-devel@m.gmane-mx.org; Mon, 17 Oct 2022 11:12:14 +0200 Original-Received: from localhost ([::1]:60130 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1okMAN-00021d-R2 for ged-emacs-devel@m.gmane-mx.org; Mon, 17 Oct 2022 05:12:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54742) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okM5m-00069F-VA for emacs-devel@gnu.org; Mon, 17 Oct 2022 05:07:30 -0400 Original-Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]:53011) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1okM5e-0008M1-Oj for emacs-devel@gnu.org; Mon, 17 Oct 2022 05:07:25 -0400 Original-Received: by mail-pj1-x102f.google.com with SMTP id pq16so10423295pjb.2 for ; Mon, 17 Oct 2022 02:07:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=NyblMM83u7oEfd2CVWjFt7va9wEvZc6cNXTyATOdVGI=; b=c74zVS3R9Z4SyJvj8MAFFHWxhIy9Lur2apI6q4lCmaQnCpZNgnXkVcRVpmh6wyLQo8 EvzEiStBHl4ZbeK4lJPNdDr+XuxcRMqYpucWtbD6saPBB1sdezA1wjEApaXci2gu1Er8 NB3+WtlGfrOEe7bnTMy0OR093Ba0GCmr7SlOtRs9baK9i/mlO7p1iRfaYwZla8QBMd/m AYzLagn+Y4m8E9Wb6Oo+u78NS2D5IpkRd7DCgqJSsBsibvPsPhAOfe7AYi3xh91S3zuX V358t98mrTXN6z6YpCKWF7nJvnIKJOOEivl2ci2b8rxMg9LPn7zykPk/VgX096VTiWyk eJBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NyblMM83u7oEfd2CVWjFt7va9wEvZc6cNXTyATOdVGI=; b=JvpjSmXjxAbmPMBW6LmoH6ehWbRiBqaioj0ayydobRh8y5w1QK7R7J04EB43PakOEJ iWU3Wwo8mRCfGhzpaNSv9vItRMGgHVFN1FduuDBBKrjO29jbqOIcCMYYqwbBnqbsmUMY rWkl1PU9VH6sevdbdFYEHVud+nH1Aid1m+pG9knEcB1LEjkupdy00CwTFL0XbEnNs57B 67/vmcolOItvQuLN9h6CDe6Lnp8iFq4gVVY2U4ZbnHhdTjEzBEUcDoMLr+mgqgyuZZ0d /NGdfLsK/ScrzK3aigsnw8Kh15hvJZbvGm1M9NeiEIszqVwsTQ8F0QrhFWwutVlbRPDe LNwA== X-Gm-Message-State: ACrzQf3wyRSY0WQk5yPVByShGiF+MgevQnoU8Wigwn/k7hHL9R35jtuy 9Mw6INAippwImq0c83adBArv+35ZQBM= X-Google-Smtp-Source: AMsMyM59ux7Kp54SAexQBMpOnkzg4Tzi2CLvbKQ54pnMWJoQVyG76Uw5WI4C+pevDCuYxJhu2+mk6w== X-Received: by 2002:a17:90b:1e0d:b0:20d:7a3b:df5b with SMTP id pg13-20020a17090b1e0d00b0020d7a3bdf5bmr12403399pjb.189.1665997637166; Mon, 17 Oct 2022 02:07:17 -0700 (PDT) Original-Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id y126-20020a626484000000b0056232682a7esm6531261pfb.2.2022.10.17.02.07.15 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Oct 2022 02:07:16 -0700 (PDT) In-Reply-To: <6A0F847F-910D-449B-B461-466493CC9847@gmail.com> X-Mailer: Apple Mail (2.3696.120.41.1.1) Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=casouri@gmail.com; helo=mail-pj1-x102f.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: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:297939 Archived-At: > On Oct 14, 2022, at 10:05 PM, Yuan Fu wrote: >=20 >=20 >=20 >> On Oct 14, 2022, at 8:26 PM, Stefan Monnier = wrote: >>=20 >>> (add-hook 'xxx-mode-hook >>> (lambda () (when (eq major-mode 'xxx-mode) >>> (treesit-mode)))) >>>=20 >>> Which again is a bit awkward. >>=20 >> Awkward but possible. Another approach can be: >>=20 >> (add-hook 'xxx-mode-hook #'treesit-mode) >> (add-hook 'yyy-mode-hook (lambda () (treesit-mode -1))) >=20 > With the central variable approach, you can do (push =E2=80=98(xxx-mode = t nil) treesit-settings), where t means enable, nil means don=E2=80=99t = inherit. >=20 >>=20 >>> So maybe a central variable isn=E2=80=99t that bad an idea. Could = you layout >>> why mapping modes to some information is bad? >>=20 >> Because it needs to be able to say "for this mode and all its derived >> modes" but also "for this mode only" as well as various combinations, >> and then you need to document how it interacts with the major mode's >> hook, ... >=20 > Do you mind elaborate on: What are the other combinations? What are = the ways a central variable can interact with major mode hooks?=20 >=20 >> Maybe we should devise a way to "centrally" control the value of some >> vars depending on major modes, but if so we should carefully design >> a thing specifically for that, make sure it's sufficiently flexible, = and >> then use it for several (any?) variable. >>=20 >> All the vars I've seen so far which do that do it quite naively, = which >> works OK for simple cases but breaks down one way or another when you >> start taking derived modes into account. Hence my considering it a = code >> smell (just like most uses of the `major-mode` variable). >=20 > How about a function mode-specific-value that takes any variable with = the following shape: >=20 > ((MODE VALUE INHERIT)=E2=80=A6) >=20 > And returns the right VALUE for the current mode? INHERIT decides = whether VALUE is inherited by MODE=E2=80=99s derived modes. Something = like: >=20 > (defun mode-specific-value (central-var) > (cl-loop for setting in central-var > for mode =3D (nth 0 setting) > for value =3D (nth 1 setting) > for inherit =3D (nth 2 setting) > if (and (derived-mode-p mode) inherit) > return value > finally return > (if-let ((default (alist-get t central-var))) ; t sets the = default value for all mode. > (car default) > nil))) >=20 > This function would handle derived mode ok, but I don=E2=80=99t know = what are the other problems you are think of, maybe you can tell me what = this function falls short for. And we can go from there. If no one has opinions on this, I=E2=80=99m going to implement the = central-variable approach, since IMO that one is most fit. Yuan=