[Top][All Lists]

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

RE: have cake will eat, eatcake will have - krazy key koncept kontrovers

From: Drew Adams
Subject: RE: have cake will eat, eatcake will have - krazy key koncept kontroversy
Date: Thu, 27 Aug 2009 13:41:11 -0700

> 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

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 ()
  (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

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

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

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 via email to

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