-
-
Save troglotit/c931bb43c8ee8f657e9cb40683c3670a to your computer and use it in GitHub Desktop.
Typescript with CSS in JS (styled-components, Emotion), JSX and graphql highlight and major mode for Emacs Doom with `mmm-mode` for *.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Assign typescript-mode to .tsx files | |
(add-to-list 'auto-mode-alist '("\\.tsx\\'" . typescript-mode)) | |
(require 'mmm-mode) | |
(setq mmm-global-mode t) | |
(setq mmm-submode-decoration-level 0) ;; Turn off background highlight | |
;; Add css mode for CSS in JS blocks | |
(mmm-add-classes | |
'((mmm-styled-mode | |
:submode css-mode | |
:front "\\(styled\\|css\\)[.()<>[:alnum:]]?+`" | |
:back "`;"))) | |
(mmm-add-mode-ext-class 'typescript-mode nil 'mmm-styled-mode) | |
;; Add submodule for graphql blocks | |
(mmm-add-classes | |
'((mmm-graphql-mode | |
:submode graphql-mode | |
:front "gr?a?p?h?ql`" | |
:back "`;"))) | |
(mmm-add-mode-ext-class 'typescript-mode nil 'mmm-graphql-mode) | |
;; Add JSX submodule, because typescript-mode is not that great at it | |
(mmm-add-classes | |
'((mmm-jsx-mode | |
:front "\\(return\s\\|n\s\\|(\n\s*\\)<" | |
:front-offset -1 | |
:back ">\n?\s*)" | |
:back-offset 1 | |
:submode web-mode))) | |
(mmm-add-mode-ext-class 'typescript-mode nil 'mmm-jsx-mode) | |
(defun mmm-reapply () | |
(mmm-mode) | |
(mmm-mode)) | |
(add-hook 'after-save-hook | |
(lambda () | |
(when (string-match-p "\\.tsx?" buffer-file-name) | |
(mmm-reapply)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Packages used in config.el for regular emacs you'll need `use-package` I guess | |
(package! mmm-mode) | |
(package! typescript-mode) | |
(package! web-mode) | |
(package! graphql-mode) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment