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: How to properly use treesit-range-rules ? Date: Mon, 18 Sep 2023 21:11:42 -0700 Message-ID: <769ACC51-F33A-425F-8638-47BFFBD5D62F@gmail.com> References: <8289988.T7Z3S40VBb@fedora> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6\)) 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="4201"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Vincenzo Pupillo Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Sep 19 06:12:48 2023 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 1qiS6S-0000t3-IU for ged-emacs-devel@m.gmane-mx.org; Tue, 19 Sep 2023 06:12:48 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qiS5h-0007FB-Ly; Tue, 19 Sep 2023 00:12:01 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qiS5f-0007El-4p for emacs-devel@gnu.org; Tue, 19 Sep 2023 00:11:59 -0400 Original-Received: from mail-oi1-x22c.google.com ([2607:f8b0:4864:20::22c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qiS5b-0006ud-VC for emacs-devel@gnu.org; Tue, 19 Sep 2023 00:11:57 -0400 Original-Received: by mail-oi1-x22c.google.com with SMTP id 5614622812f47-3ab244ef065so3776622b6e.0 for ; Mon, 18 Sep 2023 21:11:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695096714; x=1695701514; darn=gnu.org; 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=ZwXu3jZzQ7GteFn7aoguyAhBgLyaQLwUeU/issSOqYY=; b=KikMs3Pc1Hs4tlkCNW6p0iZyeYIX9ZxjXG6B5NgRo64/JHxAqb6FjytRSwUMh54ikA 0n2aQuXWW9WJCltiuCFhm8mo2NPAVJEm54rjXbknnPjNX08R+TSlpc67l53r/mR6bwf7 y0vmOpdu3sq7dtHyjTPjxQChxpMki8RagUi7cBH9X4+dckSt7SmnBjBgnQ0xHL7QtBBa 7wJn4Tg2jpwTPKf7EQYyuFp+KIEAZr4kGUTdy8x9udcsucFNsWPOhkFDvJf/mYv3s3Nj wBEoP1FvLeZeNVSxUdog+/2wG/d0RCgr090udQidpwC/2WW5pDjWFCAYa92Lfrw3PfPn XyDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695096714; x=1695701514; 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=ZwXu3jZzQ7GteFn7aoguyAhBgLyaQLwUeU/issSOqYY=; b=Lj+UZ1i3Bw326qxepICA3aj9ZN4UBRgLrYcceKnUNM+EYM6XkpbT8/NagY9wPM2hmL uZWJM6NsLM7JWTQct8YJZmAy6FOYTDP8wRPxunTbjxhkQKBouX9VVdUi+tH8QJ3Um8Mh oWelGx3FxkuWOs6gQpuR8f9qgBwo39Eirc8OqUc9CbjStMmOYce6BoN1N1utowk01qn0 Fs/zuJjkbo4jAdDXVPtB7CxCAtbA5AeEho9RPRPtW1t8gBLS7DoLUlpdMKN+d1dOf+Wu WR81iMydfgimvxe/iG68FFPvOHV9aF/PAzIcUWkseP6jWoUh+sXyiXiTy3AxI9bDIeth MWVQ== X-Gm-Message-State: AOJu0YzGPy9cldxZm5CtEhXfsIcpJBp8fU9WvWPB2GImEJOeQxNiYElP 4UPnVz8NzDixRKFQJy4ju5Q4CkIKkFg= X-Google-Smtp-Source: AGHT+IF7UIO/5mUZ2Sf+8r4zGTsDg9PkQQrKhNWgOvhUeNIFCD7TgpOujdRH1deUbZMipzg4DT8KEQ== X-Received: by 2002:aca:2104:0:b0:3a4:1c16:b1bc with SMTP id 4-20020aca2104000000b003a41c16b1bcmr12819332oiz.12.1695096714452; Mon, 18 Sep 2023 21:11:54 -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 ob6-20020a17090b390600b00263f8915aa3sm200856pjb.31.2023.09.18.21.11.53 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Sep 2023 21:11:54 -0700 (PDT) In-Reply-To: <8289988.T7Z3S40VBb@fedora> X-Mailer: Apple Mail (2.3731.700.6) Received-SPF: pass client-ip=2607:f8b0:4864:20::22c; envelope-from=casouri@gmail.com; helo=mail-oi1-x22c.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-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:310736 Archived-At: > On Sep 18, 2023, at 1:58 PM, Vincenzo Pupillo = wrote: >=20 > Hi,=20 > I'm trying to figure out how to properly use treesit-range-rules for = my > php-ts-mode (you can find it here = https://github.com/vpxyz/php-ts-mode, there=20 > are still several things to fix.). > Currently the rules I am using are as follows: > (setq-local treesit-range-settings > (treesit-range-rules > :embed 'html > :host 'php > ;;:local t > '((program (text) @cap) > (text_interpolation (text) @cap)) >=20 > :embed 'javascript > :host 'html > ;;:local t > '((script_element > (start_tag (tag_name)) > (raw_text) @cap)) >=20 > :embed 'css > :host 'html > ;;:local t > '((style_element > (start_tag (tag_name)) > (raw_text) @cap)))) >=20 > I also tried different combinations, even with the new :local flag. = However, I=20 > couldn't find a way to prevent built-in language parsers from = modifying=20 > highlighted syntax outside of the ranges captured by queries. > I used php-mode as a comparison. For example you can see how it = behaves with=20 > the two files = https://github.com/emacs-php/php-mode/blob/master/tests/8.0/ > attribute/class.php or = https://github.com/emacs-php/php-mode/blob/master/=20 > tests/issue-66-namespace.php. > It is possible to set a php-ts-mode-disable-inject variable to enable = or=20 > disable the parsers for html/css/javascript to see the differences. >=20 > What am I doing wrong? > Thank you I haven=E2=80=99t try your mode yet, but the problem you described looks = the same as another bug report I just received a few days ago [1]. If = they are indeed caused by the same issue, you are not doing anything = wrong. Instead, it=E2=80=99s due to a bug in Emacs.=20 Try defining the following workaround function, and add it as a query = rule: (defun test-php--clean-up-parser-range (&rest _) (dolist (parser (mapcan (lambda (lang) (treesit-parser-list nil lang)) '(html css javascript))) (when (null (treesit-parser-included-ranges parser)) (treesit-parser-set-included-ranges parser `((,(point-min) . ,(point-min))))))) Add it like this (make sure it=E2=80=99s the last rule): (setq-local treesit-range-settings (treesit-range-rules :embed 'html :host 'php '((text) @capture) :embed 'css :host 'html '((style_element (raw_text) @capture)) :embed 'javascript :host 'html '((script_element (raw_text) @capture)) #'test-php--clean-up-parser-range)) [1] https://github.com/casouri/expreg/issues/3 (Also, it seems that both of you got the idea of creating a php mode, = maybe it a good idea for you two to exchange a few ideas and what not.) Yuan=