Skip to content

Commit

Permalink
Restore the input method on deactivation of evil-local-mode
Browse files Browse the repository at this point in the history
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]: agda/agda#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
  • Loading branch information
ibbem authored and axelf4 committed Mar 17, 2023
1 parent bdbf41b commit 53fb7af
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions evil-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions evil-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 53fb7af

Please sign in to comment.