From 7777b3e5ecfe4f721fa6d65282caf52766d48fb5 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Sat, 30 May 2020 17:22:14 +0100 Subject: [PATCH] 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. --- tmux.conf | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/tmux.conf b/tmux.conf index 3847513..2e88298 100644 --- a/tmux.conf +++ b/tmux.conf @@ -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