Emacs: Mode-Dependent Key Shortcut
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 will check 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-cmdif current mode is
x2-cmdif current mode is
(defun my-smart-command () "call different commands depending on what's current major mode." (interactive) (cond ((string-equal major-mode "x1-mode") (x1-cmd)) ((string-equal 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: How to Define Keys]
[see Emacs: Find Major Mode Name]