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: Fri, 14 Oct 2022 22:05:15 -0700 Message-ID: <6A0F847F-910D-449B-B461-466493CC9847@gmail.com> 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> 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="21164"; 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 Sat Oct 15 07:06:52 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 1ojZNs-0005J5-4e for ged-emacs-devel@m.gmane-mx.org; Sat, 15 Oct 2022 07:06:52 +0200 Original-Received: from localhost ([::1]:38846 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ojZNq-00058S-Sj for ged-emacs-devel@m.gmane-mx.org; Sat, 15 Oct 2022 01:06:50 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53210) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ojZMO-0004Lw-JQ for emacs-devel@gnu.org; Sat, 15 Oct 2022 01:05:24 -0400 Original-Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]:39445) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ojZMM-0007AF-Se for emacs-devel@gnu.org; Sat, 15 Oct 2022 01:05:20 -0400 Original-Received: by mail-pl1-x62f.google.com with SMTP id f23so6480271plr.6 for ; Fri, 14 Oct 2022 22:05: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=RuJRUb8+pkKMrrJoApXqhWzuO62OOTid8MdpvUnY2so=; b=m4mJ1oP/llIZ09t5ssgWkpP5A19AI1scMVr6Xx8tkkThp7dnTr8MFI+A2CxH23+Qwd oy11gmiFiIdcyCOeYO6t0BMoqPZPTtVOVPZ2UUN8Tf1NZ2lGSb8dAHacnGHwJvCBILx4 JjSFqiK+/MCvFMXL/wqwjY/DLDDN1Vnb1ahGzgT0KFhCyQfqQYqoQJi0N1/sWitFu9MD 13a8TMcSUU6RepkP1fw55MZUbVBq0vXV7hxX2gGei0jfq/YPa83mzcJjtFNzjEwC3DXu W3EiPP/sLW5rCkghl5LxFoytIlg6sSSLKhY8ER/Vb/CQFFfPH1cpIJf6hHMt1VMrhnkL gKYQ== 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=RuJRUb8+pkKMrrJoApXqhWzuO62OOTid8MdpvUnY2so=; b=kEWFOE//zZf0CcknFUPQBAq49TRCwefnmQEuEedQzvBwsdILovZm/lSd8YFZw0FM9K BOnl0wwMgZDSHIXUqjXD1iOxYOe9bQnJhKMk3/I8S0DKPrbCE4K3cDYv1ZseKfNZ6QBx 8ks1GU1iSNXf6pNr3zrGDLrJRX4LXZmnho7Mhn+r2EeckH8LxUB7E2XAngYKEpaY9S6o h8aNksADDsawYnQ+/Y/z469BNAUbztCJ+07QkNDXR17H6XElEtDVEeCMu5FbPDE405DN 4F7JgZD3f+Aoq1Y0pOlg+iIWStU1ENW/NlisjWUXkz7M4FPsz0yDH9aBtT0tiZBDl1Y4 r6rw== X-Gm-Message-State: ACrzQf3aHM8Pr4tbdcSJdv+D+oPI4jbZDb2DQbZskC0RjmhihEKB9KnE UkP6OoJb4yUY9J8QVlhdq8E= X-Google-Smtp-Source: AMsMyM4lj1YxoeKyhATu2mct0xEBCELK95lavDIxbAvrNTGtPHSF3IcnzcH32dt4pe02XdmnfCgP7Q== X-Received: by 2002:a17:90b:2d85:b0:20a:d20e:a5fe with SMTP id sj5-20020a17090b2d8500b0020ad20ea5femr1540970pjb.96.1665810316871; Fri, 14 Oct 2022 22:05:16 -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 y5-20020aa78f25000000b0053ae018a91esm2662817pfr.173.2022.10.14.22.05.16 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Oct 2022 22:05:16 -0700 (PDT) In-Reply-To: X-Mailer: Apple Mail (2.3696.120.41.1.1) Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=casouri@gmail.com; helo=mail-pl1-x62f.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:297749 Archived-At: > 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))) 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 >> 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, ... Do you mind elaborate on: What are the other combinations? What are the = ways a central variable can interact with major mode hooks?=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). How about a function mode-specific-value that takes any variable with = the following shape: ((MODE VALUE INHERIT)=E2=80=A6) And returns the right VALUE for the current mode? INHERIT decides = whether VALUE is inherited by MODE=E2=80=99s derived modes. Something = like: (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))) 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. Yuan=