emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Android input methods


From: Po Lu
Subject: Re: Android input methods
Date: Mon, 13 Feb 2023 10:21:24 +0800
User-agent: Gnus/5.13 (Gnus v5.13)

Eli Zaretskii <eliz@gnu.org> writes:

> Maybe I'm missing something, but where's the problem in this?  We have
> all this implemented in insdel.c, and a command can tell Emacs to
> insert, delete, or replace text.  IOW, so far you describe the
> communications between Emacs and the input method as a stream of
> insert/delete/replace commands, for which we already have all the
> infrastructure, and the only thing that's missing is the low-level
> communication protocol with the input method, which should issue those
> commands.

My problem is that modes such as `electric-indent-mode' expect, for
example, newline characters to be inserted by the return key, and do not
indent if the change is made directly by the input method.

So at least until the other major modes are adjusted to work with these
input methods, there will need to be complicated conversion between
input method editing commands and the key events which will normally
perform the same thing.

>> If Emacs makes a change to the buffer outside the area in which the
>> input method expresses interest, then it is obligated to ``restart'' the
>> input method.  This takes a significant amount of time to complete.
>
> What does Emacs have to do to "restart" an input method? what does
> this mean in practice?

In practice, this means the input method will hide and reshow its
editing window.

> And how much time is "a significant amount of time" in this case?

Up to a second.

>> Sometimes, the input method will also tell Emacs to mark a portion of
>> the buffer as ``preconversion text'' (or a ``composing span''), which is
>> an ephemeral region which may be replaced by the input method by some
>> other text, or deleted altogether.
>
> Again, I see no problems with this: markers will handle such a region.
>
>> at that point, the input method asks for the contents of the buffer
>> before point again, and repeats the whole process.
>
> What does "asks for the contents of the buffer" mean in practice? what
> does the input method tell Emacs, and what does it expect from Emacs
> in response? if it expects us to send it the text it requested, then
> how (by which medium and protocol) is that text sent by Emacs to the
> input method?

When this happens, the input method specifies an offset around the caret
or absolute buffer positions, and calls a callback.  Emacs is then
supposed to reply by returning the text from that callback.

>> All of this is behavior I have observed CJK and English input methods
>> perform.  An input method is not obligated to behave in any way like
>> what I have described above, as long as it constrains its edits to some
>> reasonable position (600 characters) around the caret; if it makes edits
>> any further away from the caret than that, the behavior of the
>> application is undefined.
>
> "Undefined" meaning that input methods will not usually do this?  Or
> what does it mean?

It means that input methods are not allowed to do this, so applications
don't have to allow it to happen.

> How can the input method know that the replacement is reflected in the
> Emacs buffer?

It will either query for the buffer contents after some time, or monitor
for the change.

>> Sometimes, an input method will also monitor changes to the caret
>> position.  At this point, Emacs is obligated to report any changes to
>> the on screen caret to the input method, so it knows where it should
>> begin to make edits from.
>
> Again no problem for us: "we have the technology", in the form of
> buffer-modification hooks.
>
>> An input method might also ask for a region of text to be ``extracted'',
>> which means Emacs must report each change to the buffer that modifies
>> said region to the input method
>
> Same.
>
>> In any case, the conclusion is that Emacs must present a completely
>> correct view of the buffer contents of the selected window and the
>> location of its point to the input method, correctly report edits made
>> by the input method to the buffer contents and any edits made by Emacs
>> after that, and dilligently report changes to extracted text and/or
>> reset the input method on ``major changes'' such as the selected buffer
>> or window changing, or edits happening outside extracted text.
>
> And the problem with doing what the input method expects is...?

That most of Emacs expects character input events, and not for text to
be changed underneath its nose.  So, Emacs will have to implement (at
least optional) translation between these complex editing commands and
simple character input events.

> You mean, if I select, say, a Cyrillic keyboard and start typing, what
> Emacs will see is the above complex insert/delete/replace commands
> instead of a series of single Cyrillic characters?  And this only
> happens with non-ASCII characters, but not with ASCII?

Yes, that's what will happen right now.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]