Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

agda-mode: Make unicode play well with evil-mode #2141

Closed
ghost opened this issue Aug 13, 2016 · 11 comments
Closed

agda-mode: Make unicode play well with evil-mode #2141

ghost opened this issue Aug 13, 2016 · 11 comments
Labels
ux: emacs Issues relating to the Emacs agda2-mode

Comments

@ghost
Copy link

ghost commented Aug 13, 2016

Unicode input does not work in normalisation (via C-c C-n) or typechecking (C-c C-d) when using evil-mode.

To demonstrate this, install agda-mode and evil-mode, require evil-mode and load-file agda-mode, then open an Agda source file where you M-x evil-mode, and try to C-c C-n with e.g. '\bn'. Spoiler alert: you'll end up typing literally '\bn'.

@ghost
Copy link
Author

ghost commented Aug 13, 2016

Using unicode in the regular /-search would also be beneficial.

@andreasabel
Copy link
Member

I do not know evil-mode, but the Agda input method can be toggled by C-\ (e.g. turned on for search after C-s).

@ghost
Copy link
Author

ghost commented Aug 13, 2016

I am able to reproduce this when evil-mode is disabled.

Furthermore, if I run with (require 'evil-mode), open an Agda program, and run (turn-on-evil-mode), it still works. It even works using evil-mode's /-search. It also works in the normaliser and in the typechecker.

But, if you have (evil-mode 1) in your configuration, which turns on evil-mode globally -- it doesn't work in search. I don't know why this is significant. It's all very confusing.

The good news is that your C-\ tips always works for the normaliser and in the typechecker, even with evil-mode, so that's a godsend. Now if only search would be a little bit more collaborative as well.

@andreasabel
Copy link
Member

Shooting in the dark: could it be that if evil-mode is on globally, then the C-\ functionality is bound to something else globally, even in the search minibuffer?! [Not very consistent with the fact it works in Agda interaction though...]

Unfortunately, I am not good a emacs-lisp and I am not a vi user at all. Maybe @UlfNorell knows something, he is a vi user.

@ghost
Copy link
Author

ghost commented Aug 14, 2016

Interestingly C-h k C-\ says "C-\ runs the command toggle-input-method". I'm not an advanced emacs user yet, so I'm not sure how I can check what C-\ is bound to at the moment of attempting to search (either via / or via C-s). Amusingly, I found out that C-h d supports C-\ for some reason. It's all seemingly quite random to me as an inexperienced user.

@UlfNorell
Copy link
Member

I'm a vi user, but not an emacs user (except for Agda coding) and no evil-mode experience.

@nad
Copy link
Contributor

nad commented Aug 16, 2016

Let's try to figure out where the problem lies.

Load the following code (by placing the cursor right after the final closing parenthesis and typing M-x eval-last-sexp RET):

(defun quick-test (argument)
  "Prints ARGUMENT."
  (interactive "MWrite something: ")
  (message "%s" argument))

Now execute the code (using M-x quick-test RET) when evil-mode and the Agda input method are both active. Is the input method preserved? If not, then I don't think that the Agda mode is to blame.

@ghost
Copy link
Author

ghost commented Aug 17, 2016

I'm not sure what you mean by "preserved", but I can indeed activate it in this prompt.

@nad
Copy link
Contributor

nad commented Aug 17, 2016

I interpret your response as saying that, despite the Agda input method being active just before you run quick-test, it is not initially active in the minibuffer. This suggests to me that evil-mode messes with the input method in some way.

@nad nad closed this as completed Aug 17, 2016
ibbem added a commit to ibbem/evil that referenced this issue Mar 15, 2023
This ensures that the input method after deactivating evil-local-mode is
the same as the input method used for states with an :input-method
property of non-nil.

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
[1]: 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
ibbem added a commit to ibbem/evil that referenced this issue Mar 15, 2023
This ensures that the input method after deactivating evil-local-mode is
the same as the input method used for states with an :input-method
property of non-nil.

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
ibbem added a commit to ibbem/evil that referenced this issue Mar 15, 2023
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
@ibbem
Copy link
Contributor

ibbem commented Mar 15, 2023

I've experienced the same issue. It's correct that evil is the problem in this case. I opened a pull request addressing this issue.

In the meantime, for everyone who is annoyed by this: Putting the following code snippet in your Emacs config solves this issue (eliminates the need for pressing C-\ on each new Agda buffer).

(defun set-agda-input-method ()
  (evil-without-input-method-hooks ;; Disable evil's hooks which reset current-input-method in favor of evil-input-method before the evil minor mode has been loaded.
    (set-input-method "Agda")))
(add-hook 'agda2-mode-hook 'set-agda-input-method)

@pmbittner
Copy link

This works for me! Thank you so much. 😃

GNU Emacs 28.1
Spacemacs v.0.999.0

@andreasabel andreasabel added the ux: emacs Issues relating to the Emacs agda2-mode label Mar 16, 2023
axelf4 pushed a commit to emacs-evil/evil that referenced this issue Mar 17, 2023
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ux: emacs Issues relating to the Emacs agda2-mode
Projects
None yet
Development

No branches or pull requests

5 participants