[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/subed f5d8ebf28d 1/6: Fix "I"/"O" insertion on focus event
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/subed f5d8ebf28d 1/6: Fix "I"/"O" insertion on focus events when Emacs runs in terminal |
Date: |
Fri, 5 Jul 2024 10:00:55 -0400 (EDT) |
branch: elpa/subed
commit f5d8ebf28d5e96c959189a16d44d6b67cda07b68
Author: Random User <rndusr@posteo.de>
Commit: Random User <rndusr@posteo.de>
Fix "I"/"O" insertion on focus events when Emacs runs in terminal
If Emacs runs in a terminal emulator, the characters "I"/"O" are inserted
in the
buffer every time the terminal window is focused/unfocused.
Emacs tells the terminal emulator to send focus in/out events, and they are
sent
as "\e[I" (focus in) and "\e[O" (focus out). "\e" is the escape character.
Alt/Meta combinations are sent as "\eC" where "C" is the key pressed
together
with Alt. For example, if you press `M-x`, the terminal emulator sends an
escape
character and "x".
And if you press `M-[`, "\e[" is sent which is indistinguishable from the
beginning of the "\e[I" or "\e[O" event. For some reason I don't know, Emacs
doesn't bother peeking at the next character. It sees "\e[", sees that this
character sequence is bound and acts on it. Then it sees "I" or "O", which
are
just letters, so they are inserted as if you pressed those keys.
Further reading:
https://emacs.stackexchange.com/questions/1020/problems-with-keybindings-when-using-terminal/13957#13957
This should be fixable in Emacs itself, but I have no idea exactly how, and
the
fact that such an annoying bug hasn't been fixed yet tells me it's actually
not
that easy.
This PR simply doesn't map `M-[` if Emacs is running in a terminal emulator
and
uses `C-M-[` instead.
---
README.org | 7 ++++---
subed/subed.el | 14 ++++++++++++--
2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/README.org b/README.org
index 28525cecf2..dc0ab1fa8b 100644
--- a/README.org
+++ b/README.org
@@ -34,9 +34,10 @@ formats are:
many subtitles to insert and whether they are inserted before or after the
current subtitle.
- Kill subtitles (~M-k~).
-- Adjust subtitle start (~M-[~ / ~M-]~) and stop (~M-{~ / ~M-}~) time. A
- prefix argument sets the number of milliseconds for the current session
- (e.g. ~C-u 1000 M-[ M-[ M-[~ decreases start time by 3 seconds).
+- Adjust subtitle start (~M-[~ / ~M-]~ or ~C-M-[~ / ~C-M-]~ if Emacs lives in a
+ terminal) and stop (~M-{~ / ~M-}~) time. A prefix argument sets the number
of
+ milliseconds for the current session (e.g. ~C-u 1000 M-[ M-[ M-[~ decreases
+ start time by 3 seconds).
- Move the current subtitle or all marked subtitles
(~subed-move-subtitles~) forward (~C-M-n~) or backward (~C-M-p~) in
time without changing subtitle duration. A prefix argument sets the
diff --git a/subed/subed.el b/subed/subed.el
index b4b1d8b81c..11c83a54ff 100644
--- a/subed/subed.el
+++ b/subed/subed.el
@@ -52,8 +52,18 @@
(define-key subed-mode-map (kbd "M-p") #'subed-backward-subtitle-text)
(define-key subed-mode-map (kbd "C-M-a") #'subed-jump-to-subtitle-text)
(define-key subed-mode-map (kbd "C-M-e") #'subed-jump-to-subtitle-end)
- (define-key subed-mode-map (kbd "M-[") #'subed-decrease-start-time)
- (define-key subed-mode-map (kbd "M-]") #'subed-increase-start-time)
+ ;; Binding M-[ when Emacs runs in a terminal emulator inserts "O" and "I"
+ ;; every time the terminal window looses/gains focus.
+ ;; https://emacs.stackexchange.com/questions/48738
+ ;;
https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-FocusIn_FocusOut
+ ;;
https://www.gnu.org/software/emacs/manual/html_node/elisp/Input-Focus.html
+ (if (display-graphic-p)
+ (progn
+ (define-key subed-mode-map (kbd "M-[") #'subed-decrease-start-time)
+ (define-key subed-mode-map (kbd "M-]") #'subed-increase-start-time))
+ (progn
+ (define-key subed-mode-map (kbd "C-M-[") #'subed-decrease-start-time)
+ (define-key subed-mode-map (kbd "C-M-]") #'subed-increase-start-time)))
(define-key subed-mode-map (kbd "M-{") #'subed-decrease-stop-time)
(define-key subed-mode-map (kbd "M-}") #'subed-increase-stop-time)
(define-key subed-mode-map (kbd "C-M-n") #'subed-move-subtitle-forward)
- [nongnu] elpa/subed updated (07567d51ff -> 997b1fa7b8), ELPA Syncer, 2024/07/05
- [nongnu] elpa/subed f5d8ebf28d 1/6: Fix "I"/"O" insertion on focus events when Emacs runs in terminal,
ELPA Syncer <=
- [nongnu] elpa/subed 74ed6240e2 2/6: Add support for "mov" file extension (fix #67), ELPA Syncer, 2024/07/05
- [nongnu] elpa/subed 80a5d27185 4/6: Merge pull request #72 from rndusr/fix/terminal-focus-events, ELPA Syncer, 2024/07/05
- [nongnu] elpa/subed d1e375213d 3/6: Merge pull request #73 from rndusr/mov-file-extension, ELPA Syncer, 2024/07/05
- [nongnu] elpa/subed 110e4bdfe1 5/6: 1.2.12 bugfix for SRT numeric cue text, ELPA Syncer, 2024/07/05
- [nongnu] elpa/subed 997b1fa7b8 6/6: 1.2.13 bugfix: Fix requirements for subed-waveform, ELPA Syncer, 2024/07/05