Refactor magic-mode-alist entries for rjsx-mode, c++-mode & objc-mode

This commit is contained in:
Henrik Lissner 2017-09-20 01:34:47 +02:00
parent 3fcbdae441
commit 58198acf18
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 18 additions and 19 deletions

View file

@ -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)

View file

@ -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 '(?\} ?\) ?. ?>))