[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Partially answering my own question (was Re: not quite understanding inp
From: |
Perry E. Metzger |
Subject: |
Partially answering my own question (was Re: not quite understanding input methods) |
Date: |
Wed, 1 Sep 2021 09:29:47 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:92.0) Gecko/20100101 Thunderbird/92.0 |
Answering my own question a bit, so that others might benefit from what
I've learned.
On 8/30/21 13:24, Perry E. Metzger wrote:
So I've built a small input method to test out my understanding, and
I've hit a bit of a wall.
I would like to prefix my translations with a special character. I've
mapped my caps lock key to send F19 (I don't use the caps lock key
ever and using it as a compose key seems reasonable) and I've set
Emacs to insert a special character for me when I hit that key, like so:
(global-set-key (kbd "<f19>")
(lambda (n)
(interactive "p")
(self-insert-command n ?⎄)))
(That special character happens to be the unicode "COMPOSE SYMBOL",
which seemed intuitively appropriate.)
I've also created a small input method, and which has the following
rules:
(quail-define-rules
("⎄gl" ?λ)
("⎄gL" ?Λ)
("⎄iA" ?∀)
("⎄iE" ?∃)
("xx" ?Π)
)
Now, if I hit "xx", Π is inserted as expected, but if I hit "<F19> g
l", the buffer shows me "⎄gl" and not "λ" as I would expect.
My guess is that something in the belly of Quail is reading events and
not the characters in the buffer, but as there's no documentation I'm
not really clear on what is going on.
For the benefit of all: indeed, Quail ends up hooking events, and not
characters. It's fed those in read_char, which hands off all events
optionally to a function stored in input-method-function, which is where
Quail gets its hook into the whole thing. Quail functions by taking over
reading the input events if it decides that an event might be the prefix
of a thing it wants to translate, and afterwards returns the replacement
event (that is, the translated character.)
The system is currently incapable (without a bunch of hacking that I
haven't done yet and might not do) of handling characters to be
translated that are above code 255 -- this limitation exists not only in
read_char but also in quail.el itself. (If you just fix this in
read_char you can easily end up getting emacs to hang, though I haven't
yet tracked down exactly where in quail the hang happens.)
The right way for now to do something demented like what I'm trying
above is first
1. Use a character like "¤" which is below 255 in Unicode to represent
hitting your function key.
2. Insert a synthetic keystroke into the event stream by appending it to
`unread-input-method-events`; you may do this approximately like so:
(global-set-key (kbd "<f19>")
(lambda (n)
(interactive "p")
(setq unread-input-method-events
(append unread-input-method-events '(?¤)))))
I still don't quite have everything right here; in particular, things
like isearch don't work right. My suspicion is that I need to put this
into an early input processing keymap and not the global keymap, but I
thought I'd explain what I have figured out so far.
Perry
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Partially answering my own question (was Re: not quite understanding input methods),
Perry E. Metzger <=