branch: scratch/editorconfig-cc
commit 9b86ec3902c95bc69d8f08a9b142bc0b19635642
Author: 10sr <[email protected]>
Commit: Stefan Monnier <[email protected]>
Add file_type_emacs support
---
editorconfig.el | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/editorconfig.el b/editorconfig.el
index ff02aad1d1..c1337a50f4 100644
--- a/editorconfig.el
+++ b/editorconfig.el
@@ -279,6 +279,32 @@ current buffer yet.")
(> (string-to-number length) 0))
(setq fill-column (string-to-number length))))
+(defun editorconfig--is-a-mode-p (current want)
+ "Return non-nil if major mode CURRENT is a major mode WANT."
+ (or (eq current
+ want)
+ (let ((parent (get current 'derived-mode-parent)))
+ (and parent
+ (editorconfig--is-a-mode-p parent want)))))
+
+(defun editorconfig-set-major-mode (filetype)
+ "Set buffer `major-mode' by FILETYPE.
+
+FILETYPE should be s string like `\"ini\"`, if not nil or empty string."
+ (let ((mode (and filetype
+ (not (string= filetype
+ ""))
+ (intern (concat filetype
+ "-mode")))))
+ (when (and mode
+ (not (editorconfig--is-a-mode-p major-mode
+ mode)))
+ (if (fboundp mode)
+ (funcall mode)
+ (display-warning :error (format "Major-mode `%S' not found"
+ mode))
+ nil))))
+
(defun editorconfig-call-editorconfig-exec ()
)
@@ -350,6 +376,7 @@ applies available properties."
(gethash 'end_of_line props)
(gethash 'charset props))
(editorconfig-set-line-length (gethash 'max_line_length props))
+ (editorconfig-set-major-mode (gethash 'file_type_emacs props))
(condition-case err
(run-hook-with-args 'editorconfig-custom-hooks props)
(error