nixos/pkgsets/emacs/web-mode.nix

99 lines
2.9 KiB
Nix
Raw Normal View History

{ config, lib, ... }:
with lib;
mkIf (elem "emacs::web-mode" config.machine.pkgs) {
2021-11-07 16:05:02 +01:00
programs.emacs.init.usePackage = {
web-mode = {
enable = true;
2023-01-29 14:34:19 +01:00
init = "(require 'sgml-mode)";
hook = [
"(web-mode . (lambda () (sgml-electric-tag-pair-mode)))"
''
(web-mode . (lambda ()
(when (and (buffer-file-name)
(equal (file-name-extension (buffer-file-name)) "svelte"))
(lsp))))
''
];
2021-11-07 16:05:02 +01:00
# bind = {};
mode = [
''("\\.html\\'" . web-mode)''
''("\\.css\\'" . web-mode)''
''("\\.html?\\'" . web-mode)''
2023-01-29 14:34:19 +01:00
''("\\.svelte\\'" . web-mode)''
2021-11-07 16:05:02 +01:00
''("\\.phtml\\'" . web-mode)''
''("\\.tpl\\.php\\'" . web-mode)''
''("\\.[agj]sp\\'" . web-mode)''
''("\\.as[cp]x\\'" . web-mode)''
''("\\.erb\\'" . web-mode)''
''("\\.mustache\\'" . web-mode)''
''("\\.djhtml\\'" . web-mode)''
];
config = ''
2023-01-29 14:34:19 +01:00
(setq web-mode-markup-indent-offset 2)
(setq web-mode-css-indent-offset 2)
(setq web-mode-code-indent-offset 2)
(setq web-mode-sql-indent-offset 2)
(setq web-mode-script-padding 2)
(setq web-mode-style-padding 2)
(setq web-mode-part-padding 2)
(setq web-mode-block-padding 2)
(setq web-mode-enable-comment-annotation 't)
(setq web-mode-enable-current-element-highlight 't)
(setq web-mode-enable-sql-detection 't)
(setq web-mode-auto-close-style 2)
2021-11-07 16:05:02 +01:00
(setq web-mode-engines-alist
'(("php" . "\\.phtml\\'")
("blade" . "\\.blade\\."))
)
'';
};
js2-mode = {
enable = true;
mode = [
''("\\.js\\'" . js2-mode)''
];
2021-11-07 16:05:02 +01:00
};
typescript-mode = {
2021-11-07 16:05:02 +01:00
enable = true;
2023-01-29 14:34:19 +01:00
hook = [ "(typescript-mode . (lambda () (subword-mode)))" ]
++ lib.optional (elem "emacs::lsp" config.machine.pkgs)
''(typescript-mode . (lambda () (lsp)))'';
mode = [
''("\\.ts\\'" . typescript-mode)''
2023-01-29 14:34:19 +01:00
''("\\.tsx?\\'" . typescript-tsx-mode)''
2021-11-07 16:05:02 +01:00
];
2023-01-29 14:34:19 +01:00
init = ''
(define-derived-mode typescript-tsx-mode typescript-mode "tsx")
'';
config = ''
(setq typescript-indent-level 2)
'';
};
# https://github.com/NixOS/nixpkgs/pull/150239
tree-sitter = {
enable = true;
package = (epkgs: [ epkgs.tree-sitter (epkgs.tree-sitter-langs.withPlugins(p: epkgs.tree-sitter-langs.plugins ++ [ p.tree-sitter-markdown p.tree-sitter-tsx ]))]);
hook = [
"(typescript-mode . tree-sitter-hl-mode)"
"(typescript-tsx-mode . tree-sitter-hl-mode)"
];
config = ''
(tree-sitter-require 'tsx)
(add-to-list 'tree-sitter-major-mode-language-alist '(typescript-tsx-mode . tsx))
'';
2021-11-07 16:05:02 +01:00
};
impatient-mode = {
enable = true;
};
simple-httpd = {
enable = true;
};
};
}