39

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?

2 Answers 2

35

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.

22

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

(define-key (current-global-map) key command))
2
  • 4
    It will be nice if you can tell the difference b/w the 2
    – Jaseem
    May 1, 2013 at 20:35
  • @Jaseem He just did. That's the difference between the two. global-set-key is a shortcut for defining a key in the value of (current-global-map).
    – user964843
    Dec 12, 2016 at 0:53

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.