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: Tree-sitter, using treesit-range-rules for embedded languages Date: Tue, 22 Nov 2022 12:39:54 -0800 Message-ID: References: <87o7syaon6.fsf@gmail.com> <158606F8-9A2E-4630-A441-2BEAA07EB137@gmail.com> <93179658.VN8fuaoyE4@melissa.local> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_63083CAA-43CA-450A-98A0-93DBB7D01AD3" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32973"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Wilhelm Hugo Kirschbaum Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Nov 22 21:40:48 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 1oxa4U-0008L3-IM for ged-emacs-devel@m.gmane-mx.org; Tue, 22 Nov 2022 21:40:46 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oxa3r-00018y-4B; Tue, 22 Nov 2022 15:40:07 -0500 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 1oxa3o-00018f-7J for emacs-devel@gnu.org; Tue, 22 Nov 2022 15:40:04 -0500 Original-Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oxa3j-0003GA-86 for emacs-devel@gnu.org; Tue, 22 Nov 2022 15:40:01 -0500 Original-Received: by mail-pg1-x534.google.com with SMTP id s196so15069106pgs.3 for ; Tue, 22 Nov 2022 12:39:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=1TKBVpTQppkznrd3HTB4oCSwDtlDLhB/E5kDia6foFk=; b=dxbvjXb1vBKikiXf9lkugPQdRuXy4qIieFDjK7O5oaBIlrflWPeCC1c7PwfCmslCkv Ky6IO0EIRyHGNAiEHXOtOGZjOCt2R5cTEQpBNoL+A0J4sHZltcSLP+mUg4KQNA6MrGh3 KnkrY3kA9NNH5qgC8HdFlh/E5jv6VDMv6fkSMiZfjqxBWpceQneBIs9Ln0bAWpBT6/ru wL85+vREBcRUkekkV2D7vs4opXJr+NfBP7HU+Ue7BkDWSh/RcgoDYHQu5sqRsFuVwmNn SGDO/3E7xiqcng4I8Xes/58ZTdP4Y2tgGSeKK1l9uNPktBbwYSSbKvak2gUdLJ+pMRkh 3GSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1TKBVpTQppkznrd3HTB4oCSwDtlDLhB/E5kDia6foFk=; b=RLx+17BTynpktRTwqKrsgzvSYBUpoozeNdgAscAhrloDdx/I/LHyY5MgephLJtEwV8 npPSbEvM4nbaNfrV19ODlbthOVeVsw8N3NjJi3Q7qGZuU5geh2uBhn/IOOqHE20K/jK0 5Ufh/+p9U04B9b3nVTylaLrMBSa2la8LBS+HSHenlUsFylJNdaxusPX+IdeteaM2MSIO 1gEMBAu66NhGSxkc5np3q7rAZawLmT2lHdeYwF+TLmDHAHi4qK3+WmtN8XHFWdpX4Ynd JdihcVdk99A2lykM+e6OWpsHonfyPvEQxMUyO118GIViuFoUA23Dql8SHQahfMouWSRr Xlgw== X-Gm-Message-State: ANoB5plVH3F8E1K/gHIlh0vbPct04YSheBDTJ2SqT+Z7OlJE+IwgUCRV x411RabgJw+DLIedg+W2R3BuAKlOC1pMFg== X-Google-Smtp-Source: AA0mqf5lmVWinmb2eTDvTrBNXGETCA09EJAN4AdMgeyZrinuVk5SeZILUnwCQaTxDSqiCzRCp5jMlQ== X-Received: by 2002:a63:2443:0:b0:43c:e6cd:a9e4 with SMTP id k64-20020a632443000000b0043ce6cda9e4mr23112708pgk.546.1669149596358; Tue, 22 Nov 2022 12:39:56 -0800 (PST) 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 i6-20020a626d06000000b00572275e68f8sm11008371pfc.166.2022.11.22.12.39.55 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Nov 2022 12:39:56 -0800 (PST) In-Reply-To: <93179658.VN8fuaoyE4@melissa.local> X-Mailer: Apple Mail (2.3696.120.41.1.1) Received-SPF: pass client-ip=2607:f8b0:4864:20::534; envelope-from=casouri@gmail.com; helo=mail-pg1-x534.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:300351 Archived-At: --Apple-Mail=_63083CAA-43CA-450A-98A0-93DBB7D01AD3 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Nov 22, 2022, at 11:52 AM, Wilhelm Hugo Kirschbaum = wrote: >=20 > On Tuesday, 22 November 2022 21:28:48 SAST Yuan Fu wrote: >>> On Nov 22, 2022, at 9:24 AM, Wilhelm wrote: >>>=20 >>> Is there perhaps an example using treesit-range-rules? To following >>> attempt to set treesit-range-settings does not seem to have the = desired >>> effect. >>>=20 >>> (defvar heex--treesit-range-rules >>>=20 >>> (treesit-range-rules >>>=20 >>> :embed 'elixir >>> :host 'heex >>>=20 >>> '((directive (partial_expression_value) @cap) >>>=20 >>> (directive (expression_value) @cap) >>> (expression (expression_value) @cap)))) >>>=20 >>> (setq-local treesit-range-settings heex--treesit-range-rules) >>>=20 >>> The following error also pops up when modifying the buffer when = removing >>> buffer content: >>>=20 >>> Error during redisplay: (jit-lock-function 1) signaled >>> (treesit-range-invalid "RANGE is either overlapping, out-of-order or >>> out-of-range" ((11 . 20))) >>>=20 >>> The full attempt is here: >>> https://github.com/wkirschbaum/elixir-mode/blob/main/heex-mode.el >> Thanks Wilhelm. It would be nice if you can provide some example = source file >> of heex for me to experiment with. I tried to find some on the = internet but >> didn=E2=80=99t get very far :-) >>=20 >> Yuan >=20 > Thanks for having a look as I was not sure if this was meant to be = used yet.=20 >=20 > A heex file can be as simple as this:=20 >=20 > #sample.html.heex >
> <%=3D Enum.map([1, 2], &(&1 + 1)) %> >
>=20 > and the directive <%=3D (partial_expression_value) %> should then be = elixir.,=20 > not heex. >=20 > When checking with (treesit-language-at (point)) for the embed it = still show. >=20 > Wilhelm Cool. Please see if this works. Admittedly the process is a little = =E2=80=9Craw=E2=80=9D. That=E2=80=99s mainly due to me not wanting to = commit to a framework before we have a lot of real-world experience with = multi-language major modes. Please let me know if you think how could = this be improved. For starters, maybe someways to =E2=80=9Cinherit=E2=80=9D= font-lock rules with treesit-font-lock-rules? Maybe the feature-list = should have independent configuration for each language, so we don=E2=80=99= t have feature-namespace conflicts? (Right now we rename all elixir = features to elixir-.) I=E2=80=99ve also fixed the warning you see (which is due to treesit.el, = not your code), so you=E2=80=99ll need to pull master. Thanks! Yuan --Apple-Mail=_63083CAA-43CA-450A-98A0-93DBB7D01AD3 Content-Disposition: attachment; filename=heex.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="heex.patch" Content-Transfer-Encoding: quoted-printable =46rom=2089eaff15030bf627b39a4e98801103ab622cfac6=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20Yuan=20Fu=20=0ADate:=20Tue,=20= 22=20Nov=202022=2012:24:31=20-0800=0ASubject:=20[PATCH]=20Enable=20= elixir=20font-lock=20rules=20in=20heex-mode=0A=0A---=0A=20heex-mode.el=20= |=2032=20+++++++++++++++++++++++++++-----=0A=201=20file=20changed,=2027=20= insertions(+),=205=20deletions(-)=0A=0Adiff=20--git=20a/heex-mode.el=20= b/heex-mode.el=0Aindex=20a32b9ee..7425ed8=20100644=0A---=20= a/heex-mode.el=0A+++=20b/heex-mode.el=0A@@=20-18,6=20+18,7=20@@=0A=20=0A=20= ;;=20Code:=0A=20=0A+(require=20'elixir-mode)=0A=20(require=20'treesit)=0A= =20=0A=20(eval-when-compile=0A@@=20-257,11=20+258,32=20@@=0A=20=0A=20=20=20= (cond=0A=20=20=20=20((treesit-ready-p=20'heex)=0A-=20=20=20=20(progn=20= (if=20(treesit-ready-p=20'elixir)=0A-=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20;;=20(setq-local=20treesit-range-settings=0A-=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20;;=20=20=20=20=20=20=20=20=20=20=20=20=20= heex--treesit-range-rules)=0A-=20=20=20=20=20=20=20=20=20=20=20=20=20)=0A= -=20=20=20=20=20=20=20=20=20=20=20(treesit-major-mode-setup)))=0A+=20=20=20= =20(when=20(treesit-ready-p=20'elixir)=0A+=20=20=20=20=20=20(setq-local=20= treesit-range-settings=20heex--treesit-range-rules)=0A+=20=20=20=20=20=20= (setq-local=20treesit-font-lock-settings=0A+=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20(append=20heex--treesit-font-lock-settings=0A+=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= ;;=20Add=20elixir=20font-lock=20rules,=20rename=20each=0A+=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20;;=20= rules=E2=80=99=20feature=20name=20to=20be=0A+=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20;;=20elixir-.=0A= +=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20(mapcar=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20(lambda=20(rule)=0A+=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(list=20(nth=20= 0=20rule)=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(nth=201=20rule)=0A+=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20(intern=20(format=20"elixir-%s"=0A+=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20(nth=202=20= rule)))=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20(nth=203=20rule)))=0A+=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= elixir--treesit-font-lock-settings)))=0A+=20=20=20=20=20=20;;=20Add=20= elixir=20features=20to=20the=20feature=20list.=0A+=20=20=20=20=20=20= (setq-local=20treesit-font-lock-feature-list=0A+=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20'((=20doctype=20comment=20elixir-comment=20= elixir-string=20)=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20(=20bracket=20tag=20attribute=20keyword=20string=0A+=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20elixir-keyword=20= elixir-unary-operator=20elixir-operator=0A+=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20elixir-doc)=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20(=20component=0A+=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20elixir-call=20= elixir-constant)=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20(=20elixir-sigil=20elixir-string-escape)=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20(=20elixir-string-interpolation))))=0A= +=20=20=20=20(treesit-major-mode-setup))=0A=20=0A=20=20=20=20(t=0A=20=20=20= =20=20(message=20"Tree-sitter=20for=20Heex=20isn't=20available")))=0A--=20= =0A2.33.1=0A=0A= --Apple-Mail=_63083CAA-43CA-450A-98A0-93DBB7D01AD3 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii --Apple-Mail=_63083CAA-43CA-450A-98A0-93DBB7D01AD3--