From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Alex Hutcheson <alexhutcheson@google.com>
Cc: Eli Zaretskii <eliz@gnu.org>, 54027@debbugs.gnu.org
Subject: bug#54027: Wishlist: Support full CSI u specification for terminal input
Date: Sun, 27 Feb 2022 22:49:58 -0500 [thread overview]
Message-ID: <jwvee3nzops.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <CACjgaUdj-3rsp1o4tj=9oTBHkQHJe7X9a7DUCy4EaXu6PicUXg@mail.gmail.com> (Alex Hutcheson's message of "Sun, 27 Feb 2022 13:21:20 -0500")
Alex Hutcheson [2022-02-27 13:21:20] wrote:
>> I think just adding the missing combinations is a better way forward.
> I think we're in agreement here, I was just suggesting how to add
> the combinations to xterm.el without introducing a lot of boilerplate
> code.
Actually, for `ESC [ 27 ...` the better option is to bind `ESC [ 27` to
a function that reads the subsequent parameters so it will handle *all*
cases in one go, as in the barely tested patch below.
For `ESC [ ... u` it's a bit more tricky because it doesn't have such
a "clean" prefix (it's distinguished by the final `u` instead), so we'd
have to rework a lot of the rest of the `ESC [` bindings.
Maybe not a bad idea, tho.
Stefan
diff --git a/lisp/term/xterm.el b/lisp/term/xterm.el
index a7e257f41c5..9bf6a5750b1 100644
--- a/lisp/term/xterm.el
+++ b/lisp/term/xterm.el
@@ -192,6 +192,41 @@ xterm-rxvt-function-map
map)
"Keymap of escape sequences, shared between xterm and rxvt support.")
+(defun xterm--read-csi ()
+ ;; Format described in the "Control Sequence Introducer" section:
+ ;; https://en.wikipedia.org/wiki/ANSI_escape_code#CSIsection.
+ (let ((params '())
+ (intermediates '())
+ (final nil))
+ (setq final (read-char))
+ (while (<= #x30 final #x3F)
+ (push final params) ;And read more.
+ (setq final (read-char)))
+ (while (<= #x20 final #x2F)
+ (push final intermediates)
+ (setq final (read-char)))
+ (list (nreverse params) (nreverse intermediates) final)))
+
+(defun xterm--csi-27-modified-keys (&rest _)
+ (pcase-let* ((csi (xterm--read-csi))
+ (`(,params ,intermediates ,final) csi)
+ (tmp nil))
+ (cond
+ ((and (eq final ?~) (null intermediates)
+ (setq tmp (apply #'string params))
+ (string-match "\\([1-9][0-9]*\\);\\([0-9]+\\)" tmp))
+ (let ((modifiers (1- (string-to-number (match-string 1 tmp))))
+ (char (string-to-number (match-string 2 tmp))))
+ (vector
+ (+ char
+ (if (zerop (logand modifiers 1)) 0 ?\S-\0)
+ (if (zerop (logand modifiers 2)) 0 ?\A-\0)
+ (if (zerop (logand modifiers 4)) 0 ?\C-\0)
+ (if (zerop (logand modifiers 8)) 0 ?\M-\0)))))
+ (t
+ (message "Unknown CSI-27 sequence: %S" csi)
+ []))))
+
(defvar xterm-function-map
(let ((map (make-sparse-keymap)))
(set-keymap-parent map xterm-rxvt-function-map)
@@ -576,12 +611,12 @@ xterm-function-map
(6 9 [C-S-tab])
(6 13 [C-S-return])))
- (define-key map
- (format "\e[27;%d;%d~" (nth 0 bind) (nth 1 bind)) (nth 2 bind))
;; For formatOtherKeys=1, the sequence is a bit shorter (bug#13839).
(define-key map
(format "\e[%d;%du" (nth 1 bind) (nth 0 bind)) (nth 2 bind)))
+ (define-key map "\e[27;" #'xterm--csi-27-modified-keys)
+
;; Other versions of xterm might emit these.
(define-key map "\e[1~" [home])
next prev parent reply other threads:[~2022-02-28 3:49 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-16 18:24 bug#54027: Wishlist: Support full CSI u specification for terminal input Alex Hutcheson via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-17 23:14 ` Richard Stallman
2022-02-18 8:30 ` Eli Zaretskii
2022-02-23 1:07 ` Alex Hutcheson via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-26 8:10 ` Eli Zaretskii
2022-02-27 18:21 ` Alex Hutcheson via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-27 18:38 ` Eli Zaretskii
2022-02-27 18:53 ` Alex Hutcheson via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-27 19:16 ` Eli Zaretskii
2022-02-28 3:49 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2022-02-28 12:17 ` Eli Zaretskii
2022-02-28 13:22 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-28 13:31 ` Eli Zaretskii
2022-02-28 15:25 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-05-25 1:25 ` Alex Hutcheson via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-05-25 2:33 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
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=jwvee3nzops.fsf-monnier+emacs@gnu.org \
--to=bug-gnu-emacs@gnu.org \
--cc=54027@debbugs.gnu.org \
--cc=alexhutcheson@google.com \
--cc=eliz@gnu.org \
--cc=monnier@iro.umontreal.ca \
/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).