Skip to content

Commit

Permalink
Merge pull request #204 from editorconfig/modewhitelist
Browse files Browse the repository at this point in the history
Add whitelist for file_type_emacs value
  • Loading branch information
10sr authored Oct 9, 2019
2 parents 92c3736 + aefcc0b commit 4aa19cb
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion editorconfig.el
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,24 @@ to non-nil when FINAL-NEWLINE is true."
(> (string-to-number length) 0))
(setq fill-column (string-to-number length))))

(defvar editorconfig-file-type-emacs-whitelist
(append (mapcar 'car
editorconfig-indentation-alist)
'(conf-mode))
"List of known `major-mode' that can be used for file_type_emacs value.")

;; Emacs<26 does not have provided-mode-derived-p
(defun editorconfig--provided-mode-derived-p (mode &rest modes)
"Non-nil if MODE is derived from one of MODES.
Uses the `derived-mode-parent' property of the symbol to trace backwards.
If you just want to check `major-mode', use `derived-mode-p'."
(if (fboundp 'provided-mode-derived-p)
(apply 'provided-mode-derived-p mode modes)
(while (and (not (memq mode modes))
(setq mode (get mode 'derived-mode-parent))))
mode))


(defun editorconfig-set-major-mode-from-name (filetype)
"Set buffer `major-mode' by FILETYPE.
Expand All @@ -499,7 +517,12 @@ FILETYPE should be s string like `\"ini\"`, if not nil or empty string."
"-mode")))))
(when mode
(if (fboundp mode)
(editorconfig-apply-major-mode-safely mode)
(if (apply 'editorconfig--provided-mode-derived-p mode
editorconfig-file-type-emacs-whitelist)
(editorconfig-apply-major-mode-safely mode)
(display-warning :error (format "Major-mode `%S' is not listed in `%S'"
mode
'editorconfig-file-type-emacs-whitelist)))
(display-warning :error (format "Major-mode `%S' not found"
mode))
nil))))
Expand Down

0 comments on commit 4aa19cb

Please sign in to comment.