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: Foo.html.erb -- major mode Date: Tue, 13 Dec 2022 23:48:26 -0800 Message-ID: <4AB94890-7028-49CE-9069-2AE274F9CFDA@gmail.com> References: <479CD2BE-EFB5-426C-9C60-D22DBB75745D@easesoftware.com> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_CBCD08CF-724A-452F-9CC0-C786CF9FF818" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6081"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel To: Perry Smith Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Dec 14 08:51:26 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 1p5MY0-0001RW-Lp for ged-emacs-devel@m.gmane-mx.org; Wed, 14 Dec 2022 08:51:24 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p5MVE-0004Cx-PP; Wed, 14 Dec 2022 02:48:32 -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 1p5MVD-0004BZ-Aj for emacs-devel@gnu.org; Wed, 14 Dec 2022 02:48:31 -0500 Original-Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p5MVB-0003oO-Ox for emacs-devel@gnu.org; Wed, 14 Dec 2022 02:48:31 -0500 Original-Received: by mail-pf1-x42b.google.com with SMTP id 21so3883105pfw.4 for ; Tue, 13 Dec 2022 23:48:29 -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=jbCdTwIvfTNWDqJ5XYaumXVxk5GaKd5/08ak2VwCSV4=; b=BoGP5LP8SeIYNM2JvngJEvy4xzr1oipgJ73mcqpkT9yB3nmopiILP8/8d0alvo/xCN oowNaFCG6M7FQYtW1SAhwoGp43ZFm3bkFSj/2xASyE8cXOXWz35uWvVXyb7kmnbj2ldS gb9KLyVCi/KZXXRxSOKwB+PPHI0IHbn2dWFt5oe1OELTaFVI1wvxYRkxkf2G5EGsfnxq VSOi3J2mpW4nqiluxFNsNOx26n2aCm11F3d38eUBJGSxme3dxnH4oep0HElbU+ToM04e iamBHNrObZ+Q7RWK1uktK8v32MobrXEo+sHcRF7NH57W2IvR0HRi8cH18R8wN6HpctzC wunQ== 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=jbCdTwIvfTNWDqJ5XYaumXVxk5GaKd5/08ak2VwCSV4=; b=UFOfPb6VD2YOtpiXqDL7FrWzImK3zgBzFZqNpb4xYalwj73wF8Sjpt3hWAbnKHMjQS rKH44WcivUnzteVvfLH1NqNmhaLvm4z80XWeNZGNbh6KRrQF8ky6bauY8nktpTQUG62L EmvZrbqv9OidUkRTwnxhLl4GPoHkVBg7Y7cBJGndTt3po7RXQzFhnnTbspyFX9ItaMci bGdmlDjNAx/5GAbq73KNBdUURFI2IwXC7LgfMKLsIgQ87bsDRoDpH8wU/MVUSHWfuJZe qe8HhdhHVTj/xIdmNerNR4tCuRQ7elSmj0TFiO39Mz3FChcttQ2MlfJ95NaftNdR7ToC /y+Q== X-Gm-Message-State: ANoB5pnVrRfv2vmSFf2GnpdyjEaj2lfB4cnc2aNYfqv5ODjPnhwMsIV+ FtjF7oQaw90ieOGemuM1uHFajIVsAq2ySA== X-Google-Smtp-Source: AA0mqf77ZKv5Vz/vY3uNo/0Rtm5e9pVFnAYmtpH2TTCBO6GiaRXPa0cgZE8LwfSY+mQtc1xfK5An/A== X-Received: by 2002:a62:6303:0:b0:578:83f5:554d with SMTP id x3-20020a626303000000b0057883f5554dmr11221485pfb.23.1671004108127; Tue, 13 Dec 2022 23:48:28 -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 q14-20020aa7842e000000b0056bd6b14144sm8736418pfn.180.2022.12.13.23.48.27 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Dec 2022 23:48:27 -0800 (PST) In-Reply-To: <479CD2BE-EFB5-426C-9C60-D22DBB75745D@easesoftware.com> X-Mailer: Apple Mail (2.3696.120.41.1.1) Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=casouri@gmail.com; helo=mail-pf1-x42b.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:301371 Archived-At: --Apple-Mail=_CBCD08CF-724A-452F-9CC0-C786CF9FF818 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 >=20 > Also, I=E2=80=99ve bumped into the Info page about using Tree Sitter = for multi language modes. Is there an example of a mode that uses = multiple languages that I can look at for ideas? I=E2=80=99ve written a tiny html mode to make sure the multi language = APIs make sense. Hopefully I=E2=80=99ll find time to expand it a bit and = add a tree-sitter HTML mode. (If you are interested in doing it, please = go ahead.) Yuan --Apple-Mail=_CBCD08CF-724A-452F-9CC0-C786CF9FF818 Content-Disposition: attachment; filename=veb-mode.el Content-Type: application/octet-stream; x-unix-mode=0644; name="veb-mode.el" Content-Transfer-Encoding: 7bit ;;; veb-mode.el --- HTML mode -*- lexical-binding: t; -*- ;; Author: Yuan Fu ;;; Commentary: ;;; Code: (require 'treesit) (require 'js) (require 'css-mode) (defvar veb-mode--font-lock-settings (append (treesit-font-lock-rules :feature 'html-tag :language 'html '((tag_name) @font-lock-comment-face) :feature 'html-tag-error :language 'html '((erroneous_end_tag_name) @error) :feature 'html-meta :language 'html '((doctype) @font-lock-comment-face) :feature 'html-comment :language 'html '((comment) @font-lock-comment-face) :feature 'html-attribute :language 'html '((attribute_name) @font-lock-comment-face) :feature 'css-selector :language 'css '((class_selector) @css-selector) :feature 'css-property :language 'css '((property_name) @css-property) :feature 'css-comment :language 'css '((comment) @font-lock-comment-face)) (mapcar (lambda (rule) (list (nth 0 rule) (nth 1 rule) (intern (format "js-%s" (nth 2 rule))) (nth 3 rule))) js--treesit-font-lock-settings))) (defvar veb-mode--range-settings (treesit-range-rules :embed 'javascript :host 'html '((script_element (raw_text) @cap)) :embed 'css :host 'html '((style_element (raw_text) @cap)))) (defun veb-mode--language-at (pos) (let ((node (treesit-node-at pos 'html))) (pcase (treesit-node-type (treesit-node-parent node)) ("script_element" 'javascript) ("style_element" 'css) (_ 'html)))) (define-derived-mode veb-mode prog-mode "Veb" "A mode for HTML + CSS + Javascript." (cond ((treesit-ready-p '(html css javascript)) (treesit-parser-create 'javascript) (treesit-parser-create 'css) (treesit-parser-create 'html) (setq-local treesit-font-lock-settings veb-mode--font-lock-settings) (setq-local treesit-font-lock-feature-list '((html-tag html-comment html-tag-error) ( html-attribute css-comment css-property css-selector js-comment js-string js-declaration js-string js-keyword js-identifier js-expression js-constant) (js-property js-pattern js-jsx))) (setq-local treesit-range-settings veb-mode--range-settings) (setq-local treesit-language-at-point-function #'veb-mode--language-at) (treesit-major-mode-setup)))) ;;;###autoload (add-to-list 'auto-mode-alist '("\\.html\\'" . veb-mode)) (provide 'veb-mode) ;;; veb-mode.el ends here --Apple-Mail=_CBCD08CF-724A-452F-9CC0-C786CF9FF818--