[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/evil 53fb7af020 2/2: Restore the input method on deactivat
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/evil 53fb7af020 2/2: Restore the input method on deactivation of evil-local-mode |
Date: |
Fri, 17 Mar 2023 07:00:13 -0400 (EDT) |
branch: elpa/evil
commit 53fb7af0204d297661949aa208a867d74362a256
Author: ibbem <ibbem@ibbem.net>
Commit: Axel Forsman <axelsfor@gmail.com>
Restore the input method on deactivation of evil-local-mode
This ensures that the input method after deactivating evil-local-mode is
the same as the input method used for states with a non-nil
:input-method property.
This issue was discovered while investigating why the input method
couldn't be set by the agda2-mode while evil was active [1]. As the
change in major mode (to agda2-mode) caused evil-local-mode to be
disabled and reenabled by `define-globalized-minor-mode evil-mode`, the
input method was lost because the default state (i.e. normal state) does
have an :input-method property of nil.
In summary this patch fixes the approach used by agda2-mode [2] and the
official recommendation in the Emacs manual [3], e.g.
(add-hook 'text-mode-hook
(lambda () (set-input-method "german-prefix")))
[1]: https://github.com/agda/agda/issues/2141
[2]:
https://github.com/agda/agda/blob/37554c46cbd770fa630f9b164e2b543506acbdbc/src/data/emacs-mode/agda2-mode.el#L432
[3]:
https://www.gnu.org/software/emacs/manual/html_node/emacs/Select-Input-Method.html
---
evil-core.el | 1 +
evil-tests.el | 20 ++++++++++++++++++++
2 files changed, 21 insertions(+)
diff --git a/evil-core.el b/evil-core.el
index 3216c7a9ad..b1f5fb004b 100644
--- a/evil-core.el
+++ b/evil-core.el
@@ -134,6 +134,7 @@
(remove-hook 'activate-mark-hook 'evil-visual-activate-hook t)
(remove-hook 'input-method-activate-hook #'evil-activate-input-method t)
(remove-hook 'input-method-deactivate-hook #'evil-deactivate-input-method
t)
+ (activate-input-method evil-input-method)
(evil-change-state nil)))
;; Make the variable permanent local. This is particular useful in
diff --git a/evil-tests.el b/evil-tests.el
index 0a0bb4c2bf..fbf1cd4a6d 100644
--- a/evil-tests.el
+++ b/evil-tests.el
@@ -9679,6 +9679,26 @@ main(argc, argv) char **argv; {
(test-3-mode)
(should (eq evil-state 'insert))))
+(ert-deftest evil-test-keep-input-method ()
+ "Test that the input method is preserved when changing the major mode."
+ :tags '(evil core input-method)
+ (cl-flet ((use-german-input-method () (set-input-method "german-prefix")))
+ (unwind-protect
+ (progn
+ (add-hook 'text-mode-hook #'use-german-input-method)
+ (evil-test-buffer
+ "[]"
+ (should (equal evil-input-method nil))
+ ("a\"a" [escape])
+ "\"[a]"
+ (text-mode)
+ (should (equal evil-input-method "german-prefix"))
+ ("a\"a" [escape])
+ "\"a[รค]"
+ (emacs-lisp-mode)
+ (should (equal evil-input-method "german-prefix"))))
+ (remove-hook 'text-mode-hook #'use-german-input-method))))
+
(provide 'evil-tests)
;;; evil-tests.el ends here