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: Wed, 19 Oct 2022 17:23:10 -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> <87sfjmg69q.fsf@gnus.org> <21B2ADDF-70BC-46D4-98D6-41C5D0EF7D40@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="969"; 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 Thu Oct 20 02:24:41 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 1olJMW-000AYv-PG for ged-emacs-devel@m.gmane-mx.org; Thu, 20 Oct 2022 02:24:40 +0200 Original-Received: from localhost ([::1]:36618 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1olJMV-0002Z5-Kh for ged-emacs-devel@m.gmane-mx.org; Wed, 19 Oct 2022 20:24:39 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:32932) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1olJLA-0001j4-EV for emacs-devel@gnu.org; Wed, 19 Oct 2022 20:23:16 -0400 Original-Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]:34753) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1olJL8-00031P-H7 for emacs-devel@gnu.org; Wed, 19 Oct 2022 20:23:15 -0400 Original-Received: by mail-pl1-x636.google.com with SMTP id n7so18808621plp.1 for ; Wed, 19 Oct 2022 17:23:13 -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=a8LTb8ed22M649WDNUPzjsfQRBY1SI2hGlj+HkZ6LzU=; b=quJzowLS99GQBoJzBmhkT1uMe41rCueyl2nl56+KOn6MR7xw3/LRIZCp2WfezHoj1L RTJsSr/QIK8WrjRfW3Wpy2nhOMmzZSeA3tQAhH0UHvmIp11hzfMD9yOdbhUE7ItF+St/ dlNFqpHtxUS2rO4o8uyY1LgfZoCOOuQc5DJpfyfCCb9AvilzSCoKBhCSo7R435Iw4Xw8 S5idmAZJJY87Y3UNbCOxRRfbltFqiaIrV0XocvGvqAqXW1pKzuPpn6PMEjwr0vTxfx1b 6FC2blaK9+hvKOCuRQ5n0u86yMwdmTeHhoyWTCLS2FCQqh0Vf5dvlzeQj925dz/OthpW xAqA== 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=a8LTb8ed22M649WDNUPzjsfQRBY1SI2hGlj+HkZ6LzU=; b=AxzKXt+JveZfy0vQOi62xypEg+tVeDLq5JPyUY4UJPviPcKNU81SKKVoNO4GofNkYC UZYRyK0S97DRQkZmvwlEH2ZIQaN6trGiXxn/TK9gl9VZzXNyHGMFnQLpdSa8w1ZKL5xv nNYo7FtzXkvjLdxtBFIspTFo2lDZcYOvKfL3lL+ZJiytwqjqLJKy7tf7Dxad38gJ16w7 HvF6WIiN+5/WeQ6//8PwQMwRK+iUzcxvRLjdh6iX0A6+gaNkqdP5iGJjNl8KFihbuK8Y oYdXUrQBF4PT1bQnQyt0xKI72NV8lfXXuuyBco2D54bong63XQT5dvsSK7MGIId6M1Ct +hVw== X-Gm-Message-State: ACrzQf1A5yuZVdbH/Vt81diHZg7rrje6wVaUNtlt41vO+f868AcSCj3W Kum8WhiU/nTPuNBHrXpnpok= X-Google-Smtp-Source: AMsMyM4gIbq4ISBdBaujFhW4eT/ByAG42+y8j4UWhd582Bgs49C4ev1M23Dhq3hD1CtizWIlvX62Wg== X-Received: by 2002:a17:90b:1c87:b0:20a:e485:4e21 with SMTP id oo7-20020a17090b1c8700b0020ae4854e21mr12675478pjb.194.1666225392574; Wed, 19 Oct 2022 17:23:12 -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 z16-20020aa79f90000000b005385e2e86eesm12405085pfr.18.2022.10.19.17.23.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Oct 2022 17:23:12 -0700 (PDT) In-Reply-To: X-Mailer: Apple Mail (2.3696.120.41.1.1) Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=casouri@gmail.com; helo=mail-pl1-x636.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:298130 Archived-At: > On Oct 18, 2022, at 7:52 PM, Stefan Monnier = wrote: >=20 >>> BTW, I see that `global-treesit-mode--turn-on` is currently a (non >>> official) alias of `treesit-mode`, but I think it should only call >>> `treesit-mode` in those buffers where there is some indication that = the >>> major mode provides some treesit-mode support (e.g., currently that >>> could be if `major-mode-backend-function` is set). >>=20 >> I=E2=80=99m changing it to what you described in another email. (So >> major-mode-backend-function is goner). I can use = treesit-font-lock-settings >> as the minimum criterion. Ends up using treesit-mode-supported. >>=20 >>>=20 >>> And then maybe `treesit-mode` should signal an error (and turn = itself >>> off) if it's enabled in a buffer whose major mode does not provide = any >>> support for `treesit-mode`. >>=20 >> So currently treesit-mode signals a warning if it can=E2=80=99t = activate tree-sitter >> and (eq this-command =E2=80=99treesit-mode), but if it is called in = find-file-hook, >> etc set up by global-treesit-mode, it doesn=E2=80=99t signal a = warning. >=20 > That's why define-globalized-minor-mode has a TURN-ON function > argument separately from the MODE argument: the TURN-ON function has > to determine whether to enable the minor mode or not. It shouldn't > blindly call `treesit-mode` but first check whether `treesit-mode` > is applicable. >=20 > This way, `treesit-mode` can always signal an error when called in > a buffer where it's not applicable: it's always the responsibility of > the caller to check beforehand. Ok, I pushed the new system. Now major modes sets a range of tree-sitter = specific variables, and treesit-mode takes care of activating them. For = example, python-mode sets these: (setq-local treesit-mode-supported t) (setq-local treesit-required-languages '(python)) (setq-local treesit-font-lock-feature-list '((basic) (moderate) (elaborate))) (setq-local treesit-font-lock-settings python--treesit-settings) (setq-local treesit-imenu-function #'python-imenu-treesit-create-index) Js-mode sets these: (setq-local treesit-mode-supported t) (setq-local treesit-required-languages '(javascript)) (setq-local treesit-simple-indent-rules js--treesit-indent-rules) (setq-local treesit-defun-type-regexp (rx (or "class_declaration" "method_definition" "function_declaration" "lexical_declaration"))) (setq-local treesit-font-lock-settings js--treesit-font-lock-settings) (setq-local treesit-font-lock-feature-list '((minimal) (moderate) = (full))) treesit-mode-supported could seem a bit redundant, but no harm in being = explicit I guess? Now global-treesit-mode never signals warning, and treesit-mode always = signals warning, when treesit can=E2=80=99t activate in a buffer. Yuan=