From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Additional cleanup around xterm-mouse Date: Sun, 27 Dec 2020 10:36:34 -0500 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14547"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: Eli Zaretskii , emacs-devel@gnu.org To: Jared Finder Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Dec 27 16:38:09 2020 Return-path: Envelope-to: ged-emacs-devel@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 1ktY7T-0003hH-W3 for ged-emacs-devel@m.gmane-mx.org; Sun, 27 Dec 2020 16:38:08 +0100 Original-Received: from localhost ([::1]:48810 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ktY7T-00086w-1b for ged-emacs-devel@m.gmane-mx.org; Sun, 27 Dec 2020 10:38:07 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34796) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ktY6H-0007ZL-Vk for emacs-devel@gnu.org; Sun, 27 Dec 2020 10:36:54 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:23800) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ktY66-0005T8-OP; Sun, 27 Dec 2020 10:36:52 -0500 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 483F810023D; Sun, 27 Dec 2020 10:36:37 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 90858100222; Sun, 27 Dec 2020 10:36:35 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1609083395; bh=P/2jEcqxmmVESNZGQnHXnn1OENRvCaFDrIw+FhlCFW0=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=RLErvH/XXO4/jC2h7V9dlKTWnO5bm8Kuo45QGGh51RQmzakjUPJOw5KebJI8KSq+z dENMEBETYV2Sbbl9mfvR/POa6uf8ksEwoPuCPwrtNMi6J34pV4SVosqAv/xx9INaOb 7w09DX83otvLHOWMx6t3Ck066UQsgDuwDAnPIokjrcvPXLI+OayscEV3D/ZluD74RF ixDrouoVq0jsvQhY6luEVBICnHiGJx7suNK+HEFKy0cNTWiQJHFz8+OOmZTrU3uAx0 vcZVyuk/wOEZ0OI/RBIGQgRr98XqPF/ryCCHPYknJX3z4lOuh56TY/aySf/4QicaZD aIG0O7X7G05Cw== Original-Received: from alfajor (unknown [104.247.243.191]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 53BDE120392; Sun, 27 Dec 2020 10:36:35 -0500 (EST) In-Reply-To: (Jared Finder's message of "Sat, 26 Dec 2020 15:49:19 -0800") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:261903 Archived-At: > -@defun read-key &optional prompt > +@defun read-key &optional prompt all-fallbacks-disabled FWIW, I would call it "fallbacks-disabled". > - (key (read-key-sequence "Set key globally: " nil t))) > + (key (read-key-sequence > + "Set key globally: " nil > + ;; FIXME: It'd be nicer if this was set to > + ;; 'all-fallbacks, however that would not apply the > + ;; transformations applied by local-function-key-map, > + ;; for example control modified function keys. > + ;; `widget-key-sequence-read-event' queries the user > + ;; which key they want in this case, perhaps do the > + ;; same here? > + 'downcase-last))) The name `all-fallbacks` makes it sound like it *enables* all fallbacks. Similarly `downcase-last` makes it sound like we'll downcase the last event. Not sure what would be best, but I'd suggest `dont-fallback` and `dont-downcase-last`. > - (catch 'read-key (read-key-sequence-vector prompt nil t))) > + (catch 'read-key > + (read-key-sequence-vector prompt nil > + (if all-fallbacks-disabled > + 'all-fallbacks > + 'downcase-last)))) BTW, just like above, it might be the case that many/most uses of `read-key` would actually prefer `dont-fallback`, so I think a FIXME should be added here saying we should review all uses of `read-key` to see if they would benefit from the use of the new argument. > @@ -3490,11 +3490,11 @@ 'key-sequence > (defun widget-key-sequence-read-event (ev) > (interactive (list > (let ((inhibit-quit t) quit-flag) > - (read-event "Insert KEY, EVENT, or CODE: ")))) > + (read-key "Insert KEY, EVENT, or CODE: " t)))) > (let ((ev2 (and (memq 'down (event-modifiers ev)) > - (read-event))) > - (tr (and (keymapp function-key-map) > - (lookup-key function-key-map (vector ev))))) > + (read-key nil t))) > + (tr (and (keymapp local-function-key-map) > + (lookup-key local-function-key-map (vector ev))))) > (when (and (integerp ev) > (or (and (<= ?0 ev) (< ev (+ ?0 (min 10 read-quoted-char-radix)))) > (and (<= ?a (downcase ev)) AFAICT this function doesn't make it possible to read double or triple clicks. Maybe it should be consolidated with `help--read-key-sequence`. > + * If a key sequence is unbound, we check Vfunction_key_map to see > + if some trailing subsequence might be the beginning of a function > + key's sequence. If so, we try to read the whole function key, and > + substitute its symbolic name into the key sequence. Nowadays this deserves some serious quotes around "function key" since function keys are normally handled in `input-decode-map` instead. > + * If a `down-' mouse click event is unbound, it is discarded. > + > + * If a `drag-' or `double-' event is unbound, it is turned into > + similar click events if that would make them bound. We try to turn > + `triple-' events first into `double-' events, then into clicks. > + > + * If a capital letter is unbound, it is turned into a lower case > + letter if that would make it bound. > + > + If FALLBACKS_DISABLED is Qnil, all of the above fallbacks are > + applied. If it is Qall_fallbacks, then none of the fallbacks are > + applied. If it is Qdowncase_last, the capital letter fallback is > + not applied, but all other ones are applied. Hmm... now that I think about it, I wonder if we need to make changes in `read_key_sequence` at all, because we can instead arrange for all keys to be bound: diff --git a/lisp/subr.el b/lisp/subr.el index 725722cbee..1ca1d51d44 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -2453,10 +2453,11 @@ memory-limit ;;;; Input and display facilities. (defconst read-key-empty-map (make-sparse-keymap)) - +(defconst read-key-full-map + (let ((map (make-sparse-keymap))) (define-key map [t] 'dummy) map)) (defvar read-key-delay 0.01) ;Fast enough for 100Hz repeat rate, hopefully. -(defun read-key (&optional prompt) +(defun read-key (&optional prompt dont-fallback) "Read a key from the keyboard. Contrary to `read-event' this will not return a raw event but instead will obey the input decoding and translations usually done by `read-key-sequence'. @@ -2468,7 +2469,8 @@ read-key ;; always inherits the input method, in practice read-key does not ;; inherit the input method (at least not if it's based on quail). (let ((overriding-terminal-local-map nil) - (overriding-local-map read-key-empty-map) + (overriding-local-map + (if dont-fallback read-key-full-map read-key-empty-map)) (echo-keystrokes 0) (old-global-map (current-global-map)) (timer (run-with-idle-timer WDYT? > diff --git a/src/lread.c b/src/lread.c > index 3ef874039a..74ed474944 100644 > --- a/src/lread.c > +++ b/src/lread.c > @@ -782,6 +782,12 @@ DEFUN ("read-char", Fread_char, Sread_char, 0, 3, 0, > > DEFUN ("read-event", Fread_event, Sread_event, 0, 3, 0, > doc: /* Read an event object from the input stream. > + > +If you want to read mouse events (for example, to discard an expected > +button up event inside a button down command), call `read-key' which > +can return events via `input-decode-map' such as all mouse events > +generated by `xterm-mouse-mode'. > + > If the optional argument PROMPT is non-nil, display that as a prompt. > If PROMPT is nil or the string \"\", the key sequence/events that led > to the current command is used as the prompt. I like that. I'd say "decode events via" instead of "return events via", tho. And I'd also mention function keys since the same applies if you want to read `f7` in a tty. Stefan