Emacs Keys: Major-Mode Dependent Key
You can have a key do different things depending on what's the current Major Mode .
The most simple way, is to write a wrapper command. The wrapper command checks current mode and call different commands. Then, you bind the wrapper command to a key in global map.
Here's a example of a wrapper command.
suppose you want F9 to call:
x1-cmd
if current mode isx1-mode
x2-cmd
if current mode isx2-mode
(defun my-smart-command () "call different commands depending on what's current major mode." (interactive) (cond ((eq major-mode 'x1-mode) (x1-cmd)) ((eq major-mode 'x2-mode) (x2-cmd)) ;; more major-mode checking here ;; if nothing match, do nothing (t nil)))
Then, just bind this command to a key. 〔see Emacs Keys: Define Key〕