unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
To: "'Andrey Paramonov'" <cmr.Pent@gmail.com>, <emacs-devel@gnu.org>
Subject: RE: have cake will eat, eatcake will have - krazy key koncept kontroversy
Date: Thu, 27 Aug 2009 13:41:11 -0700	[thread overview]
Message-ID: <E4672959BA664F7BA94C52E005BD8D37@us.oracle.com> (raw)
In-Reply-To: <loom.20090827T195747-305@post.gmane.org>

> I see the problem you are trying to solve.

Yes and no. I think you see the point about using a suffix key to repeat an
action.

I don't think you see the point about using a prefix key (as its own suffix) to
perform a (repeatable) action.

[*]

> 1) In many cases, user will have to hit prefix twice instead 
> of once (C-a C-a instead of C-a).

Not just in many cases. In *all* cases where this technique is used.

This is in the nature of a prefix key. If a key (e.g. C-a) performs an action on
its first press, then it cannot be a prefix key.

Otherwise, how could you distinguish C-a as action from C-a as prefix? How would
you know whether C-a might be followed by `j' or `C-r' (assuming keys `C-a j'
and `C-a C-r' were defined)?

> I suggest to go the other way around: 
> IF there is no keymap entry that matches the key sequence
> *and* the previous key has successfully executed a command
> *and* the key equals to the previous key 
> THEN repeat the command (and keep processing the key sequence).
> 
> For example:
> C-x o   will take me to other window
> C-x o o o o ...   will cycle me through windows
> C-x C-f   will work as used to
> C-x C-x   will exchange point and mark
> C-x C-x C-x   will exchange point and mark twice
> C-x C-x C-x C-x   will exchange point and mark three times
> 
> This approach does not impose extra key penalty for 
> non-repetitive command execution.
> 
> In Emacs 23, C-x C-= / C-x C-- (text-scale-adjust) work this 
> way. I find it very useful and intuitive.

What you are talking about has nothing to do with prefix keys.

Using the technique I mentioned, you can get the behavior you listed (C-x o, C-x
o o o..., C-x C-x, etc) immediately:

(defun other-window-repeat ()
  (interactive)
  (repeat-command 'other-window))

(define-key ctl-x-map "o" 'other-window-repeat)

The fact that you can do that in this way is only part of what I was pointing
out.

The real point was to be able to use this technique also for a prefix key: to be
able to have a prefix key perform some action when repeated.  Why?

a. To have additional easily repeatable keys (giving existing prefix keys double
duty).

b. To have additional prefix keys (giving existing non-prefix keys double duty).

Obviously, if the same key is used as both prefix and suffix, then no action can
be performed the first time the key is pressed. Because it is a prefix key, C-x
does nothing until you press it again (or press some another key).

So we would only bind a repeatable action to a prefix key followed by itself
when that action is not very useful as a one-off. I gave as examples commands
that incrementally change some parameter - e.g. the height of a window, frame,
font,...  It's not very important that such a command do something on the very
first key press, since you are going to press it multiple times.

The point is that we can:

a. Use an existing prefix key as its own suffix, and thus let it perform some
repeatable action (starting with the first repetition).

b. Convert an existing non-prefix key to a prefix key, when its one-off action
isn't really needed (that is, we are mainly interested in its repeated action).

Together, these allow reuse of the same key to (a) perform a repeated action by
holding it pressed and (b) serve as a way station to other keys/commands, by
being a prefix.

Wrt (a): Think of all the prefix keys you use. We could reuse an existing prefix
key such as `M-s h' to perform a repeatable action such as, I don't know,
highlight-the-next-word: M-s h h h h...

Would it be worth it to do that? Dunno. It all depends on the particular keys
and commands. But the possibility is there.

Wrt (b): Think of all the non-prefix keys you use. Some of them perform useful
repeatable actions. Others do not - they are just one-offs. C-M-a is usefully
repeatable; C-M-x is not. (Binding C-M-x to a command that we do not repeat is,
_in itself_, a waste. But there are other reasons for that binding.)

We could make a key such as C-M-a or C-M-x into a prefix key, if we wanted. (I'm
not suggesting we do that.) Advantage: another prefix key.

If we did that, we could still have C-M-a go to the beginning of the previous
defun, in a repeatable way, just as now. The only loss would be that to get the
one-off behavior of going just to the current defun, you would need to hit C-M-a
twice.

Would it be worth it to do that for C-M-a? Probably not. It all depends on the
particular command (do we really need the one-off behavior?), the particular key
binding (is it easy to repeat?), and how hard up we are for a new prefix key.
But the possibility is there.


[* To simplify the wording, I say use the prefix key as its own suffix, but I
really mean use some tail of the prefix key as its own suffix, where the tail
could be the whole prefix key. `C-x C-x' uses the whole prefix key `C-x' as a
suffix. `M-s h h' uses only the tail `h' of the prefix key `M-s h' as a suffix.]






  reply	other threads:[~2009-08-27 20:41 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-27  1:36 have cake will eat, eat cake will have - krazy key koncept kontroversy Drew Adams
2009-08-27 17:58 ` Andrey Paramonov
2009-08-27 20:41   ` Drew Adams [this message]
2009-08-28  6:35     ` have cake will eat, eatcake " Андрей Парамонов
2009-08-28  9:09       ` Andreas Schwab
2009-08-28  9:16         ` Андрей Парамонов
2009-08-28  9:35           ` Andreas Schwab
2009-08-28 15:34       ` Drew Adams
2009-08-28  0:35 ` have cake will eat, eat cake " Juri Linkov
2009-08-28  2:31   ` Miles Bader
2009-08-28 15:34     ` Drew Adams

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=E4672959BA664F7BA94C52E005BD8D37@us.oracle.com \
    --to=drew.adams@oracle.com \
    --cc=cmr.Pent@gmail.com \
    --cc=emacs-devel@gnu.org \
    /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).