docs: def update_subchannel_msgs(debug=False, force=False):
      """
      Grab any pending messages and place them inside the vim-ipython shell.
      This function will do nothing if the vim-ipython shell is not visible,
      unless force=True argument is passed.
      """
      if kc is None or (not vim_ipython_is_open() and not force):
          return False
      msgs = kc.iopub_channel.get_msgs()
      b = vim.current.buffer
      startedin_vimipython = vim.eval('@%')=='vim-ipython'
      if not startedin_vimipython:
          # switch to preview window
          vim.command(
              "try"
              "|silent! wincmd P"
              "|catch /^Vim\%((\a\+)\)\=:E441/"
              "|silent pedit +set\ ma vim-ipython"
              "|silent! wincmd P"
              "|endtry")
          # if the current window is called 'vim-ipython'
          if vim.eval('@%')=='vim-ipython':
              # set the preview window height to the current height
              vim.command("set pvh=" + vim.eval('winheight(0)'))
          else:
              # close preview window, it was something other than 'vim-ipython'
              vim.command("pcl")
              vim.command("silent pedit +set\ ma vim-ipython")
              vim.command("wincmd P") #switch to preview window
              # subchannel window quick quit key 'q'
              vim.command('nnoremap <buffer> q :q<CR>')
              vim.command("set bufhidden=hide buftype=nofile ft=python")
              vim.command("setlocal nobuflisted") # don't come up in buffer lists
              vim.command("setlocal nonumber") # no line numbers, we have in/out nums
              vim.command("setlocal noswapfile") # no swap file (so no complaints cross-instance)
              # make shift-enter and control-enter in insert mode behave same as in ipython notebook
              # shift-enter send the current line, control-enter send the line
              # but keeps it around for further editing.
              vim.command("inoremap <buffer> <s-Enter> <esc>dd:python run_command('''<C-r>\"''')<CR>i")
              # pkddA: paste, go up one line which is blank after run_command,
              # delete it, and then back to insert mode
              vim.command("inoremap <buffer> <c-Enter> <esc>dd:python run_command('''<C-r>\"''')<CR>pkddA")
              # ctrl-C gets sent to the IPython process as a signal on POSIX
              vim.command("noremap <buffer>  :IPythonInterrupt<cr>")
  
      #syntax highlighting for python prompt
      # QtConsole In[] is blue, but I prefer the oldschool green
      # since it makes the vim-ipython 'shell' look like the holidays!
      colors = status_prompt_colors
      vim.command("hi IPyPromptIn ctermfg=%s guifg=%s" % (colors['in_ctermfg'], colors['in_guifg']))
      vim.command("hi IPyPromptOut ctermfg=%s guifg=%s" % (colors['out_ctermfg'], colors['out_guifg']))
      vim.command("hi IPyPromptOut2 ctermfg=%s guifg=%s" % (colors['out2_ctermfg'], colors['out2_guifg']))
      in_expression = vim_regex_escape(status_prompt_in % {'line': 999}).replace('999', '[ 0-9]*')
      vim.command("syn match IPyPromptIn /^%s/" % in_expression)
      out_expression = vim_regex_escape(status_prompt_out % {'line': 999}).replace('999', '[ 0-9]*')
      vim.command("syn match IPyPromptOut /^%s/" % out_expression)
      vim.command("syn match IPyPromptOut2 /^\\.\\.\\.* /")
      b = vim.current.buffer
      update_occured = False
      for m in msgs:
          s = ''
          if 'msg_type' not in m['header']:
              # debug information
              #echo('skipping a message on sub_channel','WarningMsg')
              #echo(str(m))
              continue
          header = m['header']['msg_type']
          if header == 'status':
              continue
          elif header == 'stream':
              # TODO: alllow for distinguishing between stdout and stderr (using
              # custom syntax markers in the vim-ipython buffer perhaps), or by
              # also echoing the message to the status bar
              try:
                  s = strip_color_escapes(m['content']['data'])
              except KeyError:    # changed in IPython 3.0.0
                  s = strip_color_escapes(m['content']['text'])
          elif header == 'pyout' or header == 'execute_result':
              s = status_prompt_out % {'line': m['content']['execution_count']}
              s += m['content']['data']['text/plain']
          elif header == 'display_data':
              # TODO: handle other display data types (HMTL? images?)
              # Modified by BoPeng
              if 'text/plain' in m['content']['data']:
                  s += m['content']['data']['text/plain']
              elif 'text/markdown' in m['content']['data']:
                  s += m['content']['data']['text/markdown']
              elif 'text/html' in m['content']['data']:
                  s += dehtml(m['content']['data']['text/html'])
          elif header == 'pyin' or header == 'execute_input':
              # TODO: the next line allows us to resend a line to ipython if
              # %doctest_mode is on. In the future, IPython will send the
              # execution_count on subchannel, so this will need to be updated
              # once that happens
              line_number = m['content'].get('execution_count', 0)
              prompt = status_prompt_in % {'line': line_number}
              s = prompt
              # add a continuation line (with trailing spaces if the prompt has them)
              dots = '.' * len(prompt.rstrip())
              dots += prompt[len(prompt.rstrip()):]
              s += m['content']['code'].rstrip().replace('\n', '\n' + dots)
          elif header == 'pyerr' or header == 'error':
              c = m['content']
              s = "\n".join(map(strip_color_escapes,c['traceback']))
              s += c['ename'] + ":" + c['evalue']
  
          if s.find('\n') == -1:
              # somewhat ugly unicode workaround from
              # http://vim.1045645.n5.nabble.com/Limitations-of-vim-python-interface-with-respect-to-character-encodings-td1223881.html
              if isinstance(s,unicode):
                  s=s.encode(vim_encoding)
              b.append(s)
          else:
              try:
                  b.append(s.splitlines())
              except Exception:
                  b.append([l.encode(vim_encoding) for l in s.splitlines()])
          update_occured = True
      # make a newline so we can just start typing there
      if status_blank_lines:
          if b[-1] != '':
              b.append([''])
      if update_occured or force:
          vim.command('normal! G') # go to the end of the file
      if not startedin_vimipython:
          vim.command('normal! p') # go back to where you were
      return update_occured