Nicholas Marriott <nicholas.marri...@gmail.com> writes:

> Hi
>
> Looks nice, can you make a diff with your suggested text against FAQ
> and adding this file to examples/?
>
> Cheers
>
> -------- Original message --------
> From: Mark Oteiza <mvote...@udel.edu> 
> Date: 04/02/2014 06:11 (GMT+00:00) 
> To: tmux-users@lists.sourceforge.net 
> Subject: FAQ: xterm-keys and editors 
>
> Hi,
>
> Recently I tackled the issue of editors and keybindings in tmux. This
> has been addressed on the mailing list a couple times before [0][1],
> and
> has spawned a bunch of SO posts, etc. It would be really nice if
> solutions were in the FAQ.
>
> Most of what I think should be added was already written by Chris
> Johnsen: on here about emacs [1], and on SO about vim [3].
>
> I think I found a simpler (and elispy) alternative solution for emacs
> based on what I found on the emacs help mailing list [2]. I try to
> explain all the details for the below snippet in its comments.
>
> <snip>
>
> [0]
> http://thread.gmane.org/gmane.comp.terminal-emulators.tmux.user/2197
> [1]
> http://thread.gmane.org/gmane.comp.terminal-emulators.tmux.user/4268
> [2] https://groups.google.com/forum/#!topic/gnu.emacs.help/ZGu2MNkJGrI
> [3] https://stackoverflow.com/questions/15445481

Here's the patch for the emacs stuff, and another with a
vim-plugin-ified version of what Johnsen wrote in [3], if you think that
could be added as well.

diff --git a/FAQ b/FAQ
index da72d43..7c0e2b6 100644
--- a/FAQ
+++ b/FAQ
@@ -238,6 +238,24 @@ would be welcome.
 
 vim users may also want to set the "ttyfast" option inside tmux.
 
+* How do I make Ctrl-arrow and Shift-arrow keys work in emacs?
+
+For each new emacs frame, a function is called to initialize term-specific
+things. In tmux, where TERM is a "screen" derivative, this function is
+"terminal-init-screen". It loads the xterm library to use its functionality to
+figure out whether to use 88 or 256 colors; it does not map the xterm-specific
+keys.
+
+The code in the library "term/xterm.el.gz" that maps xterm keys is
+
+  (let ((map (copy-keymap xterm-function-map)))
+    (set-keymap-parent map (keymap-parent input-decode-map))
+    (set-keymap-parent input-decode-map map)))
+
+You can copy "term/screen.el" to your local load path to to include desired
+mappings from "xterm-function-map", thus overriding the native screen library.
+You can also advise the function "terminal-init-screen" -- see examples/tmux.el.
+
 * Why doesn't elinks set the window title inside tmux?
 
 There isn't a way to detect if a terminal supports setting the window title, so
diff --git a/examples/tmux.el b/examples/tmux.el
new file mode 100644
index 0000000..52e76d8
--- /dev/null
+++ b/examples/tmux.el
@@ -0,0 +1,20 @@
+;; This is an `advice' to augment `terminal-init-screen', which one can
+;; add to `~/.emacs/init.el' to get xterm keys in Emacs & tmux, when
+;; `xterm-keys' is set to `on' in tmux.
+;;
+;; https://groups.google.com/forum/#!topic/gnu.emacs.help/ZGu2MNkJGrI
+;;
+;; Documentation: (info "(Elisp) Advising Functions")
+
+(defadvice terminal-init-screen
+  ;; The advice is named `tmux', and is run before
+  ;; `terminal-init-screen' runs.
+  (before tmux activate)
+  ;; Docstring.  This describes the advice and is made available inside
+  ;; emacs; for example when doing C-h f terminal-init-screen RET
+  "Apply xterm keymap, allowing use of keys passed through tmux."
+  ;; This is the elisp code that is run before `terminal-init-screen'.
+  (if (getenv "TMUX")
+    (let ((map (copy-keymap xterm-function-map)))
+    (set-keymap-parent map (keymap-parent input-decode-map))
+    (set-keymap-parent input-decode-map map))))
diff --git a/examples/xterm-keys.vim b/examples/xterm-keys.vim
new file mode 100644
index 0000000..6b5efe3
--- /dev/null
+++ b/examples/xterm-keys.vim
@@ -0,0 +1,45 @@
+" tmux.vim - Set xterm input codes passed by tmux
+" Documentation: help:xterm-modifier-keys man:tmux(1)
+
+if exists("g:loaded_tmux") || &cp
+  finish
+endif
+let g:loaded_tmux = 1
+
+function! s:SetXtermCapabilities()
+  set ttymouse=sgr
+
+  execute "set <xUp>=\e[1;*A"
+  execute "set <xDown>=\e[1;*B"
+  execute "set <xRight>=\e[1;*C"
+  execute "set <xLeft>=\e[1;*D"
+
+  execute "set <xHome>=\e[1;*H"
+  execute "set <xEnd>=\e[1;*F"
+
+  execute "set <Insert>=\e[2;*~"
+  execute "set <Delete>=\e[3;*~"
+  execute "set <PageUp>=\e[5;*~"
+  execute "set <PageDown>=\e[6;*~"
+
+  execute "set <xF1>=\e[1;*P"
+  execute "set <xF2>=\e[1;*Q"
+  execute "set <xF3>=\e[1;*R"
+  execute "set <xF4>=\e[1;*S"
+
+  execute "set <F5>=\e[15;*~"
+  execute "set <F6>=\e[17;*~"
+  execute "set <F7>=\e[18;*~"
+  execute "set <F8>=\e[19;*~"
+  execute "set <F9>=\e[20;*~"
+  execute "set <F10>=\e[21;*~"
+  execute "set <F11>=\e[23;*~"
+  execute "set <F12>=\e[24;*~"
+
+  execute "set t_kP=^[[5;*~"
+  execute "set t_kN=^[[6;*~"
+endfunction
+
+if exists('$TMUX')
+  call s:SetXtermCapabilities()
+endif
------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121051231&iu=/4140/ostg.clktrk
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to