[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Key bindings proposal

From: Uday S Reddy
Subject: Re: Key bindings proposal
Date: Tue, 27 Jul 2010 17:41:43 +0100

Stefan Monnier writes:

> Not at all.  `remap' is typically not used by the user in his .emacs but
> by major/minor modes to locally/temporarily replace particular commands
> by other ones (and to do so in a declarative way ;-), so that if the
> user (or some other mode) has rebound this command elsewhere, the
> remapping still works as intended.  Before that, packages used
> substitute-key-definition for that purpose, but that was not as
> declarative and it only adapted to changes in global bindings.

Indeed.  Not only is it declarative, but it is also object-oriented
(or "subtyped" or "conformant").

When you bind [remap undo] to a mode-specific undo operation, you are
inheriting the key binding made for undo somewhere else.  At least for
this operation, you are conforming to some global theme that has been
established for the user.

The world outside Emacs is heavily object-oriented.  And, that has
brought a tremendous amount of order to the world of user interfaces.
We take it for granted that every application will have a suitable
implementation for generic operations like "open", "close", "refresh"
and "help".  Unfortunately, all of this civilizational progress is
passing Emacs by.  Just a few weeks ago, somebody here was bemoaning
how the inconsistency of "refresh" in Emacs modes drives him nuts.

However, I think we can do better than remap.  remap allows ad-hoc
inheritance to grow up in fits and sneezes wherever it feels like.  It
is not proper subtyping.  Oscar Fuentes had a proposal here on 7/17
which I am drawn to:

> I possible solution for this problem is to use `actions'. An action is a
> generic concept like `fordward-line', or `undo', or `save', or `yank'
> (`paste', if you prefer.)  `universal-argument',
> `execute-extended-command' and `C-x' (whatever is officially called on
> Emacs jargon) would be actions as well.
> Currently a mode defines its keymap relating keys to functions. An
> action-aware mode relates actions to functions. At a higher level, there
> is a mapping of keys into actions. When a mode is activated for a
> buffer, the keymap is constructed looking up the corresponding keys
> assigned to the actions the mode implements. A mode inherits the
> key->action mapping from its parent mode, but can define its own actions
> that overrides its parent's.

It seems to me that these "actions" are a form of abstract operations.
The actions implemented by a mode can be regarded as its interface.
Some of these actions might have globally defined key bindings, some
might be local, and some might have no key bindings.  It might be
possible to invoke actions with the M-x prefix or something like it.
Emacs would immediately feel a lot more object-oriented than it
currently does.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]