From: Juri Linkov <juri@linkov.net>
To: 44266@debbugs.gnu.org
Subject: bug#44266: Transient input methods
Date: Tue, 27 Oct 2020 22:43:33 +0200 [thread overview]
Message-ID: <87o8knao7u.fsf_-_@mail.linkov.net> (raw)
[-- 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.
next reply other threads:[~2020-10-27 20:43 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-27 20:43 Juri Linkov [this message]
2020-10-28 11:40 ` bug#44266: Transient input methods 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
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=87o8knao7u.fsf_-_@mail.linkov.net \
--to=juri@linkov.net \
--cc=44266@debbugs.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).