unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#44266: Transient input methods
@ 2020-10-27 20:43 Juri Linkov
  2020-10-28 11:40 ` Lars Ingebrigtsen
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Juri Linkov @ 2020-10-27 20:43 UTC (permalink / raw)
  To: 44266

[-- Attachment #1: Type: text/plain, Size: 1439 bytes --]

Tags: patch

[Creating a separate feature request from bug#43866]

>> How about making a new input method for those?  It seems to me that
>> C-x 8 is already too "fat".
>
> That may be useful, but it has a drawback compared with C-x 8.
>
> It is inconvenient to change input methods just for one character and
> then change back.

The following patch addresses such issues of the current input method
implementation by providing a new feature of transient input methods.

A transient input method is enabled temporarily for entering a key sequence,
and is disabled automatically afterwards.

The command that temporarily activates an one-off transient input method
is bound to the mnemonic key 'C-x \'.  A prefix key is used to select
the default transient input method, e.g.:

C-u C-x \ compose RET   - selects the 'compose' input method
                          as the default transient input method;
C-x \ E =   - activates the default transient input method,
              inserts the EURO SIGN character,
              and disables the transient input method;
C-x \ ^ 3   - inserts the character SUPERSCRIPT THREE.

The same with the help of the 'TeX' input method:

C-u C-x \ TeX RET
C-x \ \ e u r o   - inserts the character EURO SIGN

Also it's possible to create a new input method from the existing
'C-x 8' keymap, and set it as the default method, e.g.:

C-u C-x \ iso-transl RET
C-x \ * E   - inserts the character EURO SIGN


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: transient-input-method.patch --]
[-- Type: text/x-diff, Size: 2724 bytes --]

diff --git a/lisp/international/mule-cmds.el b/lisp/international/mule-cmds.el
index e3155dfc52..c5a0145163 100644
--- a/lisp/international/mule-cmds.el
+++ b/lisp/international/mule-cmds.el
@@ -55,6 +55,7 @@ mule-keymap
 
 ;; Keep "C-x C-m ..." for mule specific commands.
 (define-key ctl-x-map "\C-m" mule-keymap)
+(define-key ctl-x-map "\\" 'transient-input-method)
 
 (defvar describe-language-environment-map
   (let ((map (make-sparse-keymap "Describe Language Environment")))
@@ -1344,6 +1345,16 @@ default-input-method
                  mule-input-method-string)
   :set-after '(current-language-environment))
 
+(defcustom transient-input-method nil
+  "Default transient input method.
+This is the input method activated automatically by the command
+`transient-input-method' (\\[transient-input-method])."
+  :link  '(custom-manual "(emacs)Input Methods")
+  :group 'mule
+  :type '(choice (const nil)
+                 mule-input-method-string)
+  :set-after '(current-language-environment))
+
 (put 'input-method-function 'permanent-local t)
 
 (defvar input-method-history nil
@@ -1519,6 +1530,35 @@ set-input-method
 (defvar toggle-input-method-active nil
   "Non-nil inside `toggle-input-method'.")
 
+(defun transient-input-method (&optional arg interactive)
+  "Enable transient input method for the current buffer."
+  (interactive "P\np")
+  (when (or arg (not transient-input-method))
+    (let* ((default (or (car input-method-history) default-input-method))
+           (input-method
+            (read-input-method-name
+             (if default "Transient input method (default %s): " "Transient input method: ")
+             default t)))
+      (setq transient-input-method input-method)
+      (when interactive
+        (customize-mark-as-set 'transient-input-method))))
+  (let* ((previous-input-method current-input-method)
+         (history input-method-history)
+         (clearfun (make-symbol "clear-transient-input-method"))
+         (exitfun
+          (lambda ()
+            (deactivate-input-method)
+            (when previous-input-method
+              (activate-input-method previous-input-method))
+            (setq input-method-history history)
+            (remove-hook 'input-method-after-insert-chunk-hook clearfun))))
+    (fset clearfun (lambda () (funcall exitfun)))
+    (add-hook 'input-method-after-insert-chunk-hook clearfun)
+    (when previous-input-method
+      (deactivate-input-method))
+    (activate-input-method transient-input-method)
+    exitfun))
+
 (defun toggle-input-method (&optional arg interactive)
   "Enable or disable multilingual text input method for the current buffer.
 Only one input method can be enabled at any time in a given buffer.

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-11-06  8:33 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-27 20:43 bug#44266: Transient input methods Juri Linkov
2020-10-28 11:40 ` Lars Ingebrigtsen
2020-10-29  4:48 ` Richard Stallman
2020-11-01 21:36   ` Juri Linkov
2020-11-05 20:14     ` Juri Linkov
2020-11-06  8:33       ` Juri Linkov
2020-11-01 14:37 ` Lars Ingebrigtsen
2020-11-01 18:24   ` Juri Linkov
2020-11-02  5:41   ` Richard Stallman

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).