emacs-devel
[Top][All Lists]
Advanced

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

Re: Proposal: Bind backspace and delete like DEL in view-mode


From: Kim F. Storm
Subject: Re: Proposal: Bind backspace and delete like DEL in view-mode
Date: 29 Dec 2001 03:14:22 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1

address@hidden (Kai Großjohann) writes:

> address@hidden (Kim F. Storm) writes:
> 
> > Basically, I still feel that when emacs prints a certain name for an
> > event, then it should be possible to use that same name when making a
> > binding for that event.
> 
> Of course, my suggestion is to advise people to use the kbd syntax,
> as it gives what you want.

I knew you would say that :-)
And I don't disagree in general - but it is an even more complex
syntax for the novice user.

> 
> Please note that using the non-kbd syntax already requires some
> knowledge.  In particular, when Emacs 20 prints "C-f1" you have to
> write [C-f1] in define-key but when Emacs 20 prints "C-a" you have to
> write "\C-a" or [?\C-a] in define-key.  (Emacs 21 prints "<C-f1>" and
> "C-a" so the presence of the angle brackets is some indication.  But
> it's still a lot easier to just copy the string that Emacs 21 prints,
> verbatim, to kbd.)
> 
> I strongly believe that the kbd syntax should be somehow default.
> For example, define-key could look whether the key definition is a
> string, and if so, it could look for \C-x and suchlike constructs in
> it.  If none are present, it could hand the string to kbd and use the
> result.  I'm not sure if this is feasible.
>
The problem is that define-key is built-in while kbd is not.

 
> But I am convinced that the kbd syntax is the best syntax to use for
> newbies, because it is (since Emacs 21) exactly equal to the printout
> from C-h c, C-h l, C-h k and friends!

What about adding the following function:

(defun bind-key (keys command &optional map)
   "Bind KEYS to COMMAND in MAP. Use global-map if MAP is omitted or nil.
KEYS is string specifying a key sequence in the format recogized by the `kbd' 
macro."
   (define-key
      (or map global-map) (read-kbd-macro keys) command))

This supports formats like

        (bind-key "DEL" 'backward-delete-char)
        (bind-key "C-a" 'apropos help-map)


A more advanced version could be:

(defun bind-key (keys command &optional map)
   "Bind KEYS to COMMAND in MAP. Use global-map if MAP is omitted or nil.
KEYS is string specifying a key sequence in the format recogized by the `kbd' 
macro.
Alternatively, KEYS is a vector in the format recognized by `define-key'.
Finally, KEYS may be a single key or symbol."
   (define-key
      (or map global-map) 
      (cond
        ((stringp keys) (read-kbd-macro keys))
        ((vectorp keys) keys)
        (t (vector keys)))
      command))

This also allows things like:

        (bind-key [(control ?a)] 'beginning-of-line)
        (bind-key ?\d 'backward-delete-char)
        (bind-key 'f5 'bury-buffer)


Alternatively, the keydef.el package posted some time ago on
gnu.emacs.sources could be installed.  It is more complex -
but also has some interesting ideas.

-- 
Kim F. Storm <address@hidden> http://www.cua.dk




reply via email to

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