Integrate Tmux pane switching with Emacs

When current pane is running Emacs, simply pass the pane switching keys
through to Emacs, so they can switch panes (called "windows") within
Emacs itself.

This allows a nearly seamless window/pane switching experience between
Emacs and Tmux.
This commit is contained in:
2020-05-30 17:22:14 +01:00
parent 55872cf5b8
commit 7777b3e5ec

View File

@@ -51,11 +51,24 @@ unbind Enter
bind Enter resize-pane -Z
bind C-Enter resize-pane -Z
# Use Alt-[j/i/l/k] keys without prefix key to switch panes.
bind -n M-j select-pane -L
bind -n M-k select-pane -D
bind -n M-i select-pane -U
bind -n M-l select-pane -R
# Enable smart pane switching that's Emacs aware.
is_emacs='echo "#{pane_current_command}" | grep -iqE "(^|\/)emacs$"'
# Use Alt-[i/k/j/l] keys without prefix key to switch panes if current pane is
# not running Emacs. If the pane is running Emacs, let Emacs receive the
# keybindings instead.
bind -n M-i if-shell "$is_emacs" "send-keys M-i" "select-pane -U"
bind -n M-k if-shell "$is_emacs" "send-keys M-k" "select-pane -D"
bind -n M-j if-shell "$is_emacs" "send-keys M-j" "select-pane -L"
bind -n M-l if-shell "$is_emacs" "send-keys M-l" "select-pane -R"
bind -T copy-mode M-i if-shell "$is_emacs" "send-keys M-i" "select-pane -U"
bind -T copy-mode M-k if-shell "$is_emacs" "send-keys M-k" "select-pane -D"
bind -T copy-mode M-j if-shell "$is_emacs" "send-keys M-j" "select-pane -L"
bind -T copy-mode M-l if-shell "$is_emacs" "send-keys M-l" "select-pane -R"
bind -T copy-mode-vi M-i if-shell "$is_emacs" "send-keys M-i" "select-pane -U"
bind -T copy-mode-vi M-k if-shell "$is_emacs" "send-keys M-k" "select-pane -D"
bind -T copy-mode-vi M-j if-shell "$is_emacs" "send-keys M-j" "select-pane -L"
bind -T copy-mode-vi M-l if-shell "$is_emacs" "send-keys M-l" "select-pane -R"
# Toogle synchronize-panes without prefix key.
bind -n M-I setw synchronize-panes