unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Perry E. Metzger" <perry@piermont.com>
To: emacs-devel@gnu.org
Subject: Partially answering my own question (was Re: not quite understanding input methods)
Date: Wed, 1 Sep 2021 09:29:47 -0400	[thread overview]
Message-ID: <4a9f5f62-a897-32dd-a2c9-0fce95bc89c3@piermont.com> (raw)
In-Reply-To: <231adc63-77f0-037a-365c-28db98f684cf@piermont.com>

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





      parent reply	other threads:[~2021-09-01 13:29 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-30 17:24 not quite understanding input methods Perry E. Metzger
2021-08-30 17:37 ` Stefan Monnier
2021-08-30 17:45   ` Perry E. Metzger
2021-08-30 18:00     ` Stefan Monnier
2021-08-30 18:22       ` Eli Zaretskii
2021-08-30 18:34         ` Perry E. Metzger
2021-08-30 18:39           ` Eli Zaretskii
2021-08-30 18:43             ` Perry E. Metzger
2021-08-30 18:37       ` Perry E. Metzger
2021-08-30 19:00         ` Perry E. Metzger
2021-08-30 19:08           ` Eli Zaretskii
2021-08-30 19:13             ` Perry E. Metzger
2021-08-30 19:19               ` Stefan Monnier
2021-08-30 19:26                 ` Perry E. Metzger
2021-08-30 19:31                   ` Eli Zaretskii
2021-08-30 20:12                     ` Stefan Monnier
2021-08-30 19:28               ` Eli Zaretskii
2021-08-30 20:29               ` André A. Gomes
2021-09-01  5:44 ` Yuri Khan
2021-09-01  7:23   ` Juri Linkov
2021-09-01  7:43     ` Yuri Khan
2021-09-01  8:37       ` tomas
2021-09-01  9:14       ` Joost Kremers
2021-09-01 13:17         ` Perry E. Metzger
2021-09-01 12:05       ` Eli Zaretskii
2021-09-01 12:35         ` João Távora
2021-09-01 13:19           ` André A. Gomes
2021-09-01 14:05             ` João Távora
2021-09-01 13:03         ` André A. Gomes
2021-09-01 13:02       ` Perry E. Metzger
2021-09-02 12:00       ` Maxim Nikulin
2021-09-02 13:03       ` Filipp Gunbin
2021-09-01 12:58     ` Perry E. Metzger
2021-09-01 12:51   ` Perry E. Metzger
2021-09-01 13:29 ` Perry E. Metzger [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4a9f5f62-a897-32dd-a2c9-0fce95bc89c3@piermont.com \
    --to=perry@piermont.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).