Refactor magic-mode-alist entries for rjsx-mode, c++-mode & objc-mode
This commit is contained in:
parent
3fcbdae441
commit
58198acf18
2 changed files with 18 additions and 19 deletions
|
@ -28,10 +28,8 @@ compilation database is present in the project.")
|
|||
(def-package! cc-mode
|
||||
:commands (c-mode c++-mode objc-mode java-mode)
|
||||
:mode ("\\.mm" . objc-mode)
|
||||
:init
|
||||
(setq-default c-basic-offset tab-width)
|
||||
|
||||
(defun +cc--c++-header-file-p ()
|
||||
:preface
|
||||
(defun +cc-c++-header-file-p ()
|
||||
(and buffer-file-name
|
||||
(equal (file-name-extension buffer-file-name) "h")
|
||||
(or (file-exists-p (expand-file-name
|
||||
|
@ -42,14 +40,16 @@ compilation database is present in the project.")
|
|||
(projectile-current-project-files))))
|
||||
(equal (file-name-extension file) "cpp")))))
|
||||
|
||||
(defun +cc--objc-header-file-p ()
|
||||
(defun +cc-objc-header-file-p ()
|
||||
(and buffer-file-name
|
||||
(equal (file-name-extension buffer-file-name) "h")
|
||||
(re-search-forward "@\\<interface\\>" magic-mode-regexp-match-limit t)))
|
||||
|
||||
;; Auto-detect C++/Obj-C header files
|
||||
(push (cons #'+cc--c++-header-file-p 'c++-mode) magic-mode-alist)
|
||||
(push (cons #'+cc--objc-header-file-p 'objc-mode) magic-mode-alist)
|
||||
(push (cons #'+cc-c++-header-file-p 'c++-mode) magic-mode-alist)
|
||||
(push (cons #'+cc-objc-header-file-p 'objc-mode) magic-mode-alist)
|
||||
|
||||
:init
|
||||
(setq-default c-basic-offset tab-width)
|
||||
|
||||
:config
|
||||
(set! :electric '(c-mode c++-mode objc-mode java-mode)
|
||||
|
|
|
@ -103,17 +103,16 @@
|
|||
:mode "\\.jsx$"
|
||||
:mode "components/.+\\.js$"
|
||||
:init
|
||||
;; auto-detect JSX file
|
||||
(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))
|
||||
(not (sp-point-in-string-or-comment)))))
|
||||
'rjsx-mode)
|
||||
magic-mode-alist)
|
||||
(defun +javascript-jsx-file-p ()
|
||||
(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))
|
||||
(not (sp-point-in-string-or-comment)))))
|
||||
|
||||
(push (cons #'+javascript-jsx-file-p 'rjsx-mode) magic-mode-alist)
|
||||
|
||||
:config
|
||||
(set! :electric 'rjsx-mode :chars '(?\} ?\) ?. ?>))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue