conf-jsx.el 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. ;;; Code:
  2. (require 'web-mode)
  3. (require 'emmet-mode)
  4. (require 'web-beautify)
  5. (require 'company-tern)
  6. (define-derived-mode web-jsx-mode web-mode "web-jsx")
  7. (defvar distopico:web-mode-comments-faces
  8. '(web-mode-annotation-face
  9. web-mode-javascript-comment-face)
  10. "Comment faces of `web-mode' for add to `flyspell-prog-text-faces'.")
  11. (add-to-list 'interpreter-mode-alist '("react" . web-jsx-mode))
  12. (add-to-list 'interpreter-mode-alist '("jsx" . web-jsx-mode))
  13. (add-to-list 'auto-mode-alist '("\\.jsx\\'" . web-jsx-mode))
  14. (add-to-list 'magic-mode-alist '("/\\*\\* @jsx React\\.DOM \\*/" . web-jsx-mode))
  15. (add-to-list 'magic-mode-alist '("import React" . web-jsx-mode))
  16. ;; Beautify with js
  17. (eval-after-load 'web-jsx-mode
  18. '(define-key web-jsx-mode-map (kbd "C-c C-b f") 'web-beautify-js))
  19. ;; Functions
  20. (defun distopico:web-jsx-mode-hook ()
  21. "Adjust web-mode to JSX from spacemacs."
  22. (emmet-mode 1)
  23. (tern-mode 1)
  24. (ggtags-mode 1)
  25. ;; Support to imenu
  26. (setq-local imenu-create-index-function #'ggtags-build-imenu-index)
  27. ;; See https://github.com/CestDiego/emmet-mode/commit/3f2904196e856d31b9c95794d2682c4c7365db23
  28. (setq-local emmet-expand-jsx-className? t)
  29. ;; Enable js-mode snippets
  30. (yas-activate-extra-mode 'js-mode)
  31. ;; Force jsx content type
  32. (web-mode-set-content-type "jsx")
  33. ;; Don't auto-quote attribute values
  34. (setq-local web-mode-enable-auto-quoting nil)
  35. ;; Enable JSDoc
  36. (setq-local web-mode-enable-comment-annotation t)
  37. (dolist (web-face distopico:web-mode-comments-faces)
  38. (add-to-list (make-local-variable 'flyspell-prog-text-faces) web-face))
  39. ;; Fix some indentation problems
  40. (add-to-list (make-local-variable 'web-mode-indentation-params) '("lineup-ternary" . nil))
  41. ;; Common JS setup
  42. (distopico:js-common-setup))
  43. ;; Hooks
  44. (add-hook 'web-jsx-mode-hook 'distopico:web-jsx-mode-hook)
  45. (provide 'conf-jsx)
  46. ;;; conf-jsx.el ends here