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

Conflict [uim-mode] [latex-mode]: Prefix key C-c overshadowed. #539

Closed
Araeos opened this issue Nov 29, 2014 · 9 comments
Closed

Conflict [uim-mode] [latex-mode]: Prefix key C-c overshadowed. #539

Araeos opened this issue Nov 29, 2014 · 9 comments

Comments

@Araeos
Copy link

Araeos commented Nov 29, 2014

Reproduction

uim (universal input method) is required for reproduction.

$ emacs --version
GNU Emacs 25.0.50.2
$ cd /tmp/
$ git clone https://github.com/capitaomorte/yasnippet.git yasnippet-bug
$ cd yasnippet-bug
$ git log -1 --oneline
50ca8d3 Update README.mdown

Copy this custom snippet (notice the binding) in /tmp/yasnippet-bug/yasnippets/latex-mode/jd

# -*- mode: snippet; require-final-newline: nil -*-
# name: latex \jdash
# key: jd
# binding: C-c d
# --
\\jdash 

Then executing this (in this order at least) yields the overshadowing of many keybindings.

$ HOME=$PWD emacs -L .

(latex-mode)
(require 'yasnippet)
(yas-global-mode 1)
(require 'uim)
(uim-mode)
(yas-load-directory "/tmp/yasnippet-bug/yasnippets/")

Description

According to my little understanding uim tries to read all input using its keymap (uim-mode keymap) in minor-mode-map-alist in order to send some key to the uim process. In this way I can use shortcuts for uim as well as emacs keybindings like C-c C-c(in Auctex).

This itself works well, but combined with the mentioned yasnippet it stops working. To be exact, all key sequences with the prefix key C-c stop working as if they were not defined. This includes all Auctex bindings beginning with C-c.

Now I gathered from the code that uim uses the minor-mode-map-alist while yasnippet uses emulation-mode-map-alists and since the snippet (above) uses the prefix key C-c it seems to overshadow all global and minor mode key bindings.

Observations

  • I get a normal "... is undefined" error
  • Even C-x C-c stops working, which I find very odd.
  • When other modes are enabled, even more keys may stop working (can't remember which).
  • Disabling either uim-mode or all conflicting modes (latex-mode) helps but is no real fix.
  • Disabling yasnippet didn't work
  • (add-to-list 'emulation-mode-map-alists (list (car minor-mode-map-alist))) seems to enable all broken keybindings by adding ((uim-mode kemap)) in front of yasnippets alist, but then the snippet keybindings seem to stop working...

I am know this is quite specific and could very well not be a bug, but I hope this helps anyone.

@npostavs
Copy link
Collaborator

npostavs commented Dec 3, 2014

You have a pretty detailed description but you left out how to install (and where to get) uim-mode. Is it the one from here? The installation looks pretty complicated, is it possible you can show the problem without uim-mode?

@Araeos
Copy link
Author

Araeos commented Dec 3, 2014

On arch linux uim-el is packaged directly in the official uim package and on ubuntu there seems to be a uim-el package.
I do not have this issue without either uim-mode or yas-mode, though i am beginning to suspect it's an incompatibility by design and not a bug.

@npostavs
Copy link
Collaborator

npostavs commented Dec 7, 2014

I installed uim-el with apt-get, but I don't see how to use it. The README seems to assume that the user already knows the key combinations to insert Japanese. The `uim-mode' Minor Mode Bindings: appears empty in describe-bindings.

The problem is likely related to the way uim-mode defines key bindings (uim-keymap.el):

    ((and uim-emacs (>= emacs-major-version 22)) ;;; GNU Emacs-22 or later
     (define-key uim-mode-map [t] 'uim-process-input)
     (define-key uim-preedit-map [t] 'uim-process-input)

     (define-key uim-mode-map [27] 'uim-process-input)

The [t] means "default definition" which is a somewhat lesser known feature of Emacs keymaps.

I don't see a real need for yasnippet to put bindings on emulation-mode-map-alists though.

@Araeos
Copy link
Author

Araeos commented Dec 8, 2014

Yeah, using it without prior knowledge would be difficult. The settings including keybindings would have been done outside of emacs (uim-pref-gtk3 is available in my setup), though enabling the minor mode is probably enough.

But i don't even understand how emacs would not see the keybinding. Or more specifically how the grabbed input via [t] would be passed back to emacs when uim works normally and does not consume the input.
Mhh, since that would have little to do with Yasnippet this may be not the right place for this issue, but I wouldn't know.

@joaotavora
Copy link
Owner

I don't see a real need for yasnippet to put bindings on emulation-mode-map-alists though.

This is tricky indeed, but how else can you implement snippet keybindings that activate/deactivate themselves according to yas--modes-to-activate and the snippet's "# condition" directive?

@npostavs
Copy link
Collaborator

I see 2 possibilities:

  1. Put all the (yas--direct-foo-mode . foo-table) directly into minor-mode-map-alist. This does make removing/disabling a bit more cumbersome. eg: let-binding yas--direct-keymaps would have to be replaced with cl-progv (which uses eval internally, icky).
  2. Create a buffer local variable with make-composed-keymap of the yas-minor-mode-map and all the direct keymaps which would then act as the yasnippet's true minor mode map.

I started implementing 1, but after running into the aforementioned problems I'm thinking 2 will be a better solution. I don't think it should have any problems, altough perhaps commands like describe-keybindings could get confused?

Oops, the buffer local value isn't used for the minor mode keymap. Need to think a bit more...

@npostavs
Copy link
Collaborator

Create a buffer local variable with make-composed-keymap of the yas-minor-mode-map and all the direct keymaps which would then act as the yasnippet's true minor mode map.

I've implemented something like this. Instead of a buffer local variable put all the keybindings in the map and yas-expand-from-keymap should handle the filtering. I'm not sure if everything works; some tests for direct keybindings should be added. But perhaps @Araeos can try it out with uim-mode and see if it makes a difference?

npostavs/yasnippet@capitaomorte:master...npostavs:minor-key

@Araeos
Copy link
Author

Araeos commented Dec 11, 2014

Ok, when replicating the bug as described above with the minor-key branch @npostavs I get the following behaviour:

  • C-c C-c from Auctex now works with uim and yasnippet enabled.
  • C-c d from the custom snippet jd does not work when uim mode is enabled, but works when it is disabled.

It seems, that the way uim grabs the input is quite invasive.

@npostavs
Copy link
Collaborator

npostavs commented Dec 7, 2015

@Araeos is this fixed in uim-el now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants