From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Vincenzo Pupillo Newsgroups: gmane.emacs.devel Subject: Re: How to properly use treesit-range-rules ? Date: Tue, 19 Sep 2023 15:09:53 +0200 Message-ID: <3566373.e9J7NaK4W3@3-191.divsi.unimi.it> References: <8289988.T7Z3S40VBb@fedora> <769ACC51-F33A-425F-8638-47BFFBD5D62F@gmail.com> Mime-Version: 1.0 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="11584"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Yuan Fu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Sep 19 15:47:21 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 1qib4T-0002kS-JU for ged-emacs-devel@m.gmane-mx.org; Tue, 19 Sep 2023 15:47:21 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qib3e-0002z1-Q4; Tue, 19 Sep 2023 09:46:30 -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 1qiaUJ-0000SA-3r for emacs-devel@gnu.org; Tue, 19 Sep 2023 09:09:59 -0400 Original-Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qiaUG-0000vX-Qe for emacs-devel@gnu.org; Tue, 19 Sep 2023 09:09:58 -0400 Original-Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-98377c5d53eso727046166b.0 for ; Tue, 19 Sep 2023 06:09:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695128995; x=1695733795; darn=gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=s1QyNkxXXfnDvX/M+I0wt00TjhqmoVV0McVGXjY7L68=; b=iE1se1E1VxZHHQw4V+c1jrF6gOqcDBNkt7XnVLHM/plJ0TfZ9E285C/dox56r9noUn HV9pRLr9Vs+3KtN2wwQHiy6o1v+VCE5q4l1P1pV91E3bL2urb/J7pK+jTe2LdcnJ02qh WCBb2whUr+r75+DnFG+4yeXrbGr3RVKF/R1wyjhwgDfP7kCeIDhBciCYd0XtGa4W9yfA EkB+erAWkXMArP7KspBejldtEGt+UXdJti12Nil+BDdex1fJeVe4YI7K8EGYJmT6koCs hPDSRa8OVyxIj4ZvBn/t4E44FMUv//iLaZpSwkUTd60ZFV6EiX8jaRZgB5UfErXpOShL MMhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695128995; x=1695733795; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=s1QyNkxXXfnDvX/M+I0wt00TjhqmoVV0McVGXjY7L68=; b=fiBB7mp2640L6cOcJkNDHGz0V+z9kCk8kBYTHXhY7QjLt6MIibGFgtENW1zdnxLYcU ptfDde/1Tf2vZLxohiy/s/nle379ACEuEXRqFbz/gdGhyr0/hcHUq0AKBG6qd8M4B4gv TVNJbCPxuhE1cvfxNp1xn8uta2fq/IQIqkW6E4o3Errb0K4DD2IDgk3jj70ZBQJ6GTEQ gNb4jEJZdDSV3FQzH3czbzcuGif3mv7uwGgAg1C6EM3QJutY0miILqfM2x8J3BCUbThh BJPCZxg4UmxEfabenNzp0srTwN5EmErD06on2S5rYRKV3iMItSEnpEq71PX6nQVMGKyo xDsQ== X-Gm-Message-State: AOJu0Yxbfz1KTXNZ3F4PdHjBReEZ81qhhdh5LPQFXnLhBiB3B20haDMe MghuDwozkszHUgBp+0oEAX4= X-Google-Smtp-Source: AGHT+IHutles7HwP+sE9/6u1t4Y0jH9iK/33lmoDrhcf05A8UVtnJ/Eia/uyyzucFXebLRXIztXVcw== X-Received: by 2002:a17:906:1d9:b0:9aa:165:aefc with SMTP id 25-20020a17090601d900b009aa0165aefcmr9446549ejj.33.1695128994105; Tue, 19 Sep 2023 06:09:54 -0700 (PDT) Original-Received: from 3-191.divsi.unimi.it (3-191.divsi.unimi.it. [159.149.3.191]) by smtp.gmail.com with ESMTPSA id i8-20020a170906698800b009a198078c53sm7691786ejr.214.2023.09.19.06.09.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 06:09:53 -0700 (PDT) In-Reply-To: <769ACC51-F33A-425F-8638-47BFFBD5D62F@gmail.com> Received-SPF: pass client-ip=2a00:1450:4864:20::62c; envelope-from=v.pupillo@gmail.com; helo=mail-ej1-x62c.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-Mailman-Approved-At: Tue, 19 Sep 2023 09:46:27 -0400 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:310762 Archived-At: Your workaround works very well! Currently my major mode is not published on Melpa etc.=20 I created a public repository two days ago just to make sharing easier. When it will be decent, I would be happy if it could be integrated into Ema= cs. Thank you very much. Vincenzo In data marted=C3=AC 19 settembre 2023 06:11:42 CEST, Yuan Fu ha scritto: >=20 > > On Sep 18, 2023, at 1:58 PM, Vincenzo Pupillo wro= te: > >=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. How= ever, 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= =2E0/ > > attribute/class.php or https://github.com/emacs-php/php-mode/blob/maste= r/=20 > > tests/issue-66-namespace.php. > > It is possible to set a php-ts-mode-disable-inject variable to enable o= r=20 > > disable the parsers for html/css/javascript to see the differences. > >=20 > > What am I doing wrong? > > Thank you >=20 > 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. Inst= ead, it=E2=80=99s due to a bug in Emacs.=20 >=20 > Try defining the following workaround function, and add it as a query rul= e: >=20 > (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))))))) >=20 > Add it like this (make sure it=E2=80=99s the last rule): >=20 > (setq-local treesit-range-settings > (treesit-range-rules > :embed 'html > :host 'php > '((text) @capture) >=20 > :embed 'css > :host 'html > '((style_element (raw_text) @capture)) >=20 > :embed 'javascript > :host 'html > '((script_element (raw_text) @capture)) >=20 > #'test-php--clean-up-parser-range)) >=20 > [1] https://github.com/casouri/expreg/issues/3 >=20 > (Also, it seems that both of you got the idea of creating a php mode, may= be it a good idea for you two to exchange a few ideas and what not.) >=20 > Yuan >=20