Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Looking at how people program their keyboard shortcuts in Emacs, I have noticed two different patterns:

One uses:

(global-set-key (kbd "M-N) 'select-next-window)

The other one:

(define-key global-map (kbd "M-N") 'select-next-window)

What's the difference between them? Don't they both define "global" keyboard shortcuts in Emacs?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Doesn't seem to be much of a difference in the major case:

  • (global-set-key key command) boils down to (define-key (current-global-map) key command)), and
  • describe-var tells us that global-map "is a keymap which is usually (but not necessarily) Emacs's global map", whereas
  • (current-global-map) "returns the current global keymap".

However, the Emacs docs talk of "the" global keymap, so it's unclear how, if ever, you can come across several global keymaps.

share|improve this answer
    
The variable global-map might be bound to a file or buffer local value, or it could even be bound in a let statement. –  Trey Jackson Dec 15 '11 at 23:09
1  
The global keymap is set by use-global-map. There aren't many packages that do this: mostly a few emulation modes such as Viper, and some functions such as read-char that override the global map temporarily. –  Gilles Dec 16 '11 at 8:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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