Web Mode in Emacs
Created: Mar 18 2025, 21:03 UTC
Last modified: Mar 18 2025, 21:03 UTC
I sometimes use web mode for editing HTML templated documents for my websites.
I have all this enabled:
(setq web-mode-enable-auto-pairing 't)
(setq web-mode-enable-auto-closing 't)
(setq web-mode-enable-auto-indentation 't)
(setq web-mode-enable-auto-opening 't)
(setq web-mode-enable-auto-quoting 't)
(setq web-mode-enable-auto-expanding 't)
Roughly, we have:
- auto-pairing: automatic insertion of closing sequences of characters like {% %} for nunjucks templates, after you press space.
- auto-closing: automatic insertion of a closing tag when you start to close the tag.
- auto-opening: positioning the cursor in between the opening and closing tags when you press enter, with proper newlines
- auto-quoting: inserting the paired quote when you type the first one.
- auto-expanding: d/ will insert a <div></div>, for example
We also have a more general electric-pair-mode
(See Emacs Electric
Characters). which will insert matching braces or brackets or parentheses.
This unfortunately messes with the auto-pairing of things with curly braces,
like {% %}.