zoppo/plugins — pull request #5 by kljohann (2014-01-20 23:35:17+00:00)
Title: fix activation of application mode in ZLE

I just noticed this because of the updated history-substring-search module. [This commit](https://github.com/zsh-users/zsh-history-substring-search/commit/82fbef5132b44c5d039e7d25972d9351c5936bc2) dropped the default binding of `\EOA` thus for the Up-key binding to work we rely on the value of `$terminfo[kcuu1]`. When I'm running tmux using `TERM=screen-256color`, `\E[A` is sent in "raw" mode and `\E[OA` in "application" mode:

```sh
# I uncommented 'zle -N zle-line-finish/init' in editor/init.zsh for this example
$ echoti rmkx
$ cat > /dev/null
^[[A^[[A^[[A
$ echoti smkx
$ cat > /dev/null
^[OA^[OA^[OA
```

`infocmp $TERM` list the application mode key for `kcuu1`. Thus I would expect the 'Up' mapping to work in tmux. But it does not. Running this snippet from the [ZSH FAQ](http://zsh.sourceforge.net/FAQ/zshfaq03.html#l25) by hand solves the problem:

```sh
function zle-line-init () { echoti smkx }
function zle-line-finish () { echoti rmkx }
zle -N zle-line-init
zle -N zle-line-finish
```

So my guess is that this functionality is not implemented correctly in `editor/init.zsh`. Indeed, the value of `"$0"` in `function zle-keymap-select zle-line-init zle-line-finish {` always seems to be `zsh` when called as a widget or via `execute-named-cmd`. When calling the function directly, `"$0"` returns the name of the function as expected.

***

I started typing this into the 'new issue' form but then created a patch after finishing the last paragraph so I'm doing a pull request instead. If you have a DRYer way of achieving the same thing feel free to implement that instead of this patch. :)