I needed the attached patch to make anthy.el ((X)Emacs interface for
the Japanese input method "Anthy") work correctly when XEmacs is
started in a terminal ("xemacs -nw").
Without that patch, XEmacs would just beep when trying to delete the
last character in the preedit string with backspace.
The reason it beeped was that
(char-to-int (event-to-character event))
fails in case of backspace because (event-to-character event) is
nil in case of backspace. One can easily check that
(event-to-character (character-to-event 'backspace))
returns nil. This is different from most other characters. Please
have a look at these examples:
example:
(character-to-event 'a)
#<keypress-event a>
(event-to-character (character-to-event 'a))
?a
(character-to-event 'return)
#<keypress-event return>
(event-to-character (character-to-event 'return))
?\r
(character-to-event 'tab)
#<keypress-event tab>
(event-to-character (character-to-event 'tab))
?\t
I.e. these behave as expected. But 'backspace, 'left, 'right
and some others behave differently
(character-to-event 'backspace)
#<keypress-event backspace>
(event-to-character (character-to-event 'backspace))
nil
(character-to-event 'left)
#<keypress-event left>
(event-to-character (character-to-event 'left))
nil
(character-to-event 'right)
#<keypress-event right>
(event-to-character (character-to-event 'right))
nil
Just like non-existing characters
(character-to-event 'foo)
#<keypress-event foo>
(event-to-character (character-to-event 'foo))
nil
But the backspace event exists and I checked that
#<keypress-event backspace>
is indeed in last-command-event when I hit the backspace key.
So why does
(event-to-character (character-to-event 'backspace))
return nil?
Apparently somebody already tried to workaround this problem
in anthy.el with the 3 lines removed by my patch. But
this didn't work in a terminal because
(event-matches-key-specifier-p (character-to-event 'backspace) 'backspace)
returns nil when XEmacs in running in a terminal. It returns t when
XEmacs is running under X11. Why this difference?
(equal (character-to-event 'backspace) (character-to-event 'backspace))
returns t both in a terminal and under X11, therefore my patch helped.
But I still don't understand why.
--
Mike FABIAN <mfabian(a)suse.de>
http://www.suse.de/~mfabian
睡眠不足はいい仕事の敵だ。