summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrédéric Mangano <fmang@mg0.fr>2022-08-03 18:04:54 +0900
committerfujiwarat <takao.fujiwara1@gmail.com>2022-08-03 18:04:54 +0900
commit934e3019b1f1e1bd7914d33064c0155e6700f8ba (patch)
treed767a5b8891afe20eebd28c4e1676c5155b6a63d
parent3769df3e8d4eefabcb88b521f3c9e2658fc233ca (diff)
downloadibus-anthy-934e3019b1f1e1bd7914d33064c0155e6700f8ba.tar.gz
Add the escape_to_latin command as a vi-cooperative cancel (#29)
When writing Japanese in Vim, everytime I switch from Insert mode back to Normal mode, I need to also switch back the IBus input mode to Latin or else Vim won’t take any of my input. This is kind fo annoying as key sequences like `<Esc>:w` easily get wired into muscle memory. For comparison, uim has got a vi-cooperative mode for that use case. See <https://blog.myon.info/entry/2014/04/14/entry/> for illustration. Here’s a new command which, when converting, behaves like cancel, but otherwise switches to Latin and sends the Escape key. To make IBus vi-cooperative, a user can map the Escape key to escape_to_latin instead of cancel.
-rw-r--r--engine/python2/engine.py14
-rw-r--r--engine/python3/engine.py14
-rw-r--r--setup/python2/anthyprefs.py1
-rw-r--r--setup/python3/anthyprefs.py1
4 files changed, 30 insertions, 0 deletions
diff --git a/engine/python2/engine.py b/engine/python2/engine.py
index d97314a..218b485 100644
--- a/engine/python2/engine.py
+++ b/engine/python2/engine.py
@@ -2333,6 +2333,20 @@ class Engine(IBus.EngineSimple):
self.__invalidate()
return True
+ def __cmd_escape_to_latin(self, keyval, state):
+ """
+ Vi-cooperative variant of cancel_all. When Vi users press Escape, they
+ expect to return to Normal mode where an IME would not make sense. This
+ command automatically switches back to Latin when sending Escape. When
+ converting, Escape will cancel the conversion instead.
+ """
+ if self._chk_mode('0'):
+ if Engine.__input_mode != INPUT_MODE_LATIN:
+ self.__cmd_latin_mode(keyval, state)
+ return False
+ else:
+ return self.__cmd_cancel_all(keyval, state)
+
def __cmd_reconvert(self, keyval, state):
if not self.__preedit_ja_string.is_empty():
# if user has inputed some chars
diff --git a/engine/python3/engine.py b/engine/python3/engine.py
index 34b7f9f..abb9c02 100644
--- a/engine/python3/engine.py
+++ b/engine/python3/engine.py
@@ -2327,6 +2327,20 @@ class Engine(IBus.EngineSimple):
self.__invalidate()
return True
+ def __cmd_escape_to_latin(self, keyval, state):
+ """
+ Vi-cooperative variant of cancel_all. When Vi users press Escape, they
+ expect to return to Normal mode where an IME would not make sense. This
+ command automatically switches back to Latin when sending Escape. When
+ converting, Escape will cancel the conversion instead.
+ """
+ if self._chk_mode('0'):
+ if Engine.__input_mode != INPUT_MODE_LATIN:
+ self.__cmd_latin_mode(keyval, state)
+ return False
+ else:
+ return self.__cmd_cancel_all(keyval, state)
+
def __cmd_reconvert(self, keyval, state):
if not self.__preedit_ja_string.is_empty():
# if user has inputed some chars
diff --git a/setup/python2/anthyprefs.py b/setup/python2/anthyprefs.py
index 5e3bade..c614491 100644
--- a/setup/python2/anthyprefs.py
+++ b/setup/python2/anthyprefs.py
@@ -276,6 +276,7 @@ _cmd_keys = [
'predict',
'cancel',
'cancel_all',
+ 'escape_to_latin',
'reconvert',
# 'do_nothing',
diff --git a/setup/python3/anthyprefs.py b/setup/python3/anthyprefs.py
index 33b2a31..404aa09 100644
--- a/setup/python3/anthyprefs.py
+++ b/setup/python3/anthyprefs.py
@@ -269,6 +269,7 @@ _cmd_keys = [
'predict',
'cancel',
'cancel_all',
+ 'escape_to_latin',
'reconvert',
# 'do_nothing',