unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Jared Finder via "Emacs development discussions." <emacs-devel@gnu.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Eli Zaretskii <eliz@gnu.org>,
	"Jared Finder via \"Emacs development discussions.\""
	<emacs-devel@gnu.org>
Subject: Re: Additional cleanup around xterm-mouse
Date: Sun, 13 Dec 2020 16:54:26 -0800	[thread overview]
Message-ID: <505d1b561cde375d1c6a55a738cd553d@finder.org> (raw)
In-Reply-To: <106c6d31ef09b83042ef0fab5ac0ed88@finder.org>

Any updates here?

I do not know what the etiquette is here in terms of replies, so I'd 
like to apologize in advance if I'm just being impatient.

And FYI, I have five other patches around the xterm-mouse that I'd like 
to also submit but have been holding back to avoid creating too much 
noise.  These just address issues I've noticed locally when running with 
my changes.

Two of the changes are straightforward:

* Make command `help-for-help` use input-decode-map (for term function 
keys and xterm mouse) and allow mouse wheel scrolling.
* Clicking tab-line-mode's "+" pops up TTY menu or TMM based on 
tty-menu-open-use-tmm.

Three will likely merit some discussion:

* Make menus popped up on a down mouse event not trigger on the first up 
event unless the mouse has moved. (This is due to [mode-line mouse-1] 
being newly defined to `tty-menu-select` in `tty-menu-navigation-map` in 
0695c9e8.)
* Do not clear echo area when input-decode-map returns an empty vector 
(e.g. when the event is mouse movement but track-mouse is nil)
* Make menu-bar-at-x properly handle gud-gdb's "toolbar"-like menubar 
and undefined menu items.

Let me know how you'd ideally like me to share these.  My initial 
thought was to avoid dumping a bunch of changes all at once and share 
these sequentially.  Thanks.

   -- MJF

On 2020-12-03 9:31 am, Jared Finder wrote:
> On 2020-12-03 6:45 am, Stefan Monnier wrote:
>> Jared Finder [2020-12-02 21:46:53] wrote:
>> 
>>> On 2020-12-02 8:53 am, Stefan Monnier wrote:
>>>>> Subject: [PATCH] Make libraries work with xterm-mouse-mode.
>>>> Could you explain (at least in the code, and ideally here as well) 
>>>> why
>>>> we need this new `all-mouse-events` behavior?
>>> 
>>> I updated the function locally to look like as follows.  Let me know 
>>> if you
>>> have further questions.
>>> 
>>> (defun read-potential-mouse-event ()
>>>     "Read an event that might be a mouse event.
>>> 
>>> This function exists for backward compatibility in code packaged
>>> with Emacs.  Do not call it directly in your own packages."
>>>     ;; `xterm-mouse-mode' events must go through `read-key' as they
>>>     ;; are decoded via `input-decode-map'.
>>>     (if xterm-mouse-mode
>>>         (read-key nil
>>>                   ;; Normally `read-key' discards all mouse button
>>>                   ;; down events.  However, we want them here.
>>>                   t)
>>>       (read-event)))
>> 
>> That doesn't say what this function should do with non-mouse events, 
>> so
>> it makes it hard to decide what its behavior should be.
>> 
>> OK, so what you specifically need is for down events not to be
>> dropped, right?
> 
> I want no mouse event to get dropped (drag events also get dropped,
> right?) and no mouse events to get degraded to simpler forms.  In
> summary, I want mouse events to get returned unprocessed, as if from
> read-event, but with input-decode-map applied.
> 
> The alternative I presented further up in the thread was to apply
> input-decode-map manually to successive calls to read-event.  I got
> this working, though it sounded like modifying read-key was preferred
> earlier in this thread.
> 
> For context, here's the alternative:
> 
> (defun read-decoded-key ()
>   "Read a single key, as if by `read-key'.
> 
> Unlike `read-key', this does not call `read-key-sequence' and
> instead has a bare-bones implementation of its functionality.  In
> particular, it applies `input-decode-map' but does not apply
> `local-function-key-map' or `input-translation-map'."
>   (let* ((keys '())
>          (decoder input-decode-map)
>          (echo-keystrokes 0)
>          (timer (run-with-idle-timer
>                  read-key-delay t
>                  (lambda ()
>                    (unless (null keys)
>                      (throw 'read-decoded-key nil)))))
>          result)
>     (catch 'read-decoded-key
>       (unwind-protect
>           (while t
>             (let ((next-key (read-event)))
>               (push next-key keys)
>               (setq decoder (lookup-key decoder (vector next-key))))
>             (when (pcase decoder
>                     ;; A direct decoding (common for function keys)
>                     ((pred arrayp)
>                      (setq result decoder))
> 
>                     ;; A function that does decoding (like for
>                     ;; `xterm-mouse-mode')
>                     ((pred functionp)
>                      (setq result (funcall decoder nil))))
>               (if (zerop (length result))
>                   ;; The decoding is an empty vector to say "continue
>                   ;; reading".  This happens when the key would be
>                   ;; mouse-movement but `track-mouse' is nil.
>                   (setq keys '()
>                         decoder input-decode-map)
>                 (throw 'read-decoded-key nil))))
>         (cancel-timer timer)))
> 
>     ;; If no decoding, the accumulated keys are the result.
>     (or result (vconcat (nreverse keys)))))
> 
>>>> `function-key-map` has very similar effects (and to a large extent, 
>>>> the
>>>> downgrading of mouse-down events controlled by `all-mouse-events` 
>>>> could
>>>> (I'd even say should) be implemented in `function-key-map` rather 
>>>> than
>>>> via the current ad-hoc code in read-key-sequence), so I'm not very
>>>> comfortable with treating these mouse-event-rewritings differently 
>>>> from
>>>> other rewritings.
>>> Just a few comments:
>>> Wouldn't that require binding 2^6 * 3 * 3 * 5 = 2880 events in
>>> function-key-map?
>> 
>> Yes, but that's only because of the limited form available in keymaps.
>> To make it practical, we'd need to add "computed keymaps".  This is
>> a long-standing desire of mine, which would be useful in various
>> circumstances (and should make it possible to remove a lot of ad-hoc
>> rewritings in read_key_sequence).
> 
> Makes sense.  I think the easiest way to do this would be to allow
> keymaps to have multiple conditional fallbacks.  Perhaps allow a
> binding in a keymap to be a hook that runs via
> `run-hook-with-args-until-success'?  It's a slight generalization of
> the current logic which allows functions.
> 
> Technically this can be done now with just a layer of indirection on
> the [t] binding in a keymap.
> 
>>> And such behavior would want a special variable (as the code is 
>>> currently in
>>> my patch) to disable it to avoid copying all of function-key-map in
>>> read-key.  So I think it is fully independent of my current patch.
>> 
>> Yes.  My point is just that a functionally "don't discard 
>> mouse-events"
>> is weird in a function which is not specifically about mouse events.
>> It naturally leads to "don't down case events", "don't remap `tab` to
>> TAB", etc...
>> There has to be a more general underlying principle.
>> 
>> Maybe we could (re)use the DONT-DOWNCASE-LAST arg of 
>> `read-key-sequence`
>> for that?  This would mean no change in `read-key` but a change in
>> `read-key-sequence` instead (and hence further-reaching consequences).
>> 
>> Or maybe an option to `read-key` to disable all
>> function-key-map-like remappings (i.e. remappings which are only 
>> applied
>> if there's no binding for that key-sequence)?
> 
> One way to do this would be to add new behavior if DONT-DOWNCASE-LAST
> is a list.  In other words, if DONT-DOWNCASE-LAST is non-nil and not a
> list, existing behavior.  But if DONT-DOWNCASE-LAST is a list, we can
> look at the members of the list to determine what to do.  This is a
> slight change in existing behavior, but it is very unlikely to break
> anything.
> 
>   -- MJF



  reply	other threads:[~2020-12-14  0:54 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-16  6:29 Additional cleanup around xterm-mouse Jared Finder via Emacs development discussions.
2020-11-16 17:30 ` Jared Finder via Emacs development discussions.
2020-11-18 17:40 ` Eli Zaretskii
2020-11-19  8:03   ` Jared Finder via Emacs development discussions.
2020-11-21  9:31     ` Eli Zaretskii
2020-11-22 23:56       ` Jared Finder via Emacs development discussions.
2020-11-28 16:36         ` Eli Zaretskii
2020-12-01  7:36           ` Jared Finder via Emacs development discussions.
2020-12-01 15:21             ` Stefan Monnier
2020-12-01 18:23             ` Eli Zaretskii
2020-12-02  6:45               ` Jared Finder via Emacs development discussions.
2020-12-02 16:53                 ` Stefan Monnier
2020-12-03  5:46                   ` Jared Finder via Emacs development discussions.
2020-12-03 14:45                     ` Stefan Monnier
2020-12-03 17:31                       ` Jared Finder via Emacs development discussions.
2020-12-14  0:54                         ` Jared Finder via Emacs development discussions. [this message]
2020-12-14 15:32                           ` Eli Zaretskii
2020-12-16  5:30                             ` Jared Finder via Emacs development discussions.
2020-12-19 18:32                               ` Eli Zaretskii
2020-12-19 22:50                                 ` Stefan Monnier
2020-12-20  7:26                                   ` Jared Finder via Emacs development discussions.
2020-12-20 14:07                                     ` Stefan Monnier
2020-12-20 23:27                                       ` Jared Finder via Emacs development discussions.
2020-12-23 16:52                                         ` Eli Zaretskii
2020-12-23 17:21                                           ` Jared Finder via Emacs development discussions.
2020-12-24 18:43                                             ` Eli Zaretskii
2020-12-14  0:36               ` Jared Finder via Emacs development discussions.
2020-11-21 17:00     ` Stefan Monnier
2020-11-21  8:23   ` Eli Zaretskii
  -- strict thread matches above, loose matches on Subject: below --
2020-12-26 23:49 Jared Finder via Emacs development discussions.
2020-12-27 15:36 ` Stefan Monnier
2020-12-27 16:30   ` Jared Finder via Emacs development discussions.
2020-12-27 17:10     ` Stefan Monnier
2020-12-28  0:22       ` Jared Finder via Emacs development discussions.
2021-01-02  8:17 ` Eli Zaretskii
2021-01-02 22:20   ` Jared Finder via Emacs development discussions.
2021-01-09 12:27     ` Eli Zaretskii
2021-01-09 23:01       ` Jared Finder via Emacs development discussions.
2021-01-15 11:54         ` Eli Zaretskii
2020-11-15  8:49 Jared Finder via Emacs development discussions.
2020-11-15 18:11 ` Eli Zaretskii

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=505d1b561cde375d1c6a55a738cd553d@finder.org \
    --to=emacs-devel@gnu.org \
    --cc=eliz@gnu.org \
    --cc=jared@finder.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).