Karsten Hopp 5bdf71
To: vim_dev@googlegroups.com
Karsten Hopp 5bdf71
Subject: Patch 7.4.852
Karsten Hopp 5bdf71
Fcc: outbox
Karsten Hopp 5bdf71
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 5bdf71
Mime-Version: 1.0
Karsten Hopp 5bdf71
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 5bdf71
Content-Transfer-Encoding: 8bit
Karsten Hopp 5bdf71
------------
Karsten Hopp 5bdf71
Karsten Hopp 5bdf71
Patch 7.4.852
Karsten Hopp 5bdf71
Problem:    On MS-Windows console Vim uses ANSI APIs for keyboard input and
Karsten Hopp 5bdf71
            console output, it cannot input/output Unicode characters.
Karsten Hopp 5bdf71
Solution:   Use Unicode APIs for console I/O. (Ken Takata, Yasuhiro Matsumoto)
Karsten Hopp 5bdf71
Files:      src/os_win32.c, src/ui.c, runtime/doc/options.txt
Karsten Hopp 5bdf71
Karsten Hopp 5bdf71
Karsten Hopp 5bdf71
*** ../vim-7.4.851/src/os_win32.c	2015-09-01 20:23:30.408603580 +0200
Karsten Hopp 5bdf71
--- src/os_win32.c	2015-09-01 20:28:43.193363546 +0200
Karsten Hopp 5bdf71
***************
Karsten Hopp 5bdf71
*** 213,220 ****
Karsten Hopp 5bdf71
  static void standend(void);
Karsten Hopp 5bdf71
  static void visual_bell(void);
Karsten Hopp 5bdf71
  static void cursor_visible(BOOL fVisible);
Karsten Hopp 5bdf71
! static BOOL write_chars(LPCSTR pchBuf, DWORD cchToWrite);
Karsten Hopp 5bdf71
! static char_u tgetch(int *pmodifiers, char_u *pch2);
Karsten Hopp 5bdf71
  static void create_conin(void);
Karsten Hopp 5bdf71
  static int s_cursor_visible = TRUE;
Karsten Hopp 5bdf71
  static int did_create_conin = FALSE;
Karsten Hopp 5bdf71
--- 213,220 ----
Karsten Hopp 5bdf71
  static void standend(void);
Karsten Hopp 5bdf71
  static void visual_bell(void);
Karsten Hopp 5bdf71
  static void cursor_visible(BOOL fVisible);
Karsten Hopp 5bdf71
! static DWORD write_chars(char_u *pchBuf, DWORD cbToWrite);
Karsten Hopp 5bdf71
! static WCHAR tgetch(int *pmodifiers, WCHAR *pch2);
Karsten Hopp 5bdf71
  static void create_conin(void);
Karsten Hopp 5bdf71
  static int s_cursor_visible = TRUE;
Karsten Hopp 5bdf71
  static int did_create_conin = FALSE;
Karsten Hopp 5bdf71
***************
Karsten Hopp 5bdf71
*** 265,279 ****
Karsten Hopp 5bdf71
      if (!win8_or_later)
Karsten Hopp 5bdf71
      {
Karsten Hopp 5bdf71
  	if (nLength == -1)
Karsten Hopp 5bdf71
! 	    return PeekConsoleInput(hInput, lpBuffer, 1, lpEvents);
Karsten Hopp 5bdf71
! 	return ReadConsoleInput(hInput, lpBuffer, 1, &dwEvents);
Karsten Hopp 5bdf71
      }
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
      if (s_dwMax == 0)
Karsten Hopp 5bdf71
      {
Karsten Hopp 5bdf71
  	if (nLength == -1)
Karsten Hopp 5bdf71
! 	    return PeekConsoleInput(hInput, lpBuffer, 1, lpEvents);
Karsten Hopp 5bdf71
! 	if (!ReadConsoleInput(hInput, s_irCache, IRSIZE, &dwEvents))
Karsten Hopp 5bdf71
  	    return FALSE;
Karsten Hopp 5bdf71
  	s_dwIndex = 0;
Karsten Hopp 5bdf71
  	s_dwMax = dwEvents;
Karsten Hopp 5bdf71
--- 265,279 ----
Karsten Hopp 5bdf71
      if (!win8_or_later)
Karsten Hopp 5bdf71
      {
Karsten Hopp 5bdf71
  	if (nLength == -1)
Karsten Hopp 5bdf71
! 	    return PeekConsoleInputW(hInput, lpBuffer, 1, lpEvents);
Karsten Hopp 5bdf71
! 	return ReadConsoleInputW(hInput, lpBuffer, 1, &dwEvents);
Karsten Hopp 5bdf71
      }
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
      if (s_dwMax == 0)
Karsten Hopp 5bdf71
      {
Karsten Hopp 5bdf71
  	if (nLength == -1)
Karsten Hopp 5bdf71
! 	    return PeekConsoleInputW(hInput, lpBuffer, 1, lpEvents);
Karsten Hopp 5bdf71
! 	if (!ReadConsoleInputW(hInput, s_irCache, IRSIZE, &dwEvents))
Karsten Hopp 5bdf71
  	    return FALSE;
Karsten Hopp 5bdf71
  	s_dwIndex = 0;
Karsten Hopp 5bdf71
  	s_dwMax = dwEvents;
Karsten Hopp 5bdf71
***************
Karsten Hopp 5bdf71
*** 868,876 ****
Karsten Hopp 5bdf71
  #endif
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
  #if defined(__GNUC__) && !defined(__MINGW32__)  && !defined(__CYGWIN__)
Karsten Hopp 5bdf71
! # define AChar AsciiChar
Karsten Hopp 5bdf71
  #else
Karsten Hopp 5bdf71
! # define AChar uChar.AsciiChar
Karsten Hopp 5bdf71
  #endif
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
  /* The return code indicates key code size. */
Karsten Hopp 5bdf71
--- 868,876 ----
Karsten Hopp 5bdf71
  #endif
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
  #if defined(__GNUC__) && !defined(__MINGW32__)  && !defined(__CYGWIN__)
Karsten Hopp 5bdf71
! # define UChar UnicodeChar
Karsten Hopp 5bdf71
  #else
Karsten Hopp 5bdf71
! # define UChar uChar.UnicodeChar
Karsten Hopp 5bdf71
  #endif
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
  /* The return code indicates key code size. */
Karsten Hopp 5bdf71
***************
Karsten Hopp 5bdf71
*** 889,900 ****
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
      if (s_iIsDead == 2)
Karsten Hopp 5bdf71
      {
Karsten Hopp 5bdf71
! 	pker->AChar = (CHAR) awAnsiCode[1];
Karsten Hopp 5bdf71
  	s_iIsDead = 0;
Karsten Hopp 5bdf71
  	return 1;
Karsten Hopp 5bdf71
      }
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
!     if (pker->AChar != 0)
Karsten Hopp 5bdf71
  	return 1;
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
      vim_memset(abKeystate, 0, sizeof (abKeystate));
Karsten Hopp 5bdf71
--- 889,900 ----
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
      if (s_iIsDead == 2)
Karsten Hopp 5bdf71
      {
Karsten Hopp 5bdf71
! 	pker->UChar = (WCHAR) awAnsiCode[1];
Karsten Hopp 5bdf71
  	s_iIsDead = 0;
Karsten Hopp 5bdf71
  	return 1;
Karsten Hopp 5bdf71
      }
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
!     if (pker->UChar != 0)
Karsten Hopp 5bdf71
  	return 1;
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
      vim_memset(abKeystate, 0, sizeof (abKeystate));
Karsten Hopp 5bdf71
***************
Karsten Hopp 5bdf71
*** 909,915 ****
Karsten Hopp 5bdf71
      }
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
      /* Clear any pending dead keys */
Karsten Hopp 5bdf71
!     ToAscii(VK_SPACE, MapVirtualKey(VK_SPACE, 0), abKeystate, awAnsiCode, 0);
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
      if (uMods & SHIFT_PRESSED)
Karsten Hopp 5bdf71
  	abKeystate[VK_SHIFT] = 0x80;
Karsten Hopp 5bdf71
--- 909,915 ----
Karsten Hopp 5bdf71
      }
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
      /* Clear any pending dead keys */
Karsten Hopp 5bdf71
!     ToUnicode(VK_SPACE, MapVirtualKey(VK_SPACE, 0), abKeystate, awAnsiCode, 2, 0);
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
      if (uMods & SHIFT_PRESSED)
Karsten Hopp 5bdf71
  	abKeystate[VK_SHIFT] = 0x80;
Karsten Hopp 5bdf71
***************
Karsten Hopp 5bdf71
*** 922,932 ****
Karsten Hopp 5bdf71
  	    abKeystate[VK_MENU] = abKeystate[VK_RMENU] = 0x80;
Karsten Hopp 5bdf71
      }
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
!     s_iIsDead = ToAscii(pker->wVirtualKeyCode, pker->wVirtualScanCode,
Karsten Hopp 5bdf71
! 			abKeystate, awAnsiCode, 0);
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
      if (s_iIsDead > 0)
Karsten Hopp 5bdf71
! 	pker->AChar = (CHAR) awAnsiCode[0];
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
      return s_iIsDead;
Karsten Hopp 5bdf71
  }
Karsten Hopp 5bdf71
--- 922,932 ----
Karsten Hopp 5bdf71
  	    abKeystate[VK_MENU] = abKeystate[VK_RMENU] = 0x80;
Karsten Hopp 5bdf71
      }
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
!     s_iIsDead = ToUnicode(pker->wVirtualKeyCode, pker->wVirtualScanCode,
Karsten Hopp 5bdf71
! 			abKeystate, awAnsiCode, 2, 0);
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
      if (s_iIsDead > 0)
Karsten Hopp 5bdf71
! 	pker->UChar = (WCHAR) awAnsiCode[0];
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
      return s_iIsDead;
Karsten Hopp 5bdf71
  }
Karsten Hopp 5bdf71
***************
Karsten Hopp 5bdf71
*** 953,960 ****
Karsten Hopp 5bdf71
      static BOOL
Karsten Hopp 5bdf71
  decode_key_event(
Karsten Hopp 5bdf71
      KEY_EVENT_RECORD	*pker,
Karsten Hopp 5bdf71
!     char_u		*pch,
Karsten Hopp 5bdf71
!     char_u		*pch2,
Karsten Hopp 5bdf71
      int			*pmodifiers,
Karsten Hopp 5bdf71
      BOOL		fDoPost)
Karsten Hopp 5bdf71
  {
Karsten Hopp 5bdf71
--- 953,960 ----
Karsten Hopp 5bdf71
      static BOOL
Karsten Hopp 5bdf71
  decode_key_event(
Karsten Hopp 5bdf71
      KEY_EVENT_RECORD	*pker,
Karsten Hopp 5bdf71
!     WCHAR		*pch,
Karsten Hopp 5bdf71
!     WCHAR		*pch2,
Karsten Hopp 5bdf71
      int			*pmodifiers,
Karsten Hopp 5bdf71
      BOOL		fDoPost)
Karsten Hopp 5bdf71
  {
Karsten Hopp 5bdf71
***************
Karsten Hopp 5bdf71
*** 982,988 ****
Karsten Hopp 5bdf71
      }
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
      /* special cases */
Karsten Hopp 5bdf71
!     if ((nModifs & CTRL) != 0 && (nModifs & ~CTRL) == 0 && pker->AChar == NUL)
Karsten Hopp 5bdf71
      {
Karsten Hopp 5bdf71
  	/* Ctrl-6 is Ctrl-^ */
Karsten Hopp 5bdf71
  	if (pker->wVirtualKeyCode == '6')
Karsten Hopp 5bdf71
--- 982,988 ----
Karsten Hopp 5bdf71
      }
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
      /* special cases */
Karsten Hopp 5bdf71
!     if ((nModifs & CTRL) != 0 && (nModifs & ~CTRL) == 0 && pker->UChar == NUL)
Karsten Hopp 5bdf71
      {
Karsten Hopp 5bdf71
  	/* Ctrl-6 is Ctrl-^ */
Karsten Hopp 5bdf71
  	if (pker->wVirtualKeyCode == '6')
Karsten Hopp 5bdf71
***************
Karsten Hopp 5bdf71
*** 1044,1050 ****
Karsten Hopp 5bdf71
  	*pch = NUL;
Karsten Hopp 5bdf71
      else
Karsten Hopp 5bdf71
      {
Karsten Hopp 5bdf71
! 	*pch = (i > 0) ? pker->AChar : NUL;
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
  	if (pmodifiers != NULL)
Karsten Hopp 5bdf71
  	{
Karsten Hopp 5bdf71
--- 1044,1050 ----
Karsten Hopp 5bdf71
  	*pch = NUL;
Karsten Hopp 5bdf71
      else
Karsten Hopp 5bdf71
      {
Karsten Hopp 5bdf71
! 	*pch = (i > 0) ? pker->UChar : NUL;
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
  	if (pmodifiers != NULL)
Karsten Hopp 5bdf71
  	{
Karsten Hopp 5bdf71
***************
Karsten Hopp 5bdf71
*** 1436,1442 ****
Karsten Hopp 5bdf71
      DWORD	    dwNow = 0, dwEndTime = 0;
Karsten Hopp 5bdf71
      INPUT_RECORD    ir;
Karsten Hopp 5bdf71
      DWORD	    cRecords;
Karsten Hopp 5bdf71
!     char_u	    ch, ch2;
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
      if (msec > 0)
Karsten Hopp 5bdf71
  	/* Wait until the specified time has elapsed. */
Karsten Hopp 5bdf71
--- 1436,1442 ----
Karsten Hopp 5bdf71
      DWORD	    dwNow = 0, dwEndTime = 0;
Karsten Hopp 5bdf71
      INPUT_RECORD    ir;
Karsten Hopp 5bdf71
      DWORD	    cRecords;
Karsten Hopp 5bdf71
!     WCHAR	    ch, ch2;
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
      if (msec > 0)
Karsten Hopp 5bdf71
  	/* Wait until the specified time has elapsed. */
Karsten Hopp 5bdf71
***************
Karsten Hopp 5bdf71
*** 1523,1529 ****
Karsten Hopp 5bdf71
  #ifdef FEAT_MBYTE_IME
Karsten Hopp 5bdf71
  		/* Windows IME sends two '\n's with only one 'ENTER'.  First:
Karsten Hopp 5bdf71
  		 * wVirtualKeyCode == 13. second: wVirtualKeyCode == 0 */
Karsten Hopp 5bdf71
! 		if (ir.Event.KeyEvent.uChar.UnicodeChar == 0
Karsten Hopp 5bdf71
  			&& ir.Event.KeyEvent.wVirtualKeyCode == 13)
Karsten Hopp 5bdf71
  		{
Karsten Hopp 5bdf71
  		    read_console_input(g_hConIn, &ir, 1, &cRecords);
Karsten Hopp 5bdf71
--- 1523,1529 ----
Karsten Hopp 5bdf71
  #ifdef FEAT_MBYTE_IME
Karsten Hopp 5bdf71
  		/* Windows IME sends two '\n's with only one 'ENTER'.  First:
Karsten Hopp 5bdf71
  		 * wVirtualKeyCode == 13. second: wVirtualKeyCode == 0 */
Karsten Hopp 5bdf71
! 		if (ir.Event.KeyEvent.UChar == 0
Karsten Hopp 5bdf71
  			&& ir.Event.KeyEvent.wVirtualKeyCode == 13)
Karsten Hopp 5bdf71
  		{
Karsten Hopp 5bdf71
  		    read_console_input(g_hConIn, &ir, 1, &cRecords);
Karsten Hopp 5bdf71
***************
Karsten Hopp 5bdf71
*** 1586,1595 ****
Karsten Hopp 5bdf71
  /*
Karsten Hopp 5bdf71
   * Get a keystroke or a mouse event
Karsten Hopp 5bdf71
   */
Karsten Hopp 5bdf71
!     static char_u
Karsten Hopp 5bdf71
! tgetch(int *pmodifiers, char_u *pch2)
Karsten Hopp 5bdf71
  {
Karsten Hopp 5bdf71
!     char_u ch;
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
      for (;;)
Karsten Hopp 5bdf71
      {
Karsten Hopp 5bdf71
--- 1586,1595 ----
Karsten Hopp 5bdf71
  /*
Karsten Hopp 5bdf71
   * Get a keystroke or a mouse event
Karsten Hopp 5bdf71
   */
Karsten Hopp 5bdf71
!     static WCHAR
Karsten Hopp 5bdf71
! tgetch(int *pmodifiers, WCHAR *pch2)
Karsten Hopp 5bdf71
  {
Karsten Hopp 5bdf71
!     WCHAR ch;
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
      for (;;)
Karsten Hopp 5bdf71
      {
Karsten Hopp 5bdf71
***************
Karsten Hopp 5bdf71
*** 1658,1668 ****
Karsten Hopp 5bdf71
  #define TYPEAHEADLEN 20
Karsten Hopp 5bdf71
      static char_u   typeahead[TYPEAHEADLEN];	/* previously typed bytes. */
Karsten Hopp 5bdf71
      static int	    typeaheadlen = 0;
Karsten Hopp 5bdf71
- #ifdef FEAT_MBYTE
Karsten Hopp 5bdf71
-     static char_u   *rest = NULL;	/* unconverted rest of previous read */
Karsten Hopp 5bdf71
-     static int	    restlen = 0;
Karsten Hopp 5bdf71
-     int		    unconverted;
Karsten Hopp 5bdf71
- #endif
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
      /* First use any typeahead that was kept because "buf" was too small. */
Karsten Hopp 5bdf71
      if (typeaheadlen > 0)
Karsten Hopp 5bdf71
--- 1658,1663 ----
Karsten Hopp 5bdf71
***************
Karsten Hopp 5bdf71
*** 1761,1798 ****
Karsten Hopp 5bdf71
  	else
Karsten Hopp 5bdf71
  #endif
Karsten Hopp 5bdf71
  	{
Karsten Hopp 5bdf71
! 	    char_u	ch2 = NUL;
Karsten Hopp 5bdf71
  	    int		modifiers = 0;
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
  	    c = tgetch(&modifiers, &ch2;;
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
- #ifdef FEAT_MBYTE
Karsten Hopp 5bdf71
- 	    /* stolen from fill_input_buf() in ui.c */
Karsten Hopp 5bdf71
- 	    if (rest != NULL)
Karsten Hopp 5bdf71
- 	    {
Karsten Hopp 5bdf71
- 		/* Use remainder of previous call, starts with an invalid
Karsten Hopp 5bdf71
- 		 * character that may become valid when reading more. */
Karsten Hopp 5bdf71
- 		if (restlen > TYPEAHEADLEN - typeaheadlen)
Karsten Hopp 5bdf71
- 		    unconverted = TYPEAHEADLEN - typeaheadlen;
Karsten Hopp 5bdf71
- 		else
Karsten Hopp 5bdf71
- 		    unconverted = restlen;
Karsten Hopp 5bdf71
- 		mch_memmove(typeahead + typeaheadlen, rest, unconverted);
Karsten Hopp 5bdf71
- 		if (unconverted == restlen)
Karsten Hopp 5bdf71
- 		{
Karsten Hopp 5bdf71
- 		    vim_free(rest);
Karsten Hopp 5bdf71
- 		    rest = NULL;
Karsten Hopp 5bdf71
- 		}
Karsten Hopp 5bdf71
- 		else
Karsten Hopp 5bdf71
- 		{
Karsten Hopp 5bdf71
- 		    restlen -= unconverted;
Karsten Hopp 5bdf71
- 		    mch_memmove(rest, rest + unconverted, restlen);
Karsten Hopp 5bdf71
- 		}
Karsten Hopp 5bdf71
- 		typeaheadlen += unconverted;
Karsten Hopp 5bdf71
- 	    }
Karsten Hopp 5bdf71
- 	    else
Karsten Hopp 5bdf71
- 		unconverted = 0;
Karsten Hopp 5bdf71
- #endif
Karsten Hopp 5bdf71
- 
Karsten Hopp 5bdf71
  	    if (typebuf_changed(tb_change_cnt))
Karsten Hopp 5bdf71
  	    {
Karsten Hopp 5bdf71
  		/* "buf" may be invalid now if a client put something in the
Karsten Hopp 5bdf71
--- 1756,1766 ----
Karsten Hopp 5bdf71
  	else
Karsten Hopp 5bdf71
  #endif
Karsten Hopp 5bdf71
  	{
Karsten Hopp 5bdf71
! 	    WCHAR	ch2 = NUL;
Karsten Hopp 5bdf71
  	    int		modifiers = 0;
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
  	    c = tgetch(&modifiers, &ch2;;
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
  	    if (typebuf_changed(tb_change_cnt))
Karsten Hopp 5bdf71
  	    {
Karsten Hopp 5bdf71
  		/* "buf" may be invalid now if a client put something in the
Karsten Hopp 5bdf71
***************
Karsten Hopp 5bdf71
*** 1816,1842 ****
Karsten Hopp 5bdf71
  		int	n = 1;
Karsten Hopp 5bdf71
  		int     conv = FALSE;
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
- 		typeahead[typeaheadlen] = c;
Karsten Hopp 5bdf71
- 		if (ch2 != NUL)
Karsten Hopp 5bdf71
- 		{
Karsten Hopp 5bdf71
- 		    typeahead[typeaheadlen + 1] = 3;
Karsten Hopp 5bdf71
- 		    typeahead[typeaheadlen + 2] = ch2;
Karsten Hopp 5bdf71
- 		    n += 2;
Karsten Hopp 5bdf71
- 		}
Karsten Hopp 5bdf71
  #ifdef FEAT_MBYTE
Karsten Hopp 5bdf71
! 		/* Only convert normal characters, not special keys.  Need to
Karsten Hopp 5bdf71
! 		 * convert before applying ALT, otherwise mapping <M-x> breaks
Karsten Hopp 5bdf71
! 		 * when 'tenc' is set. */
Karsten Hopp 5bdf71
! 		if (input_conv.vc_type != CONV_NONE
Karsten Hopp 5bdf71
! 						&& (ch2 == NUL || c != K_NUL))
Karsten Hopp 5bdf71
  		{
Karsten Hopp 5bdf71
! 		    conv = TRUE;
Karsten Hopp 5bdf71
! 		    typeaheadlen -= unconverted;
Karsten Hopp 5bdf71
! 		    n = convert_input_safe(typeahead + typeaheadlen,
Karsten Hopp 5bdf71
! 				n + unconverted, TYPEAHEADLEN - typeaheadlen,
Karsten Hopp 5bdf71
! 				rest == NULL ? &rest : NULL, &restlen);
Karsten Hopp 5bdf71
  		}
Karsten Hopp 5bdf71
  #endif
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
  		if (conv)
Karsten Hopp 5bdf71
  		{
Karsten Hopp 5bdf71
--- 1784,1819 ----
Karsten Hopp 5bdf71
  		int	n = 1;
Karsten Hopp 5bdf71
  		int     conv = FALSE;
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
  #ifdef FEAT_MBYTE
Karsten Hopp 5bdf71
! 		if (ch2 == NUL)
Karsten Hopp 5bdf71
  		{
Karsten Hopp 5bdf71
! 		    int	    i;
Karsten Hopp 5bdf71
! 		    char_u  *p;
Karsten Hopp 5bdf71
! 		    WCHAR   ch[2];
Karsten Hopp 5bdf71
! 
Karsten Hopp 5bdf71
! 		    ch[0] = c;
Karsten Hopp 5bdf71
! 		    if (c >= 0xD800 && c <= 0xDBFF)	/* High surrogate */
Karsten Hopp 5bdf71
! 		    {
Karsten Hopp 5bdf71
! 			ch[1] = tgetch(&modifiers, &ch2;;
Karsten Hopp 5bdf71
! 			n++;
Karsten Hopp 5bdf71
! 		    }
Karsten Hopp 5bdf71
! 		    p = utf16_to_enc(ch, &n);
Karsten Hopp 5bdf71
! 		    if (p != NULL)
Karsten Hopp 5bdf71
! 		    {
Karsten Hopp 5bdf71
! 			for (i = 0; i < n; i++)
Karsten Hopp 5bdf71
! 			    typeahead[typeaheadlen + i] = p[i];
Karsten Hopp 5bdf71
! 			vim_free(p);
Karsten Hopp 5bdf71
! 		    }
Karsten Hopp 5bdf71
  		}
Karsten Hopp 5bdf71
+ 		else
Karsten Hopp 5bdf71
  #endif
Karsten Hopp 5bdf71
+ 		    typeahead[typeaheadlen] = c;
Karsten Hopp 5bdf71
+ 		if (ch2 != NUL)
Karsten Hopp 5bdf71
+ 		{
Karsten Hopp 5bdf71
+ 		    typeahead[typeaheadlen + n] = 3;
Karsten Hopp 5bdf71
+ 		    typeahead[typeaheadlen + n + 1] = (char_u)ch2;
Karsten Hopp 5bdf71
+ 		    n += 2;
Karsten Hopp 5bdf71
+ 		}
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
  		if (conv)
Karsten Hopp 5bdf71
  		{
Karsten Hopp 5bdf71
***************
Karsten Hopp 5bdf71
*** 5366,5392 ****
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
  /*
Karsten Hopp 5bdf71
!  * write `cchToWrite' characters in `pchBuf' to the screen
Karsten Hopp 5bdf71
!  * Returns the number of characters actually written (at least one).
Karsten Hopp 5bdf71
   */
Karsten Hopp 5bdf71
!     static BOOL
Karsten Hopp 5bdf71
  write_chars(
Karsten Hopp 5bdf71
!     LPCSTR pchBuf,
Karsten Hopp 5bdf71
!     DWORD  cchToWrite)
Karsten Hopp 5bdf71
  {
Karsten Hopp 5bdf71
      COORD coord = g_coord;
Karsten Hopp 5bdf71
      DWORD written;
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
!     FillConsoleOutputAttribute(g_hConOut, g_attrCurrent, cchToWrite,
Karsten Hopp 5bdf71
! 				coord, &written);
Karsten Hopp 5bdf71
!     /* When writing fails or didn't write a single character, pretend one
Karsten Hopp 5bdf71
!      * character was written, otherwise we get stuck. */
Karsten Hopp 5bdf71
!     if (WriteConsoleOutputCharacter(g_hConOut, pchBuf, cchToWrite,
Karsten Hopp 5bdf71
! 				coord, &written) == 0
Karsten Hopp 5bdf71
! 	    || written == 0)
Karsten Hopp 5bdf71
! 	written = 1;
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
!     g_coord.X += (SHORT) written;
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
      while (g_coord.X > g_srScrollRegion.Right)
Karsten Hopp 5bdf71
      {
Karsten Hopp 5bdf71
--- 5343,5415 ----
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
  /*
Karsten Hopp 5bdf71
!  * write `cbToWrite' bytes in `pchBuf' to the screen
Karsten Hopp 5bdf71
!  * Returns the number of bytes actually written (at least one).
Karsten Hopp 5bdf71
   */
Karsten Hopp 5bdf71
!     static DWORD
Karsten Hopp 5bdf71
  write_chars(
Karsten Hopp 5bdf71
!     char_u *pchBuf,
Karsten Hopp 5bdf71
!     DWORD  cbToWrite)
Karsten Hopp 5bdf71
  {
Karsten Hopp 5bdf71
      COORD coord = g_coord;
Karsten Hopp 5bdf71
      DWORD written;
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
! #ifdef FEAT_MBYTE
Karsten Hopp 5bdf71
!     if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
Karsten Hopp 5bdf71
!     {
Karsten Hopp 5bdf71
! 	static WCHAR	*unicodebuf = NULL;
Karsten Hopp 5bdf71
! 	static int	unibuflen = 0;
Karsten Hopp 5bdf71
! 	int		length;
Karsten Hopp 5bdf71
! 	DWORD		n, cchwritten, cells;
Karsten Hopp 5bdf71
! 
Karsten Hopp 5bdf71
! 	length = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)pchBuf, cbToWrite, 0, 0);
Karsten Hopp 5bdf71
! 	if (unicodebuf == NULL || length > unibuflen)
Karsten Hopp 5bdf71
! 	{
Karsten Hopp 5bdf71
! 	    vim_free(unicodebuf);
Karsten Hopp 5bdf71
! 	    unicodebuf = (WCHAR *)lalloc(length * sizeof(WCHAR), FALSE);
Karsten Hopp 5bdf71
! 	    unibuflen = length;
Karsten Hopp 5bdf71
! 	}
Karsten Hopp 5bdf71
! 	MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)pchBuf, cbToWrite,
Karsten Hopp 5bdf71
! 			    unicodebuf, unibuflen);
Karsten Hopp 5bdf71
! 
Karsten Hopp 5bdf71
! 	cells = mb_string2cells(pchBuf, cbToWrite);
Karsten Hopp 5bdf71
! 	FillConsoleOutputAttribute(g_hConOut, g_attrCurrent, cells,
Karsten Hopp 5bdf71
! 				    coord, &written);
Karsten Hopp 5bdf71
! 	/* When writing fails or didn't write a single character, pretend one
Karsten Hopp 5bdf71
! 	 * character was written, otherwise we get stuck. */
Karsten Hopp 5bdf71
! 	if (WriteConsoleOutputCharacterW(g_hConOut, unicodebuf, length,
Karsten Hopp 5bdf71
! 		    coord, &cchwritten) == 0
Karsten Hopp 5bdf71
! 		|| cchwritten == 0)
Karsten Hopp 5bdf71
! 	    cchwritten = 1;
Karsten Hopp 5bdf71
! 
Karsten Hopp 5bdf71
! 	if (cchwritten == length)
Karsten Hopp 5bdf71
! 	{
Karsten Hopp 5bdf71
! 	    written = cbToWrite;
Karsten Hopp 5bdf71
! 	    g_coord.X += (SHORT)cells;
Karsten Hopp 5bdf71
! 	}
Karsten Hopp 5bdf71
! 	else
Karsten Hopp 5bdf71
! 	{
Karsten Hopp 5bdf71
! 	    char_u *p = pchBuf;
Karsten Hopp 5bdf71
! 	    for (n = 0; n < cchwritten; n++)
Karsten Hopp 5bdf71
! 		mb_cptr_adv(p);
Karsten Hopp 5bdf71
! 	    written = p - pchBuf;
Karsten Hopp 5bdf71
! 	    g_coord.X += (SHORT)mb_string2cells(pchBuf, written);
Karsten Hopp 5bdf71
! 	}
Karsten Hopp 5bdf71
!     }
Karsten Hopp 5bdf71
!     else
Karsten Hopp 5bdf71
! #endif
Karsten Hopp 5bdf71
!     {
Karsten Hopp 5bdf71
! 	FillConsoleOutputAttribute(g_hConOut, g_attrCurrent, cbToWrite,
Karsten Hopp 5bdf71
! 				    coord, &written);
Karsten Hopp 5bdf71
! 	/* When writing fails or didn't write a single character, pretend one
Karsten Hopp 5bdf71
! 	 * character was written, otherwise we get stuck. */
Karsten Hopp 5bdf71
! 	if (WriteConsoleOutputCharacter(g_hConOut, (LPCSTR)pchBuf, cbToWrite,
Karsten Hopp 5bdf71
! 		    coord, &written) == 0
Karsten Hopp 5bdf71
! 		|| written == 0)
Karsten Hopp 5bdf71
! 	    written = 1;
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
! 	g_coord.X += (SHORT) written;
Karsten Hopp 5bdf71
!     }
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
      while (g_coord.X > g_srScrollRegion.Right)
Karsten Hopp 5bdf71
      {
Karsten Hopp 5bdf71
*** ../vim-7.4.851/src/ui.c	2015-08-11 19:13:55.146175594 +0200
Karsten Hopp 5bdf71
--- src/ui.c	2015-09-01 20:27:49.069924312 +0200
Karsten Hopp 5bdf71
***************
Karsten Hopp 5bdf71
*** 42,48 ****
Karsten Hopp 5bdf71
      /* Don't output anything in silent mode ("ex -s") unless 'verbose' set */
Karsten Hopp 5bdf71
      if (!(silent_mode && p_verbose == 0))
Karsten Hopp 5bdf71
      {
Karsten Hopp 5bdf71
! #ifdef FEAT_MBYTE
Karsten Hopp 5bdf71
  	char_u	*tofree = NULL;
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
  	if (output_conv.vc_type != CONV_NONE)
Karsten Hopp 5bdf71
--- 42,48 ----
Karsten Hopp 5bdf71
      /* Don't output anything in silent mode ("ex -s") unless 'verbose' set */
Karsten Hopp 5bdf71
      if (!(silent_mode && p_verbose == 0))
Karsten Hopp 5bdf71
      {
Karsten Hopp 5bdf71
! #if defined(FEAT_MBYTE) && !defined(WIN3264)
Karsten Hopp 5bdf71
  	char_u	*tofree = NULL;
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
  	if (output_conv.vc_type != CONV_NONE)
Karsten Hopp 5bdf71
***************
Karsten Hopp 5bdf71
*** 56,62 ****
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
  	mch_write(s, len);
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
! #ifdef FEAT_MBYTE
Karsten Hopp 5bdf71
  	if (output_conv.vc_type != CONV_NONE)
Karsten Hopp 5bdf71
  	    vim_free(tofree);
Karsten Hopp 5bdf71
  #endif
Karsten Hopp 5bdf71
--- 56,62 ----
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
  	mch_write(s, len);
Karsten Hopp 5bdf71
  
Karsten Hopp 5bdf71
! #if defined(FEAT_MBYTE) && !defined(WIN3264)
Karsten Hopp 5bdf71
  	if (output_conv.vc_type != CONV_NONE)
Karsten Hopp 5bdf71
  	    vim_free(tofree);
Karsten Hopp 5bdf71
  #endif
Karsten Hopp 5bdf71
*** ../vim-7.4.851/runtime/doc/options.txt	2015-07-21 17:53:11.573528028 +0200
Karsten Hopp 5bdf71
--- runtime/doc/options.txt	2015-09-01 20:29:21.724964297 +0200
Karsten Hopp 5bdf71
***************
Karsten Hopp 5bdf71
*** 7377,7390 ****
Karsten Hopp 5bdf71
  	the GUI it only applies to the keyboard ( 'encoding' is used for the
Karsten Hopp 5bdf71
  	display).  Except for the Mac when 'macatsui' is off, then
Karsten Hopp 5bdf71
  	'termencoding' should be "macroman".
Karsten Hopp 5bdf71
- 	In the Win32 console version the default value is the console codepage
Karsten Hopp 5bdf71
- 	when it differs from the ANSI codepage.
Karsten Hopp 5bdf71
  								*E617*
Karsten Hopp 5bdf71
  	Note: This does not apply to the GTK+ 2 GUI.  After the GUI has been
Karsten Hopp 5bdf71
  	successfully initialized, 'termencoding' is forcibly set to "utf-8".
Karsten Hopp 5bdf71
  	Any attempts to set a different value will be rejected, and an error
Karsten Hopp 5bdf71
  	message is shown.
Karsten Hopp 5bdf71
! 	For the Win32 GUI 'termencoding' is not used for typed characters,
Karsten Hopp 5bdf71
  	because the Win32 system always passes Unicode characters.
Karsten Hopp 5bdf71
  	When empty, the same encoding is used as for the 'encoding' option.
Karsten Hopp 5bdf71
  	This is the normal value.
Karsten Hopp 5bdf71
--- 7396,7407 ----
Karsten Hopp 5bdf71
  	the GUI it only applies to the keyboard ( 'encoding' is used for the
Karsten Hopp 5bdf71
  	display).  Except for the Mac when 'macatsui' is off, then
Karsten Hopp 5bdf71
  	'termencoding' should be "macroman".
Karsten Hopp 5bdf71
  								*E617*
Karsten Hopp 5bdf71
  	Note: This does not apply to the GTK+ 2 GUI.  After the GUI has been
Karsten Hopp 5bdf71
  	successfully initialized, 'termencoding' is forcibly set to "utf-8".
Karsten Hopp 5bdf71
  	Any attempts to set a different value will be rejected, and an error
Karsten Hopp 5bdf71
  	message is shown.
Karsten Hopp 5bdf71
! 	For the Win32 GUI and console versions 'termencoding' is not used,
Karsten Hopp 5bdf71
  	because the Win32 system always passes Unicode characters.
Karsten Hopp 5bdf71
  	When empty, the same encoding is used as for the 'encoding' option.
Karsten Hopp 5bdf71
  	This is the normal value.
Karsten Hopp 5bdf71
*** ../vim-7.4.851/src/version.c	2015-09-01 20:23:30.408603580 +0200
Karsten Hopp 5bdf71
--- src/version.c	2015-09-01 20:27:43.713979797 +0200
Karsten Hopp 5bdf71
***************
Karsten Hopp 5bdf71
*** 743,744 ****
Karsten Hopp 5bdf71
--- 743,746 ----
Karsten Hopp 5bdf71
  {   /* Add new patch number below this line */
Karsten Hopp 5bdf71
+ /**/
Karsten Hopp 5bdf71
+     852,
Karsten Hopp 5bdf71
  /**/
Karsten Hopp 5bdf71
Karsten Hopp 5bdf71
-- 
Karsten Hopp 5bdf71
(letter from Mark to Mike, about the film's probable certificate)
Karsten Hopp 5bdf71
      I would like to get back to the Censor and agree to lose the shits, take
Karsten Hopp 5bdf71
      the odd Jesus Christ out and lose Oh fuck off, but to retain 'fart in
Karsten Hopp 5bdf71
      your general direction', 'castanets of your testicles' and 'oral sex'
Karsten Hopp 5bdf71
      and ask him for an 'A' rating on that basis.
Karsten Hopp 5bdf71
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
Karsten Hopp 5bdf71
Karsten Hopp 5bdf71
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 5bdf71
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 5bdf71
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 5bdf71
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///