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
|
(def-package! cc-mode
|
||||||
:commands (c-mode c++-mode objc-mode java-mode)
|
:commands (c-mode c++-mode objc-mode java-mode)
|
||||||
:mode ("\\.mm" . objc-mode)
|
:mode ("\\.mm" . objc-mode)
|
||||||
:init
|
:preface
|
||||||
(setq-default c-basic-offset tab-width)
|
(defun +cc-c++-header-file-p ()
|
||||||
|
|
||||||
(defun +cc--c++-header-file-p ()
|
|
||||||
(and buffer-file-name
|
(and buffer-file-name
|
||||||
(equal (file-name-extension buffer-file-name) "h")
|
(equal (file-name-extension buffer-file-name) "h")
|
||||||
(or (file-exists-p (expand-file-name
|
(or (file-exists-p (expand-file-name
|
||||||
|
@ -42,14 +40,16 @@ compilation database is present in the project.")
|
||||||
(projectile-current-project-files))))
|
(projectile-current-project-files))))
|
||||||
(equal (file-name-extension file) "cpp")))))
|
(equal (file-name-extension file) "cpp")))))
|
||||||
|
|
||||||
(defun +cc--objc-header-file-p ()
|
(defun +cc-objc-header-file-p ()
|
||||||
(and buffer-file-name
|
(and buffer-file-name
|
||||||
(equal (file-name-extension buffer-file-name) "h")
|
(equal (file-name-extension buffer-file-name) "h")
|
||||||
(re-search-forward "@\\<interface\\>" magic-mode-regexp-match-limit t)))
|
(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--c++-header-file-p 'c++-mode) magic-mode-alist)
|
(push (cons #'+cc-objc-header-file-p 'objc-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
|
:config
|
||||||
(set! :electric '(c-mode c++-mode objc-mode java-mode)
|
(set! :electric '(c-mode c++-mode objc-mode java-mode)
|
||||||
|
|
|
@ -103,17 +103,16 @@
|
||||||
:mode "\\.jsx$"
|
:mode "\\.jsx$"
|
||||||
:mode "components/.+\\.js$"
|
:mode "components/.+\\.js$"
|
||||||
:init
|
:init
|
||||||
;; auto-detect JSX file
|
(defun +javascript-jsx-file-p ()
|
||||||
(push (cons (lambda ()
|
(and buffer-file-name
|
||||||
(and buffer-file-name
|
(equal (file-name-extension buffer-file-name) "js")
|
||||||
(equal (file-name-extension buffer-file-name) "js")
|
(re-search-forward "\\(^\\s-*import React\\|\\( from \\|require(\\)[\"']react\\)"
|
||||||
(re-search-forward "\\(^\\s-*import React\\|\\( from \\|require(\\)[\"']react\\)"
|
magic-mode-regexp-match-limit t)
|
||||||
magic-mode-regexp-match-limit t)
|
(progn
|
||||||
(progn
|
(goto-char (match-beginning 1))
|
||||||
(goto-char (match-beginning 1))
|
(not (sp-point-in-string-or-comment)))))
|
||||||
(not (sp-point-in-string-or-comment)))))
|
|
||||||
'rjsx-mode)
|
(push (cons #'+javascript-jsx-file-p 'rjsx-mode) magic-mode-alist)
|
||||||
magic-mode-alist)
|
|
||||||
|
|
||||||
:config
|
:config
|
||||||
(set! :electric 'rjsx-mode :chars '(?\} ?\) ?. ?>))
|
(set! :electric 'rjsx-mode :chars '(?\} ?\) ?. ?>))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue