From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#54027: Wishlist: Support full CSI u specification for terminal input Date: Sun, 27 Feb 2022 22:49:58 -0500 Message-ID: References: <8335kg1srp.fsf@gnu.org> <83mtieoxpj.fsf@gnu.org> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39349"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: Eli Zaretskii , 54027@debbugs.gnu.org To: Alex Hutcheson Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Feb 28 04:51:12 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nOX42-0009zu-CG for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 28 Feb 2022 04:51:10 +0100 Original-Received: from localhost ([::1]:53162 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nOX40-0001zw-R1 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 27 Feb 2022 22:51:08 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:47490) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nOX3u-0001zV-Az for bug-gnu-emacs@gnu.org; Sun, 27 Feb 2022 22:51:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:37629) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nOX3u-0006ZS-2U for bug-gnu-emacs@gnu.org; Sun, 27 Feb 2022 22:51:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nOX3t-0000Zu-U6 for bug-gnu-emacs@gnu.org; Sun, 27 Feb 2022 22:51:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 28 Feb 2022 03:51:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 54027 X-GNU-PR-Package: emacs Original-Received: via spool by 54027-submit@debbugs.gnu.org id=B54027.16460202182172 (code B ref 54027); Mon, 28 Feb 2022 03:51:01 +0000 Original-Received: (at 54027) by debbugs.gnu.org; 28 Feb 2022 03:50:18 +0000 Original-Received: from localhost ([127.0.0.1]:59759 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nOX3C-0000Yy-9I for submit@debbugs.gnu.org; Sun, 27 Feb 2022 22:50:18 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:16791) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nOX3A-0000Yh-4B for 54027@debbugs.gnu.org; Sun, 27 Feb 2022 22:50:16 -0500 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 2CE89805B4; Sun, 27 Feb 2022 22:50:10 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 783088001A; Sun, 27 Feb 2022 22:50:08 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1646020208; bh=PvVOaNbL3oAgJ1NK7OwMdpwIZ1w2yoiMxAhMDI+cHsk=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=Bdpq9MQ7bDBDN2cfWqWPlTRzcDlWer/PkCfzNfWB2x7bi84VQG7Fsl4GLT1jvsTG2 RcYKRhxfepIsg15VDEx8LdKYhAz4tx30uKW13HMFy0fUsNvusQkC9gnuJHwbgA7++F 2hOQmd5l9o4om44yAqrqQNh1TNrnm7/mVcqRsD3qUYuCQeiEoJSho4XCEj3cVUEG/w kdO5l1hkKmz8FPyvU3QnFKNx8wYZw1K78pJRZ9QTIeVsqzkdmIDkhQJJr6YL7/GBC6 DxzFn3kDdsIL+U6PrW4bTxEs180wVsjf+VwnaI9KY3RKzgvQqw6o8ofP5Q7J3hmh7x jO3b1DAnDTrQQ== Original-Received: from pastel (unknown [45.72.208.76]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 348D3120EB1; Sun, 27 Feb 2022 22:50:08 -0500 (EST) In-Reply-To: (Alex Hutcheson's message of "Sun, 27 Feb 2022 13:21:20 -0500") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:227755 Archived-At: 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])