branch: scratch/editorconfig-cc
commit 91feb336b051567ee4fc3dfeb7524ede6a939ee7
Author: 10sr <[email protected]>
Commit: Stefan Monnier <[email protected]>
Use flag instead of adding -2-mode for new version testing (#251)
* Use flag instead of adding -2-mode
* Fix test
---
editorconfig.el | 65 ++++++++++++++++++++++-----------------------
ert-tests/editorconfig-2.el | 44 +++++++++++++++++-------------
2 files changed, 57 insertions(+), 52 deletions(-)
diff --git a/editorconfig.el b/editorconfig.el
index 5e2b941ce2..3ace919bf2 100644
--- a/editorconfig.el
+++ b/editorconfig.el
@@ -671,47 +671,46 @@ F is that function, and FILENAME and ARGS are arguments
passed to F."
(format "Error while setting variables from
EditorConfig: %S" err))))
ret))
+(defvar editorconfig--enable-20210221-testing nil
+ "Enable testing version of `editorconfig-mode'.
+
+Currently this mode is not well tested yet and can cause unexpected behaviors
+like killing Emacs process or not able to visit files at all.")
+
;;;###autoload
(define-minor-mode editorconfig-mode
"Toggle EditorConfig feature.
To disable EditorConfig in some buffers, modify
`editorconfig-exclude-modes' or `editorconfig-exclude-regexps'."
- :global t
- :lighter " EditorConfig"
- ;; See https://github.com/editorconfig/editorconfig-emacs/issues/141 for why
- ;; not `after-change-major-mode-hook'
- (dolist (hook '(change-major-mode-after-body-hook
- read-only-mode-hook
- ;; Some modes call `kill-all-local-variables' in their init
- ;; code, which clears some values set by editorconfig.
- ;; For those modes, editorconfig-apply need to be called
- ;; explicitly through their hooks.
- rpm-spec-mode-hook
- ))
- (if editorconfig-mode
- (add-hook hook 'editorconfig-mode-apply)
- (remove-hook hook 'editorconfig-mode-apply))))
-
-(define-minor-mode editorconfig-2-mode
- "Toggle EditorConfig feature.
-
-This function is provided temporarily for beta testing, and not well tested
yet.
-Currently this can cause unexpected behaviors like kill emacs processes and
-destroying your files, so please use with caution if you enable this instead of
- `editorconfig-mode'."
:global t
:lighter editorconfig-mode-lighter
- (if editorconfig-2-mode
- (progn
- (advice-add 'find-file-noselect :around
'editorconfig--advice-find-file-noselect)
- (advice-add 'insert-file-contents :around
'editorconfig--advice-insert-file-contents)
- (add-hook 'read-only-mode-hook
- 'editorconfig-mode-apply))
- (advice-remove 'find-file-noselect
'editorconfig--advice-find-file-noselect)
- (advice-remove 'insert-file-contents
'editorconfig--advice-insert-file-contents)
- (remove-hook 'read-only-mode-hook
- 'editorconfig-mode-apply)))
+ (if editorconfig--enable-20210221-testing
+ (if editorconfig-mode
+ (progn
+ (advice-add 'find-file-noselect :around
'editorconfig--advice-find-file-noselect)
+ (advice-add 'insert-file-contents :around
'editorconfig--advice-insert-file-contents)
+ (add-hook 'read-only-mode-hook
+ 'editorconfig-mode-apply))
+ (advice-remove 'find-file-noselect
'editorconfig--advice-find-file-noselect)
+ (advice-remove 'insert-file-contents
'editorconfig--advice-insert-file-contents)
+ (remove-hook 'read-only-mode-hook
+ 'editorconfig-mode-apply))
+
+ ;; editorconfig--enable-20210221-testing is disabled
+ ;; See https://github.com/editorconfig/editorconfig-emacs/issues/141 for
why
+ ;; not `after-change-major-mode-hook'
+ (dolist (hook '(change-major-mode-after-body-hook
+ read-only-mode-hook
+ ;; Some modes call `kill-all-local-variables' in their init
+ ;; code, which clears some values set by editorconfig.
+ ;; For those modes, editorconfig-apply need to be called
+ ;; explicitly through their hooks.
+ rpm-spec-mode-hook
+ ))
+ (if editorconfig-mode
+ (add-hook hook 'editorconfig-mode-apply)
+ (remove-hook hook 'editorconfig-mode-apply)))))
;; Tools
diff --git a/ert-tests/editorconfig-2.el b/ert-tests/editorconfig-2.el
index 348ec49c0e..f06aba49f0 100644
--- a/ert-tests/editorconfig-2.el
+++ b/ert-tests/editorconfig-2.el
@@ -40,7 +40,8 @@
(ert-deftest test-editorconfig-2 nil
"Check if properties are applied."
- (editorconfig-2-mode 1)
+ (let ((editorconfig--enable-20210221-testing t))
+ (editorconfig-mode 1)
(with-visit-file (concat editorconfig-ert-dir
"3_space.txt")
@@ -52,10 +53,11 @@
(should (eq python-indent-offset 4))
(should (eq tab-width 8))
(should (eq indent-tabs-mode nil)))
- (editorconfig-2-mode -1))
+ (editorconfig-mode -1)))
(ert-deftest test-lisp-use-default-indent-2 nil
- (editorconfig-2-mode 1)
+ (let ((editorconfig--enable-20210221-testing t))
+ (editorconfig-mode 1)
(with-visit-file (concat editorconfig-secondary-ert-dir
"2_space.el")
@@ -75,10 +77,11 @@
(with-visit-file (concat editorconfig-secondary-ert-dir
"2_space.el")
(should (eq lisp-indent-offset 2))))
- (editorconfig-2-mode -1))
+ (editorconfig-mode -1)))
(ert-deftest test-trim-trailing-ws-2 nil
- (editorconfig-2-mode 1)
+ (let ((editorconfig--enable-20210221-testing t))
+ (editorconfig-mode 1)
(with-visit-file (concat editorconfig-ert-dir
"trim.txt")
(should (memq 'delete-trailing-whitespace
@@ -88,19 +91,21 @@
(read-only-mode 1)
(should (not (memq 'delete-trailing-whitespace
write-file-functions))))
- (editorconfig-2-mode -1))
+ (editorconfig-mode -1)))
(ert-deftest test-file-type-emacs-2 nil
:expected-result t ;; Ignore failure
- (editorconfig-2-mode 1)
+ (let ((editorconfig--enable-20210221-testing t))
+ (editorconfig-mode 1)
(with-visit-file (concat editorconfig-secondary-ert-dir
"c.txt")
(should (eq major-mode 'conf-unix-mode)))
- (editorconfig-2-mode -1))
+ (editorconfig-mode -1)))
(ert-deftest test-file-type-ext-2 nil
:expected-result t ;; Ignore failure
- (editorconfig-2-mode 1)
+ (let ((editorconfig--enable-20210221-testing t))
+ (editorconfig-mode 1)
(with-visit-file (concat editorconfig-secondary-ert-dir
"a.txt")
(should (eq major-mode 'conf-unix-mode)))
@@ -109,15 +114,16 @@
"bin/perlscript")
(should (eq major-mode 'perl-mode))
(should (eq perl-indent-level 5)))
- (editorconfig-2-mode -1))
+ (editorconfig-mode -1)))
(ert-deftest test-hack-properties-functions-2 nil
- (editorconfig-2-mode 1)
- (add-hook 'editorconfig-hack-properties-functions
- (lambda (props)
- (puthash 'indent_size "5" props)))
- (with-visit-file (concat editorconfig-ert-dir
- "4_space.py")
- (should (eq python-indent-offset 5)))
- (setq editorconfig-hack-properties-functions nil)
- (editorconfig-2-mode -1))
+ (let ((editorconfig--enable-20210221-testing t))
+ (editorconfig-mode 1)
+ (add-hook 'editorconfig-hack-properties-functions
+ (lambda (props)
+ (puthash 'indent_size "5" props)))
+ (with-visit-file (concat editorconfig-ert-dir
+ "4_space.py")
+ (should (eq python-indent-offset 5)))
+ (setq editorconfig-hack-properties-functions nil)
+ (editorconfig-mode -1)))