What happened to the following unbind script?

(dolist (abcc '("Ca" "Cb")) (global-unset-key (kbd abcc))) 

He continues to give an error:

 Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p abcc) read-kbd-macro(abcc) #[(keys) "\301!\207" [keys read-kbd-macro] 2 2180088](abcc) (kbd abcc) (global-unset-key (kbd abcc)) (while --dolist-tail-- (setq abcc (car --dolist-tail--)) (global-unset-key (kbd abcc)) (setq --dolist-tail-- (cdr --dolist-tail--))) (let ((--dolist-tail-- ...) abcc) (while --dolist-tail-- (setq abcc ...) (global-unset-key ...) (setq --dolist-tail-- ...))) (dolist (abcc (quote ...)) (global-unset-key (kbd abcc))) eval-buffer(#<buffer *load*> nil "/home/name/.emacs" nil t) ; Reading at buffer position 63 load-with-code-conversion("/home/name/.emacs" "/home/name/.emacs" tt) load("~/.emacs" tt) #[nil "\205\264 
+4
source share
3 answers

I initially thought this was a bug in Emacs. I was very surprised that no one had come across this before.

The following is a workaround:

 (dolist (abcc '("Ca" "Cb")) (global-unset-key (read-kbd-macro abcc))) 

What happens is kbd, which is a macro that wraps a function, however it does not explicitly evaluate its parameter. Thus, the abcc character is passed directly to the function.

After a bit more thinking (and reading documents). This is actually a user error.

The doc string for kbd clearly states that it should be used for string constants.

So, kbd should be used when it is only required that the internal representation of the key is displayed in the compiled bytecode. eg.

 (define-key foo-mode-map (kbd "Ca") 'foo) 

But read-kbd-macro should be used when you want the argument to be evaluated.

+6
source

(keys) is a macro that just goes to (read-kbd-macro) . The former is for some reason mistaken, but the latter does not. Try this instead?

+1
source

kbd is a macro, so it does not evaluate its argument.

0
source

All Articles