]> git.wincent.com - docvim.git/commitdiff
Add Terminus to the integration tests
authorGreg Hurrell <greg@hurrell.net>
Sun, 12 Jun 2016 22:24:12 +0000 (15:24 -0700)
committerGreg Hurrell <greg@hurrell.net>
Sun, 12 Jun 2016 22:24:12 +0000 (15:24 -0700)
This is a good one as we don't have any doc comments. Should produce empty
files, but produces files with a blank line.

bin/get
bin/put
tests/fixtures/integration/terminus/golden/ast.golden [new file with mode: 0644]
tests/fixtures/integration/terminus/golden/markdown.golden [new file with mode: 0644]
tests/fixtures/integration/terminus/golden/plaintext.golden [new file with mode: 0644]
tests/fixtures/integration/terminus/input/.gitignore [new file with mode: 0644]
tests/fixtures/integration/terminus/input/LICENSE.txt [new file with mode: 0644]
tests/fixtures/integration/terminus/input/autoload/terminus/private.vim [new file with mode: 0644]
tests/fixtures/integration/terminus/input/plugin/terminus.vim [new file with mode: 0644]

diff --git a/bin/get b/bin/get
index 5aa587c52dae6719f91051ce5b444b8ae38995b9..8ed144736278c705f6dacf2581640280827875bb 100755 (executable)
--- a/bin/get
+++ b/bin/get
@@ -15,6 +15,7 @@ usage() {
   echo "  bin/get ferret      #"
   echo "  bin/put pinnacle    # freshen a specific downstream"
   echo "  bin/put scalpel     #"
+  echo "  bin/put terminus    #"
   echo "  bin/get vim-docvim  #"
   echo "  ---------------------------------------------------"
   echo "  bin/get all         # freshen all sources"
@@ -42,9 +43,10 @@ else
         update ferret
         update pinnacle
         update scalpel
+        update terminus
         update vim-docvim
         ;;
-      command-t|ferret|pinnacle|scalpel|vim-docvim)
+      command-t|ferret|pinnacle|scalpel|terminus|vim-docvim)
         update "$PROJECT"
         ;;
       *)
diff --git a/bin/put b/bin/put
index d89c9a6b716f154d78d1e2d8218e55f26fa2dbcc..a819c03acdc142cdfc5df3448c93ae94078a5cac 100755 (executable)
--- a/bin/put
+++ b/bin/put
@@ -21,6 +21,7 @@ usage() {
   echo "  bin/put ferret      #"
   echo "  bin/put pinnacle    # freshen a specific downstream"
   echo "  bin/put scalpel     #"
+  echo "  bin/put terminus    #"
   echo "  bin/put vim-docvim  #"
   echo "  ---------------------------------------------------"
   echo "  bin/put all         # freshen all downstreams"
@@ -50,9 +51,10 @@ else
         update ferret
         update pinnacle
         update scalpel
+        update terminus
         update vim-docvim
         ;;
-      command-t|ferret|pinnacle|scalpel|vim-docvim)
+      command-t|ferret|pinnacle|scalpel|terminus|vim-docvim)
         update "$PROJECT"
         ;;
       *)
diff --git a/tests/fixtures/integration/terminus/golden/ast.golden b/tests/fixtures/integration/terminus/golden/ast.golden
new file mode 100644 (file)
index 0000000..6619f5c
--- /dev/null
@@ -0,0 +1,281 @@
+Project
+  [ Project
+      [ Unit
+          [ FunctionDeclaration
+              { functionBang = True
+              , functionName = "s:escape"
+              , functionArguments = ArgumentList [ Argument "string" ]
+              , functionAttributes = [ "abort" ]
+              , functionBody =
+                  [ GenericStatement
+                      "return substitute(a:string, \"\\<Esc>\", \"\\<Esc>\\<Esc>\", 'g')"
+                  ]
+              }
+          , FunctionDeclaration
+              { functionBang = True
+              , functionName = "terminus#private#wrap"
+              , functionArguments = ArgumentList [ Argument "string" ]
+              , functionAttributes = [ "abort" ]
+              , functionBody =
+                  [ GenericStatement "if strlen(a:string) == 0"
+                  , GenericStatement "return ''"
+                  , GenericStatement "end"
+                  , LetStatement
+                      { letLexpr = "l:tmux_begin" , letValue = "\"\\<Esc>Ptmux;\"" }
+                  , LetStatement
+                      { letLexpr = "l:tmux_end" , letValue = "\"\\<Esc>\\\\\"" }
+                  , GenericStatement
+                      "return l:tmux_begin . s:escape(a:string) . l:tmux_end"
+                  ]
+              }
+          , FunctionDeclaration
+              { functionBang = True
+              , functionName = "terminus#private#focus_lost"
+              , functionArguments = ArgumentList []
+              , functionAttributes = [ "abort" ]
+              , functionBody =
+                  [ LetStatement
+                      { letLexpr = "l:cmdline" , letValue = "getcmdline()" }
+                  , LetStatement { letLexpr = "l:cmdpos" , letValue = "getcmdpos()" }
+                  , GenericStatement "silent doautocmd FocusLost %"
+                  , GenericStatement "call setcmdpos(l:cmdpos)"
+                  , GenericStatement "return l:cmdline"
+                  ]
+              }
+          , FunctionDeclaration
+              { functionBang = True
+              , functionName = "terminus#private#focus_gained"
+              , functionArguments = ArgumentList []
+              , functionAttributes = [ "abort" ]
+              , functionBody =
+                  [ LetStatement
+                      { letLexpr = "l:cmdline" , letValue = "getcmdline()" }
+                  , LetStatement { letLexpr = "l:cmdpos" , letValue = "getcmdpos()" }
+                  , GenericStatement "silent! doautocmd FocusGained %"
+                  , GenericStatement "call setcmdpos(l:cmdpos)"
+                  , GenericStatement "return l:cmdline"
+                  ]
+              }
+          , FunctionDeclaration
+              { functionBang = True
+              , functionName = "terminus#private#paste"
+              , functionArguments = ArgumentList [ Argument "ret" ]
+              , functionAttributes = [ "abort" ]
+              , functionBody =
+                  [ GenericStatement "set paste" , GenericStatement "return a:ret" ]
+              }
+          ]
+      , Unit
+          [ GenericStatement
+              "if exists('g:TerminusLoaded') || &compatible || v:version < 700"
+          , GenericStatement "finish"
+          , GenericStatement "endif"
+          , LetStatement { letLexpr = "g:TerminusLoaded" , letValue = "1" }
+          , LetStatement
+              { letLexpr = "s:cpoptions" , letValue = "&cpoptions" }
+          , GenericStatement "set cpoptions&vim"
+          , GenericStatement
+              "set autoread \" if not changed in Vim, automatically pick up changes after \"git checkout\" etc"
+          , GenericStatement
+              "if &ttimeoutlen == -1 && &timeoutlen > 50 || &ttimeoutlen > 50"
+          , GenericStatement
+              "set ttimeoutlen=50 \" speed up O etc in the Terminal"
+          , GenericStatement "endif"
+          , LetStatement
+              { letLexpr = "s:iterm" , letValue = "exists('$ITERM_PROFILE') ||" }
+          , GenericStatement
+              "\\ exists('$ITERM_SESSION_ID') || exists('$KONSOLE_DBUS_SESSION') || exists('$KONSOLE_PROFILE_NAME') || exists('g:TerminusAssumeITerm') || filereadable(expand('~/.vim/.assume-iterm'))"
+          , LetStatement
+              { letLexpr = "s:screenish"
+              , letValue = "&term =~# 'screen\\|tmux'"
+              }
+          , LetStatement
+              { letLexpr = "s:tmux" , letValue = "exists('$TMUX')" }
+          , LetStatement
+              { letLexpr = "s:xterm" , letValue = "&term =~# 'xterm'" }
+          , LetStatement
+              { letLexpr = "s:shape"
+              , letValue = "get(g:, 'TerminusCursorShape', 1)"
+              }
+          , GenericStatement "if s:shape"
+          , LetStatement
+              { letLexpr = "s:insert_shape"
+              , letValue = "+get(g:, 'TerminusInsertCursorShape', 1)"
+              }
+          , LetStatement
+              { letLexpr = "s:replace_shape"
+              , letValue = "+get(g:, 'TerminusReplaceCursorShape', 2)"
+              }
+          , LetStatement
+              { letLexpr = "s:normal_shape"
+              , letValue = "+get(g:, 'TerminusNormalCursorShape', 0)"
+              }
+          , GenericStatement "if s:iterm"
+          , LetStatement
+              { letLexpr = "s:start_insert"
+              , letValue =
+                  "\"\\<Esc>]50;CursorShape=\" . s:insert_shape . \"\\x7\""
+              }
+          , LetStatement
+              { letLexpr = "s:start_replace"
+              , letValue =
+                  "\"\\<Esc>]50;CursorShape=\" . s:replace_shape . \"\\x7\""
+              }
+          , LetStatement
+              { letLexpr = "s:end_insert"
+              , letValue =
+                  "\"\\<Esc>]50;CursorShape=\" . s:normal_shape . \"\\x7\""
+              }
+          , GenericStatement "else"
+          , LetStatement
+              { letLexpr = "s:cursor_shape_to_vte_shape"
+              , letValue = "{1: 6, 2: 4, 0: 2}"
+              }
+          , LetStatement
+              { letLexpr = "s:insert_shape"
+              , letValue = "s:cursor_shape_to_vte_shape[s:insert_shape]"
+              }
+          , LetStatement
+              { letLexpr = "s:replace_shape"
+              , letValue = "s:cursor_shape_to_vte_shape[s:replace_shape]"
+              }
+          , LetStatement
+              { letLexpr = "s:normal_shape"
+              , letValue = "s:cursor_shape_to_vte_shape[s:normal_shape]"
+              }
+          , LetStatement
+              { letLexpr = "s:start_insert"
+              , letValue = "\"\\<Esc>[\" . s:insert_shape . ' q'"
+              }
+          , LetStatement
+              { letLexpr = "s:start_replace"
+              , letValue = "\"\\<Esc>[\" . s:replace_shape . ' q'"
+              }
+          , LetStatement
+              { letLexpr = "s:end_insert"
+              , letValue = "\"\\<Esc>[\" . s:normal_shape . ' q'"
+              }
+          , GenericStatement "endif"
+          , GenericStatement "if s:tmux"
+          , LetStatement
+              { letLexpr = "s:start_insert"
+              , letValue = "terminus#private#wrap(s:start_insert)"
+              }
+          , LetStatement
+              { letLexpr = "s:start_replace"
+              , letValue = "terminus#private#wrap(s:start_replace)"
+              }
+          , LetStatement
+              { letLexpr = "s:end_insert"
+              , letValue = "terminus#private#wrap(s:end_insert)"
+              }
+          , GenericStatement "endif"
+          , LetStatement { letLexpr = "&t_SI" , letValue = "s:start_insert" }
+          , GenericStatement
+              "if v:version > 704 || v:version == 704 && has('patch687')"
+          , LetStatement
+              { letLexpr = "&t_SR" , letValue = "s:start_replace" }
+          , GenericStatement "end"
+          , LetStatement { letLexpr = "&t_EI" , letValue = "s:end_insert" }
+          , GenericStatement "endif"
+          , LetStatement
+              { letLexpr = "s:mouse" , letValue = "get(g:, 'TerminusMouse', 1)" }
+          , GenericStatement "if s:mouse"
+          , GenericStatement "if has('mouse')"
+          , GenericStatement "set mouse=a"
+          , GenericStatement "if s:screenish || s:xterm"
+          , GenericStatement "if !has('nvim')"
+          , GenericStatement "if has('mouse_sgr')"
+          , GenericStatement "set ttymouse=sgr"
+          , GenericStatement "else"
+          , GenericStatement "set ttymouse=xterm2"
+          , GenericStatement "endif"
+          , GenericStatement "endif"
+          , GenericStatement "endif"
+          , GenericStatement "endif"
+          , GenericStatement "endif"
+          , LetStatement
+              { letLexpr = "s:focus"
+              , letValue = "get(g:, 'TerminusFocusReporting', 1)"
+              }
+          , GenericStatement "if s:focus"
+          , GenericStatement "if has('autocmd')"
+          , GenericStatement "augroup Terminus"
+          , GenericStatement "autocmd!"
+          , GenericStatement "autocmd FocusGained * checktime"
+          , GenericStatement "augroup END"
+          , GenericStatement "endif"
+          , LetStatement
+              { letLexpr = "&t_ti." , letValue = "\"\\e[?1004h\"" }
+          , LetStatement
+              { letLexpr = "&t_te" , letValue = "\"\\e[?1004l\" . &t_te" }
+          , GenericStatement "execute \"set <f20>=\\<Esc>[O\""
+          , GenericStatement "execute \"set <f21>=\\<Esc>[I\""
+          , GenericStatement
+              "cnoremap <silent> <f20> <c-\\>eterminus#private#focus_lost()<cr>"
+          , GenericStatement
+              "cnoremap <silent> <f21> <c-\\>eterminus#private#focus_gained()<cr>"
+          , GenericStatement
+              "if v:version > 703 || v:version == 703 && has('patch438')"
+          , GenericStatement
+              "inoremap <silent> <f20> <c-o>:silent doautocmd <nomodeline> FocusLost %<cr>"
+          , GenericStatement
+              "inoremap <silent> <f21> <c-o>:silent doautocmd <nomodeline> FocusGained %<cr>"
+          , GenericStatement
+              "nnoremap <silent> <f20> :silent doautocmd <nomodeline> FocusLost %<cr>"
+          , GenericStatement
+              "nnoremap <silent> <f21> :silent doautocmd <nomodeline> FocusGained %<cr>"
+          , GenericStatement
+              "onoremap <silent> <f20> <Esc>:silent doautocmd <nomodeline> FocusLost %<cr>"
+          , GenericStatement
+              "onoremap <silent> <f21> <Esc>:silent doautocmd <nomodeline> FocusGained %<cr>"
+          , GenericStatement
+              "vnoremap <silent> <f20> <Esc>:silent doautocmd <nomodeline> FocusLost %<cr>gv"
+          , GenericStatement
+              "vnoremap <silent> <f21> <Esc>:silent doautocmd <nomodeline> FocusGained %<cr>gv"
+          , GenericStatement "else"
+          , GenericStatement
+              "inoremap <silent> <f20> <c-o>:silent doautocmd FocusLost %<cr>"
+          , GenericStatement
+              "inoremap <silent> <f21> <c-o>:silent doautocmd FocusGained %<cr>"
+          , GenericStatement
+              "nnoremap <silent> <f20> :silent doautocmd FocusLost %<cr>"
+          , GenericStatement
+              "nnoremap <silent> <f21> :silent doautocmd FocusGained %<cr>"
+          , GenericStatement
+              "onoremap <silent> <f20> <Esc>:silent doautocmd FocusLost %<cr>"
+          , GenericStatement
+              "onoremap <silent> <f21> <Esc>:silent doautocmd FocusGained %<cr>"
+          , GenericStatement
+              "vnoremap <silent> <f20> <Esc>:silent doautocmd FocusLost %<cr>gv"
+          , GenericStatement
+              "vnoremap <silent> <f21> <Esc>:silent doautocmd FocusGained %<cr>gv"
+          , GenericStatement "endif"
+          , GenericStatement "endif"
+          , LetStatement
+              { letLexpr = "s:paste"
+              , letValue = "get(g:, 'TerminusBracketedPaste', 1)"
+              }
+          , GenericStatement "if s:paste"
+          , GenericStatement "if s:screenish || s:xterm"
+          , LetStatement
+              { letLexpr = "&t_ti." , letValue = "\"\\e[?2004h\"" }
+          , LetStatement
+              { letLexpr = "&t_te" , letValue = "\"\\e[?2004l\" . &t_te" }
+          , GenericStatement "set pastetoggle=<Esc>[201~"
+          , GenericStatement
+              "inoremap <expr> <Esc>[200~ terminus#private#paste('')"
+          , GenericStatement
+              "nnoremap <expr> <Esc>[200~ terminus#private#paste('i')"
+          , GenericStatement
+              "vnoremap <expr> <Esc>[200~ terminus#private#paste('c')"
+          , GenericStatement "cnoremap <Esc>[200~ <nop>"
+          , GenericStatement "cnoremap <Esc>[201~ <nop>"
+          , GenericStatement "endif"
+          , GenericStatement "endif"
+          , LetStatement
+              { letLexpr = "&cpoptions" , letValue = "s:cpoptions" }
+          , UnletStatement { unletBang = False , unletBody = "s:cpoptions" }
+          ]
+      ]
+  ]
diff --git a/tests/fixtures/integration/terminus/golden/markdown.golden b/tests/fixtures/integration/terminus/golden/markdown.golden
new file mode 100644 (file)
index 0000000..8b13789
--- /dev/null
@@ -0,0 +1 @@
+
diff --git a/tests/fixtures/integration/terminus/golden/plaintext.golden b/tests/fixtures/integration/terminus/golden/plaintext.golden
new file mode 100644 (file)
index 0000000..8b13789
--- /dev/null
@@ -0,0 +1 @@
+
diff --git a/tests/fixtures/integration/terminus/input/.gitignore b/tests/fixtures/integration/terminus/input/.gitignore
new file mode 100644 (file)
index 0000000..20cb71e
--- /dev/null
@@ -0,0 +1 @@
+/*.zip
diff --git a/tests/fixtures/integration/terminus/input/LICENSE.txt b/tests/fixtures/integration/terminus/input/LICENSE.txt
new file mode 100644 (file)
index 0000000..3906829
--- /dev/null
@@ -0,0 +1,22 @@
+Copyright 2015-present Greg Hurrell. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice,
+   this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright notice,
+   this list of conditions and the following disclaimer in the documentation
+   and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
diff --git a/tests/fixtures/integration/terminus/input/autoload/terminus/private.vim b/tests/fixtures/integration/terminus/input/autoload/terminus/private.vim
new file mode 100644 (file)
index 0000000..f7f969e
--- /dev/null
@@ -0,0 +1,45 @@
+" Copyright 2015-present Greg Hurrell. All rights reserved.
+" Licensed under the terms of the BSD 2-clause license.
+
+function! s:escape(string) abort
+  " Double each <Esc>.
+  return substitute(a:string, "\<Esc>", "\<Esc>\<Esc>", 'g')
+endfunction
+
+function! terminus#private#wrap(string) abort
+  if strlen(a:string) == 0
+    return ''
+  end
+
+  let l:tmux_begin="\<Esc>Ptmux;"
+  let l:tmux_end="\<Esc>\\"
+
+  return l:tmux_begin . s:escape(a:string) . l:tmux_end
+endfunction
+
+function! terminus#private#focus_lost() abort
+  let l:cmdline=getcmdline()
+  let l:cmdpos=getcmdpos()
+
+  silent doautocmd FocusLost %
+
+  call setcmdpos(l:cmdpos)
+  return l:cmdline
+endfunction
+
+function! terminus#private#focus_gained() abort
+  let l:cmdline=getcmdline()
+  let l:cmdpos=getcmdpos()
+
+  " Our checktime autocmd will produce:
+  "   E523: Not allowed here:   checktime
+  silent! doautocmd FocusGained %
+
+  call setcmdpos(l:cmdpos)
+  return l:cmdline
+endfunction
+
+function! terminus#private#paste(ret) abort
+  set paste
+  return a:ret
+endfunction
diff --git a/tests/fixtures/integration/terminus/input/plugin/terminus.vim b/tests/fixtures/integration/terminus/input/plugin/terminus.vim
new file mode 100644 (file)
index 0000000..878bab0
--- /dev/null
@@ -0,0 +1,144 @@
+" Copyright 2015-present Greg Hurrell. All rights reserved.
+" Licensed under the terms of the BSD 2-clause license.
+
+" Provide users with means to prevent loading, as recommended in `:h
+" write-plugin`.
+if exists('g:TerminusLoaded') || &compatible || v:version < 700
+  finish
+endif
+let g:TerminusLoaded=1
+
+" Temporarily set 'cpoptions' to Vim default as per `:h use-cpo-save`.
+let s:cpoptions=&cpoptions
+set cpoptions&vim
+
+set autoread " if not changed in Vim, automatically pick up changes after "git checkout" etc
+if &ttimeoutlen == -1 && &timeoutlen > 50 || &ttimeoutlen > 50
+  set ttimeoutlen=50 " speed up O etc in the Terminal
+endif
+
+let s:iterm=
+      \ exists('$ITERM_PROFILE') ||
+      \ exists('$ITERM_SESSION_ID') ||
+      \ exists('$KONSOLE_DBUS_SESSION') ||
+      \ exists('$KONSOLE_PROFILE_NAME') ||
+      \ exists('g:TerminusAssumeITerm') ||
+      \ filereadable(expand('~/.vim/.assume-iterm'))
+let s:screenish=&term =~# 'screen\|tmux'
+let s:tmux=exists('$TMUX')
+let s:xterm=&term =~# 'xterm'
+
+" Change shape of cursor in insert mode in iTerm 2.
+let s:shape=get(g:, 'TerminusCursorShape', 1)
+if s:shape
+  let s:insert_shape=+get(g:, 'TerminusInsertCursorShape', 1)
+  let s:replace_shape=+get(g:, 'TerminusReplaceCursorShape', 2)
+  let s:normal_shape=+get(g:, 'TerminusNormalCursorShape', 0)
+  if s:iterm
+    let s:start_insert="\<Esc>]50;CursorShape=" . s:insert_shape . "\x7"
+    let s:start_replace="\<Esc>]50;CursorShape=" . s:replace_shape . "\x7"
+    let s:end_insert="\<Esc>]50;CursorShape=" . s:normal_shape . "\x7"
+  else
+    let s:cursor_shape_to_vte_shape={1: 6, 2: 4, 0: 2}
+    let s:insert_shape=s:cursor_shape_to_vte_shape[s:insert_shape]
+    let s:replace_shape=s:cursor_shape_to_vte_shape[s:replace_shape]
+    let s:normal_shape=s:cursor_shape_to_vte_shape[s:normal_shape]
+    let s:start_insert="\<Esc>[" . s:insert_shape . ' q'
+    let s:start_replace="\<Esc>[" . s:replace_shape . ' q'
+    let s:end_insert="\<Esc>[" . s:normal_shape . ' q'
+  endif
+
+  if s:tmux
+    let s:start_insert=terminus#private#wrap(s:start_insert)
+    let s:start_replace=terminus#private#wrap(s:start_replace)
+    let s:end_insert=terminus#private#wrap(s:end_insert)
+  endif
+
+  let &t_SI=s:start_insert
+  if v:version > 704 || v:version == 704 && has('patch687')
+    let &t_SR=s:start_replace
+  end
+  let &t_EI=s:end_insert
+endif
+
+let s:mouse=get(g:, 'TerminusMouse', 1)
+if s:mouse
+  if has('mouse')
+    set mouse=a
+    if s:screenish || s:xterm
+      if !has('nvim')
+        if has('mouse_sgr')
+          set ttymouse=sgr
+        else
+          set ttymouse=xterm2
+        endif
+      endif
+    endif
+  endif
+endif
+
+let s:focus=get(g:, 'TerminusFocusReporting', 1)
+if s:focus
+  if has('autocmd')
+    augroup Terminus
+      autocmd!
+      autocmd FocusGained * checktime
+    augroup END
+  endif
+
+  " Enable focus reporting on entering Vim.
+  let &t_ti.="\e[?1004h"
+  " Disable focus reporting on leaving Vim.
+  let &t_te="\e[?1004l" . &t_te
+
+  execute "set <f20>=\<Esc>[O"
+  execute "set <f21>=\<Esc>[I"
+  cnoremap <silent> <f20> <c-\>eterminus#private#focus_lost()<cr>
+  cnoremap <silent> <f21> <c-\>eterminus#private#focus_gained()<cr>
+
+  if v:version > 703 || v:version == 703 && has('patch438')
+    " <nomodeline> was added in 7.3.438 (see `:h version7.txt`).
+    inoremap <silent> <f20> <c-o>:silent doautocmd <nomodeline> FocusLost %<cr>
+    inoremap <silent> <f21> <c-o>:silent doautocmd <nomodeline> FocusGained %<cr>
+    nnoremap <silent> <f20> :silent doautocmd <nomodeline> FocusLost %<cr>
+    nnoremap <silent> <f21> :silent doautocmd <nomodeline> FocusGained %<cr>
+    onoremap <silent> <f20> <Esc>:silent doautocmd <nomodeline> FocusLost %<cr>
+    onoremap <silent> <f21> <Esc>:silent doautocmd <nomodeline> FocusGained %<cr>
+    vnoremap <silent> <f20> <Esc>:silent doautocmd <nomodeline> FocusLost %<cr>gv
+    vnoremap <silent> <f21> <Esc>:silent doautocmd <nomodeline> FocusGained %<cr>gv
+  else
+    inoremap <silent> <f20> <c-o>:silent doautocmd FocusLost %<cr>
+    inoremap <silent> <f21> <c-o>:silent doautocmd FocusGained %<cr>
+    nnoremap <silent> <f20> :silent doautocmd FocusLost %<cr>
+    nnoremap <silent> <f21> :silent doautocmd FocusGained %<cr>
+    onoremap <silent> <f20> <Esc>:silent doautocmd FocusLost %<cr>
+    onoremap <silent> <f21> <Esc>:silent doautocmd FocusGained %<cr>
+    vnoremap <silent> <f20> <Esc>:silent doautocmd FocusLost %<cr>gv
+    vnoremap <silent> <f21> <Esc>:silent doautocmd FocusGained %<cr>gv
+  endif
+endif
+
+let s:paste=get(g:, 'TerminusBracketedPaste', 1)
+if s:paste
+  " Make use of Xterm "bracketed paste mode". See:
+  "  - http://www.xfree86.org/current/ctlseqs.html#Bracketed%20Paste%20Mode
+  "  - http://stackoverflow.com/questions/5585129
+  if s:screenish || s:xterm
+    " Enable bracketed paste mode on entering Vim.
+    let &t_ti.="\e[?2004h"
+
+    " Disable bracketed paste mode on leaving Vim.
+    let &t_te="\e[?2004l" . &t_te
+
+    set pastetoggle=<Esc>[201~
+    inoremap <expr> <Esc>[200~ terminus#private#paste('')
+    nnoremap <expr> <Esc>[200~ terminus#private#paste('i')
+    vnoremap <expr> <Esc>[200~ terminus#private#paste('c')
+    cnoremap <Esc>[200~ <nop>
+    cnoremap <Esc>[201~ <nop>
+  endif
+endif
+
+" Restore 'cpoptions' to its former value.
+let &cpoptions=s:cpoptions
+unlet s:cpoptions