all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Foo.html.erb -- major mode
@ 2022-12-13 15:26 Perry Smith
  2022-12-13 16:29 ` Dmitry Gutov
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Perry Smith @ 2022-12-13 15:26 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 780 bytes --]

I assume that no one yet has written a major mode using Tree Sitter for Rail’s view files which combine HTML and erb (embedded ruby) but wanted to check.

Will there be a naming convention for such modes?  Currently I use the existing web-mode package for this task.  I think naming it erb-ts-mode will be a mistake since erb is always going to be mixed in with another “language”.  Perhaps html-erb-ts-mode ?

Also, I’ve 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?

Last, since I’m relatively up to speed on Tree Sitter at this point, is there any glaring need for a Tree Sitter based mode for a particular language?

Thank you,
Perry


[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Foo.html.erb -- major mode
  2022-12-13 15:26 Foo.html.erb -- major mode Perry Smith
@ 2022-12-13 16:29 ` Dmitry Gutov
  2022-12-13 22:56   ` chad
  2022-12-14  7:48 ` Yuan Fu
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: Dmitry Gutov @ 2022-12-13 16:29 UTC (permalink / raw)
  To: Perry Smith, emacs-devel

On 13/12/2022 17:26, Perry Smith wrote:
> Will there be a naming convention for such modes?  Currently I use the existing web-mode package for this task.

I'm using html-erb-mode from mmm-mode for that now.

> I think naming it erb-ts-mode will be a mistake since erb is always going to be mixed in with another “language”.  Perhaps html-erb-ts-mode ?

Sounds good.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Foo.html.erb -- major mode
  2022-12-13 16:29 ` Dmitry Gutov
@ 2022-12-13 22:56   ` chad
  0 siblings, 0 replies; 6+ messages in thread
From: chad @ 2022-12-13 22:56 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: Perry Smith, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 612 bytes --]

There's a mode specifically for HTML and Embedded Ruby and it's _not_
called herb-mode? 😯

(please forgive the aside)
~Chad

On Tue, Dec 13, 2022 at 11:30 AM Dmitry Gutov <dgutov@yandex.ru> wrote:

> On 13/12/2022 17:26, Perry Smith wrote:
> > Will there be a naming convention for such modes?  Currently I use the
> existing web-mode package for this task.
>
> I'm using html-erb-mode from mmm-mode for that now.
>
> > I think naming it erb-ts-mode will be a mistake since erb is always
> going to be mixed in with another “language”.  Perhaps html-erb-ts-mode ?
>
> Sounds good.
>
>

[-- Attachment #2: Type: text/html, Size: 948 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Foo.html.erb -- major mode
  2022-12-13 15:26 Foo.html.erb -- major mode Perry Smith
  2022-12-13 16:29 ` Dmitry Gutov
@ 2022-12-14  7:48 ` Yuan Fu
  2022-12-14  8:08 ` Theodor Thornhill
  2022-12-15 15:08 ` Dmitry Gutov
  3 siblings, 0 replies; 6+ messages in thread
From: Yuan Fu @ 2022-12-14  7:48 UTC (permalink / raw)
  To: Perry Smith; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 413 bytes --]

> 
> Also, I’ve 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’ve written a tiny html mode to make sure the multi language APIs make sense. Hopefully I’ll 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


[-- Attachment #2: veb-mode.el --]
[-- Type: application/octet-stream, Size: 2659 bytes --]

;;; veb-mode.el --- HTML mode  -*- lexical-binding: t; -*-

;; Author: Yuan Fu <casouri@gmail.com>

;;; 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Foo.html.erb -- major mode
  2022-12-13 15:26 Foo.html.erb -- major mode Perry Smith
  2022-12-13 16:29 ` Dmitry Gutov
  2022-12-14  7:48 ` Yuan Fu
@ 2022-12-14  8:08 ` Theodor Thornhill
  2022-12-15 15:08 ` Dmitry Gutov
  3 siblings, 0 replies; 6+ messages in thread
From: Theodor Thornhill @ 2022-12-14  8:08 UTC (permalink / raw)
  To: Perry Smith, emacs-devel

Perry Smith <pedz@easesoftware.com> writes:

> I assume that no one yet has written a major mode using Tree Sitter
> for Rail’s view files which combine HTML and erb (embedded ruby) but
> wanted to check.
>
> Will there be a naming convention for such modes?  Currently I use the
> existing web-mode package for this task.  I think naming it
> erb-ts-mode will be a mistake since erb is always going to be mixed in
> with another “language”.  Perhaps html-erb-ts-mode ?
>
> Also, I’ve 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?
>
> Last, since I’m relatively up to speed on Tree Sitter at this point,
> is there any glaring need for a Tree Sitter based mode for a
> particular language?
>
> Thank you,
> Perry


Did you consider using this [0] parser?

Theo

[0]: https://github.com/tree-sitter/tree-sitter-embedded-template



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Foo.html.erb -- major mode
  2022-12-13 15:26 Foo.html.erb -- major mode Perry Smith
                   ` (2 preceding siblings ...)
  2022-12-14  8:08 ` Theodor Thornhill
@ 2022-12-15 15:08 ` Dmitry Gutov
  3 siblings, 0 replies; 6+ messages in thread
From: Dmitry Gutov @ 2022-12-15 15:08 UTC (permalink / raw)
  To: Perry Smith, emacs-devel

On 13/12/2022 17:26, Perry Smith wrote:
> Last, since I’m relatively up to speed on Tree Sitter at this point, is there any glaring need for a Tree Sitter based mode for a particular language?

Speaking of: crystal-mode. I had received a feature request for it not 
too long ago.

It's not hugely popular, but it looks very much like Ruby, so it could 
be easy enough to support together, or implement using similar code.



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-12-15 15:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-13 15:26 Foo.html.erb -- major mode Perry Smith
2022-12-13 16:29 ` Dmitry Gutov
2022-12-13 22:56   ` chad
2022-12-14  7:48 ` Yuan Fu
2022-12-14  8:08 ` Theodor Thornhill
2022-12-15 15:08 ` Dmitry Gutov

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.