mirror of
https://github.com/doomemacs/doomemacs
synced 2025-08-03 12:27:26 -05:00
lang/javascript: detect preact import (for rjsx-mode)
This commit is contained in:
@ -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
|
||||||
|
Reference in New Issue
Block a user