Re: FAQ: xterm-keys and editors
applied, thanks On Tue, Feb 18, 2014 at 06:27:57PM -0500, Mark Oteiza wrote: Nicholas Marriott nicholas.marri...@gmail.com writes: Ok I think it is better not to include tmux.el at all then, instead just put the bit to copy in FAQ like this: diff --git a/FAQ b/FAQ index da72d43..c5abf01 100644 --- a/FAQ +++ b/FAQ @@ -238,6 +238,31 @@ would be welcome. vim users may also want to set the ttyfast option inside tmux. +* How do I make ctrl and shift arrow keys work in emacs? + +The terminal-init-screen function in term/screen.el is called for new frames, +but it doesn't configure any function keys. + +If the tmux xterm-keys option is on, it is enough to define the same keys as +xterm. Add the following to init.el or .emacs to do this: + +(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 + +And ensure .tmux.conf contains set -g xterm-keys on. + +Alternatively, the screen.el file can be copied to the load path and +customized. + * 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 Looks good. Thanks for the consideration. -- 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=121054471iu=/4140/ostg.clktrk ___ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users -- 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=121054471iu=/4140/ostg.clktrk ___ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users
Re: FAQ: xterm-keys and editors
Nicholas Marriott nicholas.marri...@gmail.com writes: I wrote tmux.el, it's the Groups thread that gave me the clue. I tried rewriting the useful bits from there into the file, as well as applying the other things you suggested. On another note, the plugins that Suraj pointed out look nice. In particular, Fixkeys seems to cover a lot. Hi Thanks. I tried to make your FAQ text clearer but I don't understand what the FAQ entry is telling me to do. Should I copy screen.el into load path and edit it? Or tmux.el? Or both? It seems like just tmux.el is enough if xterm-keys is on? So what should I do with tmux.el? Put it in load path and then require 'tmux? Or something else? So maybe this text: --- 8 --- * How do I make ctrl and shift arrow keys work in emacs? The terminal-init-screen function in term/screen.el is called for new frames, but it doesn't configure any function keys. If the tmux xterm-keys option is on, it is enough to define the same keys as xterm - use the examples/tmux.el file to do this. Alternatively, the screen.el file can be copied to the load path and customized. --- 8 --- What you wrote is a lot clearer and concise than what I wrote. Yes, you are right, either (a) customize screen.el, or (b) include the contents of examples/tmux.el in your init.el. I meant examples/tmux.el as just a snippet of elisp rather than a library that can be require'd. I try to communicate this (basically (b)) with this sentence from examples/tmux.el: ;; This can be added to `~/.emacs/init.el' to get xterm keys in Emacs ;; tmux, when `xterm-keys' is set to `on' in tmux. Perhaps s/added to/inserted into/ would be clearer? -- 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=121054471iu=/4140/ostg.clktrk ___ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users
Re: FAQ: xterm-keys and editors
Ok I think it is better not to include tmux.el at all then, instead just put the bit to copy in FAQ like this: diff --git a/FAQ b/FAQ index da72d43..c5abf01 100644 --- a/FAQ +++ b/FAQ @@ -238,6 +238,31 @@ would be welcome. vim users may also want to set the ttyfast option inside tmux. +* How do I make ctrl and shift arrow keys work in emacs? + +The terminal-init-screen function in term/screen.el is called for new frames, +but it doesn't configure any function keys. + +If the tmux xterm-keys option is on, it is enough to define the same keys as +xterm. Add the following to init.el or .emacs to do this: + +(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 + +And ensure .tmux.conf contains set -g xterm-keys on. + +Alternatively, the screen.el file can be copied to the load path and +customized. + * 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 On Mon, Feb 17, 2014 at 07:47:51PM -0500, Mark Oteiza wrote: Nicholas Marriott nicholas.marri...@gmail.com writes: I wrote tmux.el, it's the Groups thread that gave me the clue. I tried rewriting the useful bits from there into the file, as well as applying the other things you suggested. On another note, the plugins that Suraj pointed out look nice. In particular, Fixkeys seems to cover a lot. Hi Thanks. I tried to make your FAQ text clearer but I don't understand what the FAQ entry is telling me to do. Should I copy screen.el into load path and edit it? Or tmux.el? Or both? It seems like just tmux.el is enough if xterm-keys is on? So what should I do with tmux.el? Put it in load path and then require 'tmux? Or something else? So maybe this text: --- 8 --- * How do I make ctrl and shift arrow keys work in emacs? The terminal-init-screen function in term/screen.el is called for new frames, but it doesn't configure any function keys. If the tmux xterm-keys option is on, it is enough to define the same keys as xterm - use the examples/tmux.el file to do this. Alternatively, the screen.el file can be copied to the load path and customized. --- 8 --- What you wrote is a lot clearer and concise than what I wrote. Yes, you are right, either (a) customize screen.el, or (b) include the contents of examples/tmux.el in your init.el. I meant examples/tmux.el as just a snippet of elisp rather than a library that can be require'd. I try to communicate this (basically (b)) with this sentence from examples/tmux.el: ;; This can be added to `~/.emacs/init.el' to get xterm keys in Emacs ;; tmux, when `xterm-keys' is set to `on' in tmux. Perhaps s/added to/inserted into/ would be clearer? -- 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=121054471iu=/4140/ostg.clktrk ___ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users -- 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=121054471iu=/4140/ostg.clktrk ___ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users
Re: FAQ: xterm-keys and editors
Nicholas Marriott nicholas.marri...@gmail.com writes: Thanks Where did tmux.el come from? Did you write it? Can you add either a public domain declaration (look at vim-keys.conf) or the ISC license text to the top of the two new files? I think you have probably added enough to tmux.vim at least to be able to do this, although it'd probably be polite to also add something like: Based on an example give by Chris Johnsen at https://stackoverflow.com/a/15471820; I don't think the Google Groups link in tmux.el is terribly helpful, if there is any more explanatory text then just write it in the file instead. I wrote tmux.el, it's the Groups thread that gave me the clue. I tried rewriting the useful bits from there into the file, as well as applying the other things you suggested. On another note, the plugins that Suraj pointed out look nice. In particular, Fixkeys seems to cover a lot. 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 000..cb27663 --- /dev/null +++ b/examples/tmux.el @@ -0,0 +1,41 @@ +;; Author: Mark Oteiza +;; License: Public domain + +;; When using emacs in tmux, in order to make use of xterm(1)-style +;; keys like shifted arrow keys (e.g. for using windmove), one might +;; assign input codes in `init.el' like +;; +;; (define-key input-decode-map \e[1;2A [S-up]) +;; +;; and so on. This will work in a standalone emacs (i.e. emacs -nw), +;; but is insufficient for spawning emacsclients from emacs --daemon, +;; because this only affects the terminal selected when `init.el' is +;; loaded. Every terminal gets its own `input-decode-map' (i.e. it is +;; terminal local), so the define-key needs to be run every time a new +;; frame is loaded in a tmux pane. +;; +;; For each new frame, emacs runs a function `terminal-init-foo' where +;; `foo' depends on the TERM environment variable (see the `faces' +;; library). For xterm-like terminals, the `input-decode-map' +;; includes all the xterm keys; for screen-likes, these are excluded. +;; +;; The following elisp is an advice that copies xterm keys into the +;; screen `input-decode-map' by adding the logic to the function +;; `terminal-init-screen'. An advice is a way to edit builtin +;; functions. See (info (Elisp) Advising Functions). +;; +;; This can be added to `~/.emacs/init.el' to get xterm keys in Emacs +;; tmux, when `xterm-keys' is set to `on' in tmux. + +(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 000..336c371 --- /dev/null +++ b/examples/xterm-keys.vim @@ -0,0 +1,51 @@ + tmux.vim - Set xterm input codes passed by tmux + Author:Mark Oteiza + License: Public domain + Description: Simple plugin that assigns some xterm(1)-style keys to escape + sequences passed by tmux when xterm-keys is set to on. Inspired by an + example given by Chris Johnsen at: + https://stackoverflow.com/a/15471820 + + 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
Re: FAQ: xterm-keys and editors
Hi Thanks. I tried to make your FAQ text clearer but I don't understand what the FAQ entry is telling me to do. Should I copy screen.el into load path and edit it? Or tmux.el? Or both? It seems like just tmux.el is enough if xterm-keys is on? So what should I do with tmux.el? Put it in load path and then require 'tmux? Or something else? So maybe this text: --- 8 --- * How do I make ctrl and shift arrow keys work in emacs? The terminal-init-screen function in term/screen.el is called for new frames, but it doesn't configure any function keys. If the tmux xterm-keys option is on, it is enough to define the same keys as xterm - use the examples/tmux.el file to do this. Alternatively, the screen.el file can be copied to the load path and customized. --- 8 --- And a note in tmux.el saying what I should do with it. On Fri, Feb 14, 2014 at 08:35:16PM -0500, Mark Oteiza wrote: Nicholas Marriott nicholas.marri...@gmail.com writes: Thanks Where did tmux.el come from? Did you write it? Can you add either a public domain declaration (look at vim-keys.conf) or the ISC license text to the top of the two new files? I think you have probably added enough to tmux.vim at least to be able to do this, although it'd probably be polite to also add something like: Based on an example give by Chris Johnsen at https://stackoverflow.com/a/15471820; I don't think the Google Groups link in tmux.el is terribly helpful, if there is any more explanatory text then just write it in the file instead. I wrote tmux.el, it's the Groups thread that gave me the clue. I tried rewriting the useful bits from there into the file, as well as applying the other things you suggested. On another note, the plugins that Suraj pointed out look nice. In particular, Fixkeys seems to cover a lot. 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 000..cb27663 --- /dev/null +++ b/examples/tmux.el @@ -0,0 +1,41 @@ +;; Author: Mark Oteiza +;; License: Public domain + +;; When using emacs in tmux, in order to make use of xterm(1)-style +;; keys like shifted arrow keys (e.g. for using windmove), one might +;; assign input codes in `init.el' like +;; +;; (define-key input-decode-map \e[1;2A [S-up]) +;; +;; and so on. This will work in a standalone emacs (i.e. emacs -nw), +;; but is insufficient for spawning emacsclients from emacs --daemon, +;; because this only affects the terminal selected when `init.el' is +;; loaded. Every terminal gets its own `input-decode-map' (i.e. it is +;; terminal local), so the define-key needs to be run every time a new +;; frame is loaded in a tmux pane. +;; +;; For each new frame, emacs runs a function `terminal-init-foo' where +;; `foo' depends on the TERM environment variable (see the `faces' +;; library). For xterm-like terminals, the `input-decode-map' +;; includes all the xterm keys; for screen-likes, these are excluded. +;; +;; The following elisp is an advice that copies xterm keys into the +;; screen `input-decode-map' by adding the logic to the function +;; `terminal-init-screen'. An advice is a way to edit builtin +;; functions. See (info (Elisp) Advising Functions). +;; +;; This can be added to `~/.emacs/init.el' to get xterm keys in Emacs +;; tmux, when `xterm-keys' is set to `on' in tmux. + +(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
Re: FAQ: xterm-keys and editors
Two robust Vim plugins already exist for this purpose: https://github.com/drmikehenry/vim-fixkey#readme https://github.com/nacitar/terminalkeys.vim#readme On Feb 7, 2014 1:49 AM, Mark Oteiza mvote...@udel.edu wrote: 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. -- 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=121051231iu=/4140/ostg.clktrk ___ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users -- 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=121051231iu=/4140/ostg.clktrk___ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users
Re: FAQ: xterm-keys and editors
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. --- # For each new Emacs frame, a function is called to initialize # term-specific things. The function `terminal-init-screen' loads the # xterm library just to figure out 88 or 256 colors; it does not map # the xterm-specific keys. # # 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. (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; e.g. 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 --- [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 -- Mark Oteiza -- 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=121051231iu=/4140/ostg.clktrk ___ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users -- 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=121051231iu=/4140/ostg.clktrk___ tmux-users mailing list tmux-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tmux-users