views:

357

answers:

2

If you had two snippets:

(global-set-key "\C-d" delete-char)

and

(define-key global-map "\C-d" delete-char)

Is there a difference between the two? If so, when would you use one over the other?

+7  A: 

Function global-set-key is an interactive function based on define-key which you can invoke by typing M-x global-set-key. Function define-key is rather used in Lisp programs.

You can look up global-set-key's source code with C-h f global-set-key to see that it only wraps define-key.

To answer your question, there are no significant differences between them.

Török Gábor
+8  A: 

global-set-key is defined in subr.el as:

(define-key (current-global-map) key command))
dfa