Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add whitelist for file_type_emacs value #204

Merged
merged 3 commits into from
Oct 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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