Skip to content

Conversation

@jasalt
Copy link

@jasalt jasalt commented Nov 12, 2025

Noted issue with JS libraries / frameworks like Datastar and AlpineJS where attribute value non-indenting rules cannot be easily applied to attributes that use modifiers such as data-on:<eventname> or x-on:<eventname> as only string matches are looked from web-mode-indentless-attributes.

With this edit, wildcard postfix is allowed for more flexible matching e.g. following which should match attributes starting with data-on::

(setq web-mode-indentless-attributes
      '("onclick" "onmouseover" "onmouseout" "onsubmit" "data-on:*"))

With quick testing this seems to work but am evaluating it further currently. Is this sort of feature something that would be feasible to include in web-mode @fxbois ?

Test setup / demo (Emacs 30.1):

config.el

(setq-default indent-tabs-mode nil)
(setopt inhibit-splash-screen t)

;; Load the patched web-mode.el
(load "/home/user/Desktop/web-mode-attr-wildcard/web-mode/web-mode.el")
(add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))

;; Add custom rule to match data-on: attribute
(setq web-mode-indentless-attributes
      '("onclick" "onmouseover" "onmouseout" "onsubmit" "data-on:*"))

example.html

<div onclick="just {
                testing
              }"
     data-on:click="just {
                      testing
                    }"
     data-not-click="just {
              testing
              }"></div>
  • onclick keeps manual indent (as it does by default)
  • data-on:click follows same rule (matched by wildcard)
  • data-not-click gets auto indented (normal behavior)

Run: emacs -q -l ./config.el ./example.html

currently supports * postfix only
@fxbois
Copy link
Owner

fxbois commented Nov 13, 2025

Would it be possible for you to test that it works with 29.x version of emacs ?

@jasalt
Copy link
Author

jasalt commented Nov 13, 2025

@fxbois sure, I'll test it later next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants