branch: scratch/editorconfig-cc
commit de2b7919571d374eaf5b9a68f747949b5072895b
Author: 10sr <[email protected]>
Commit: Stefan Monnier <[email protected]>
Add editorconfig-exclude-modes
---
editorconfig.el | 27 +++++++++++++++++++++++----
1 file changed, 23 insertions(+), 4 deletions(-)
diff --git a/editorconfig.el b/editorconfig.el
index e1de827889..0fb07b6af2 100644
--- a/editorconfig.el
+++ b/editorconfig.el
@@ -181,6 +181,11 @@ NOTE: Only the **buffer local** value of VARIABLE will be
set."
'editorconfig-indentation-alist
"0.5")
+(defcustom editorconfig-exclude-modes ()
+ "List of major mode symbols not to apply properties."
+ :type '(repeat (symbol :tag "Major Mode"))
+ :group 'editorconfig)
+
(defvar editorconfig-properties-hash nil
"Hash object of EditorConfig properties for current buffer.
Set by `editorconfig-apply' and nil if that is not invoked in current buffer
@@ -276,7 +281,9 @@ It calls `editorconfig-get-properties-from-exec' if
;;;###autoload
(defun editorconfig-apply ()
- "Apply EditorConfig properties for current buffer."
+ "Apply EditorConfig properties for current buffer.
+This function ignores `editorconfig-exclude-modes' and always applies available
+properties."
(interactive)
(when buffer-file-name
(condition-case err
@@ -297,15 +304,27 @@ It calls `editorconfig-get-properties-from-exec' if
". Styles will not be applied.")
:error)))))
+(defun editorconfig-mode-apply ()
+ "Apply EditorConfig properties for current buffer.
+This function do the job only when the major mode is not listed in
+`editorconfig-exclude-modes'."
+ (when (and major-mode
+ (not (memq major-mode
+ editorconfig-exclude-modes)))
+ (editorconfig-apply)))
+
;;;###autoload
(define-minor-mode editorconfig-mode
- "Toggle EditorConfig feature."
+ "Toggle EditorConfig feature.
+When enabled EditorConfig properties will be applied to buffers when first
+visiting files or changing major modes if the major mode is not listed in
+`editorconfig-exclude-modes'."
:global t
:lighter ""
(dolist (hook '(after-change-major-mode-hook))
(if editorconfig-mode
- (add-hook hook 'editorconfig-apply)
- (remove-hook hook 'editorconfig-apply))))
+ (add-hook hook 'editorconfig-mode-apply)
+ (remove-hook hook 'editorconfig-mode-apply))))