Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between `global-set-key` and `define-key global-map` in Emacs

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?

like image 261
haxney Avatar asked May 25 '09 11:05

haxney


2 Answers

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.

like image 55
viam0Zah Avatar answered Oct 13 '22 09:10

viam0Zah


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

(define-key (current-global-map) key command))
like image 21
dfa Avatar answered Oct 13 '22 10:10

dfa