diff --git a/common/home-manager/emacs/default.nix b/common/home-manager/emacs/default.nix index f0a1e02..c17a27e 100644 --- a/common/home-manager/emacs/default.nix +++ b/common/home-manager/emacs/default.nix @@ -440,6 +440,34 @@ in { ''; }; + add-node-modules-path = { + enable = true; + config = '' + (eval-after-load 'js2-mode + '(add-hook 'js2-mode-hook #'add-node-modules-path)) + (eval-after-load 'typescript-mode + '(add-hook 'typescript-mode-hook #'add-node-modules-path)) + (eval-after-load 'web-mode + '(add-hook 'web-mode-hook #'add-node-modules-path)) + ''; + }; + + prettier-js = { + enable = true; + after = [ "xe-tools" ]; + config = '' + (add-hook 'js2-mode-hook 'prettier-js-mode) + (add-hook 'web-mode-hook 'prettier-js-mode) + + (add-hook 'web-mode-hook #'(lambda () + (xe/enable-minor-mode + '("\\.jsx?\\'" . prettier-js-mode)))) + (add-hook 'web-mode-hook #'(lambda () + (xe/enable-minor-mode + '("\\.tsx?\\'" . prettier-js-mode)))) + ''; + }; + deno-fmt = { enable = true; config = '' diff --git a/common/home-manager/emacs/xe-tools.el b/common/home-manager/emacs/xe-tools.el index 3ea1ae1..9cbc98b 100644 --- a/common/home-manager/emacs/xe-tools.el +++ b/common/home-manager/emacs/xe-tools.el @@ -10,4 +10,10 @@ (interactive) (insert "ಠ_ಠ")) +(defun xe/enable-minor-mode (my-pair) + "Enable minor mode if filename match the regexp. MY-PAIR is a cons cell (regexp . minor-mode)." + (if (buffer-file-name) + (if (string-match (car my-pair) buffer-file-name) + (funcall (cdr my-pair))))) + (provide 'xe-tools)