简体   繁体   中英

Emacs: wrong-type-argument error in Emacs23 but not in Emacs24

First of all, I'll admit that I'm a complete novice at Emacs and ELisp (and for that matter Lisp in general), and I have stumbled upon an error that has got me stumped for quite a while now while trying to write my .emacs file.

Here is a minimal example of code necessary to reproduce the problem (ie having .emacs containing only the following):

(defun define-esc-key (keybind)
  (define-key key-translation-map (kbd keybind) 'my-esc))
(define-esc-key "M-j")

This will produce the following error with Emacs23:

Lisp error: (wrong-type-argument integer-or-marker-p keybind)
  read-kbd-macro(keybind)
  #[(keys) "\301!\207" [keys read-kbd-macro] 2 2186954](keybind)
  (kbd keybind)
  (define-key key-translation-map (kbd keybind) (quote my-esc))
  define-esc-key("M-j")

but works as I expect it to in Emacs24. It also works in Emacs23 if I replace the instance of keybind in the define-esc-key function body by "Mj" .

(By the way, sorry for the bad title but I just couldn't think of anything more descriptive.)

From the NEWS file:

* Lisp Changes in Emacs 24.3
...
*** `kbd' is now a function rather than a macro.

That means that in earlier Emacs versions, the argument to kbd must be literally present in the call, as opposed to the use of a variable in your example.

Alternatively, you can use eval and backquotes to insert the value:

(eval `(kbd ,keybind))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM