unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Psionic K <psionik@positron.solutions>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Ihor Radchenko <yantar92@posteo.net>,
	Emacs developers <emacs-devel@gnu.org>
Subject: Re: Delegating user-reserved key binding space definition to users
Date: Mon, 28 Nov 2022 20:38:47 -0600	[thread overview]
Message-ID: <CADQMGATy4j_uPg9MBDLWRJNYk4wqn8Mw349pqsgJZeEp7h+c+A@mail.gmail.com> (raw)
In-Reply-To: <jwvfse3t13v.fsf-monnier+emacs@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 7547 bytes --]

> a solution should allow packages to declare that command FOO
> should be bound to some key based on SOME-INFO, such that it will be
> bound to one key in "normal Emacs mode", and to another in `evil-mode`
> and to yet another in `god-mode`, etc...

SOME-INFO will be of the form:
((concept command) (concept command) ...)) ; package provide
((concept (concept concept concept)) (concept concept)) ; overload
remappings, perhaps user or package provided or both
((concept binding) (concept binding)) ; user or emulation mode etc provided

The overloads might be embedded in the first and second lists, but it will
make for complicated reading later.

Either a built-in implementation in Emacs or customized implementations in
packages should consume the full SOME-INFO and generate keymaps.  If that
keymap generation is dynamic or the keymap itself embeds indirection for
contextual operations, we get essentially dynamic dispatch, and there's not
much need for new implementations.  emulation-mode-map-alists has its
structure for good reason.

In the beginning, before packages provide their half, the user will provide
it, likely through a package.  This is analogous to evil collection.

There likely will not be enough concepts to support relocating every key
this way.  While the default implementation that ships with Emacs can
attempt to rearrange keys usings current behavior and a heuristic where
that is not possible, if the user configures a different implementation,
even one that ignores the mode's SOME-INFO in part or whole, commands will
be unbound.  This is good.  We have to support the notion that the provided
commands are bad and that the users wants to write better ones or else we
are choking the evolution of the interaction models.  Package authors
should focus on good functions and editing data models.  This is what makes
it easy to write good commands.  Attempting to write all the good commands
is not possible without lots of user representation, which package authors
cannot individually have.

> To me a solution should allow packages to declare that command FOO
> should be bound to some key based on SOME-INFO, such that it will be
> bound to one key in "normal Emacs mode", and to another in `evil-mode`
> and to yet another in `god-mode`, etc...

This places too much emphasis on package authors.  They should only provide
the ((concept command)) information.  Package authors and users have to
meet in the middle, and remember to put the users first in that
discussion.  As stated above, I believe it's the job of modal systems to
decide how to consume the package-defined half of SOME-INFO.

> Agreed.  But it should apply to all bindings.

The concepts that can be good targets in SOME-INFO should arise only very
naturally.  This means there will be way too few concepts to handle the
current state of keymaps.  IMO this is because package authors feel
entitled to users' keyboards or obligated to shadow all of the random
commands bound in the default global map.  The implementations should make
it easier for bad commands / bindings to die.

Lots of Emacs applications handle lists of options because lists are simply
ubiquitous, and so navigating lists is naturally a common concept.  M-x is
the gateway to commands, and Emacs without such a gateway is degenerate, so
we need that as a concept.  Aborting a command that is asking for input or
blocking on network is a concept.  Let's get these figured out and make
them easily remappable before worrying about esoteric commands that the
user might want to redefine anyway.

On Mon, Nov 28, 2022 at 12:15 PM Stefan Monnier <monnier@iro.umontreal.ca>
wrote:

> >>> I suggest introducing a notion of "generalized" commands. Such commands
> >>> will represent common actions executed by users (like move to
> >>> next/previous element). Major and minor modes can then define specific
> >>> implementation of the actions.
> >>
> >> I think it's a non-starter because it requires foresight: only those
> >> commands defined with this mechanism will be extensible.  I agree that
> >> an additional level of indirection is probably necessary, but I suspect
> >> it needs to be placed elsewhere.
> >
> > Auto-remapping will need some kind of grouping for commands one way or
> > another. There is no way we can do it auto-magically. Developer or users
> > should decide.
>
> Agreed.  But it should apply to all bindings.
>
> > Currently, the commands in major mods are bound to specific key
> > bindings. The bindings are chosen either arbitrarily, according to major
> > mode author preferences, or according to semi-established default key
> > binding scheme (like C-f/C-M-f/C-n/C-v/etc). Either way, trying to
> > re-bind commands in multiple major modes is not easy.
>
> Yup.  I fully agree that it's a real problem.
>
> I'd welcome a solution to it.  Even an "unrealistic" one would be good.
> Currently, I don't even know what a good solution could look like.
>
> To me a solution should allow packages to declare that command FOO
> should be bound to some key based on SOME-INFO, such that it will be
> bound to one key in "normal Emacs mode", and to another in `evil-mode`
> and to yet another in `god-mode`, etc...
>
> Some SOME-INFO needs to provide not a specific key, but some information
> from which we can compute the "natural key" that fits the keybinding
> style that the user selected.
>
> Then there are also the issues of overloading several operations on
> a single key (like TAB).  So far we've solved this along the lines you
> suggest (a "generalized command", such as `indent-for-tab-command`), and
> maybe that's good enough for this, tho it prevents changing this
> overloading according to the keybinding style.
>
> [ BTW, another way to look at it is not "how can we compute which key to
>   bind FOO to" but rather "how can we compute which command to run when
>   KEY is hit".  IOW, we could make keymaps more dynamic such that when
>   you hit KEY, Emacs passes that to a "procedural keymap" which will
>   *compute* (rather than lookup) which command to run, according to the
>   current keybinding style.
>   Not sure it would be better: I just mention it as one of the many
>   things that we may want to consider in order to find a good solution
>   to the problem.  ]
>
> >> [ FWIW, you can get similar results with the current setup using
> >>   command remapping.  ]
> > You are absolutely right: when a major mode command is related to
> > built-in command in command map.
>
> Just to be clear: I don't think command remapping solves the problem
> at hand.  It can sometimes be used for that, but not in general.
>
> > However, some major modes introduce new concepts.  For example, think
> > about paredit-forward-slurp-sexp, which can be an equivalent of Org's
> > heading promotion or moving word at point forward in sentences.  How
> > could you remap to group these 3 very different yet similar (for some
> > users) commands together?
>
> Great example, indeed, thanks.
>
> In this context, I'd like the package to be able to explain that this
> command is about a "sexp"-granularity operation and about
> "forward"-direction operation, so that the keybinding style may
> automatically find a natural/consistent key (or set of keys) to use for
> it depending on whether the current keybinding style uses f/b, or j/k,
> or left/right, or ... for forward/backward operations.
>
>
>         Stefan
>
>

-- 

Psionic K <psionik@positron.solutions>
Software Engineer

*Positron Solutions <https://positron.solutions>*

[-- Attachment #2: Type: text/html, Size: 9637 bytes --]

  parent reply	other threads:[~2022-11-29  2:38 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-21 14:40 Delegating user-reserved key binding space definition to users Psionic K
2022-11-21 19:37 ` Stefan Monnier
2022-11-22  2:07   ` Phil Sainty
2022-11-25  2:48     ` Psionic K
2022-11-25  3:31       ` Ihor Radchenko
2022-11-25 13:53         ` xenodasein--- via Emacs development discussions.
2022-11-25 15:16       ` Stefan Monnier
2022-11-26  6:44         ` Ihor Radchenko
2022-11-26 17:29           ` Stefan Monnier
2022-11-27  5:45             ` Ihor Radchenko
2022-11-27 11:26               ` Psionic K
2022-11-27 11:53                 ` Psionic K
2022-11-28 18:15               ` Stefan Monnier
2022-11-28 18:37                 ` Eli Zaretskii
2022-11-29  2:38                 ` Psionic K [this message]
2022-11-29  4:01                   ` Stefan Monnier
2022-11-29  5:22                     ` Psionic K
2022-11-29 13:03                       ` Eli Zaretskii
2022-11-30  6:23                         ` Psionic K
2022-11-30  9:01                           ` xenodasein--- via Emacs development discussions.
2022-11-30 13:44                           ` Eli Zaretskii
2022-11-29 11:54                 ` John Yates

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=CADQMGATy4j_uPg9MBDLWRJNYk4wqn8Mw349pqsgJZeEp7h+c+A@mail.gmail.com \
    --to=psionik@positron.solutions \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=yantar92@posteo.net \
    /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).