In order to get keybindings to work across all buffers (both external program buffers managed by exwm and other Emacs buffers), I need to bind them using exwm-input-set-key. To make this convenient, I have a macro bind-exwm-keys similar in spirit to bind-keys described earlier.

bind-exwm-keys might have to bind key sequences to not just Emacs commands, but also to external programs. For this, the external program needs to be wrapped up in an Emacs command. This wrapping is handled by make-external-command. make-external-command returns a command that invokes the external program if it isn't already running, switches to the buffer of the external program if it is already running, and switches to the last used buffer if the external program is already running and is the current buffer. This makes it easy to start an external program, switch to it, and switch back from it all using the same keybinding.