lang/javascript: detect preact import (for rjsx-mode)
This commit is contained in:
parent
306c41e7b8
commit
37b2563dd1
1 changed files with 3 additions and 2 deletions
|
@ -47,14 +47,15 @@
|
||||||
:mode "components/.+\\.js$"
|
:mode "components/.+\\.js$"
|
||||||
:init
|
:init
|
||||||
(defun +javascript-jsx-file-p ()
|
(defun +javascript-jsx-file-p ()
|
||||||
|
"Detect React or preact imports early in the file."
|
||||||
(and buffer-file-name
|
(and buffer-file-name
|
||||||
(string= (file-name-extension buffer-file-name) "js")
|
(string= (file-name-extension buffer-file-name) "js")
|
||||||
(re-search-forward "\\(^\\s-*import React\\|\\( from \\|require(\\)[\"']react\\)"
|
(re-search-forward "\\(^\\s-*import +\\(?:pr\\|R\\)eact\\|\\( from \\|require(\\)[\"']p?react\\)"
|
||||||
magic-mode-regexp-match-limit t)
|
magic-mode-regexp-match-limit t)
|
||||||
(progn (goto-char (match-beginning 1))
|
(progn (goto-char (match-beginning 1))
|
||||||
(not (sp-point-in-string-or-comment)))))
|
(not (sp-point-in-string-or-comment)))))
|
||||||
|
|
||||||
(push (cons #'+javascript-jsx-file-p 'rjsx-mode) magic-mode-alist)
|
(push '(+javascript-jsx-file-p . rjsx-mode) magic-mode-alist)
|
||||||
:config
|
:config
|
||||||
(set! :electric 'rjsx-mode :chars '(?\} ?\) ?. ?>))
|
(set! :electric 'rjsx-mode :chars '(?\} ?\) ?. ?>))
|
||||||
(add-hook! 'rjsx-mode-hook
|
(add-hook! 'rjsx-mode-hook
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue