Skip to content

Instantly share code, notes, and snippets.

@idcrook
Created August 28, 2018 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save idcrook/443567a3b8476d33cba4fafae9ec1eab to your computer and use it in GitHub Desktop.
Save idcrook/443567a3b8476d33cba4fafae9ec1eab to your computer and use it in GitHub Desktop.
rsjx mode with attempt at auto-detecting JSX files
(use-package rjsx-mode
:mode "\\.jsx$"
:mode "components/.+\\.js$"
:init
;; auto-detect JSX file
;; https://github.com/shahinism/emacs.d/blob/master/configs.org
;; source: https://github.com/hlissner/.emacs.d/blob/master/modules/lang/javascript/config.el
(push (cons (lambda ()
(and buffer-file-name
(equal (file-name-extension buffer-file-name) "js")
(re-search-forward "\\(^\\s-*import React\\|\\( from \\|require(\\)[\"']react\\)"
magic-mode-regexp-match-limit t)
(progn
(goto-char (match-beginning 1))
;; sp-point-in-string-or-comment requires smartparens package
(not (sp-point-in-string-or-comment)))))
'rjsx-mode)
magic-mode-alist)
:config
;; match gatsby.js layout
(add-to-list 'auto-mode-alist '("components\\/.*\\.js\\'" . rjsx-mode))
(add-to-list 'auto-mode-alist '("layouts\\/.*\\.js\\'" . rjsx-mode))
(add-to-list 'auto-mode-alist '("templates\\/.*\\.js\\'" . rjsx-mode))
(add-to-list 'auto-mode-alist '("pages\\/.*\\.js\\'" . rjsx-mode)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment