home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / patches / 7.3 / 7.3.859 < prev    next >
Encoding:
Internet Message Format  |  2013-03-12  |  9.7 KB

  1. To: vim_dev@googlegroups.com
  2. Subject: Patch 7.3.859
  3. Fcc: outbox
  4. From: Bram Moolenaar <Bram@moolenaar.net>
  5. Mime-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. ------------
  9.  
  10. Patch 7.3.859
  11. Problem:    'ambiwidth' must be set by the user.
  12. Solution:   Detects East Asian ambiguous width (UAX #11) state of the terminal
  13.         at the start-up time and 'ambiwidth' accordingly.  (Hayaki Saito)
  14. Files:        src/main.c, src/option.c, src/term.c, src/term.h,
  15.         src/proto/term.pro
  16.  
  17.  
  18. *** ../vim-7.3.858/src/main.c    2013-01-17 13:59:56.000000000 +0100
  19. --- src/main.c    2013-03-13 19:09:03.000000000 +0100
  20. ***************
  21. *** 804,809 ****
  22. --- 804,812 ----
  23.   
  24.       starttermcap();        /* start termcap if not done by wait_return() */
  25.       TIME_MSG("start termcap");
  26. + #if defined(FEAT_TERMRESPONSE) && defined(FEAT_MBYTE)
  27. +     may_req_ambiguous_character_width();
  28. + #endif
  29.   
  30.   #ifdef FEAT_MOUSE
  31.       setmouse();                /* may start using the mouse */
  32. *** ../vim-7.3.858/src/option.c    2013-02-13 15:44:22.000000000 +0100
  33. --- src/option.c    2013-03-13 19:09:03.000000000 +0100
  34. ***************
  35. *** 2900,2905 ****
  36. --- 2900,2906 ----
  37.       p_term("t_op", T_OP)
  38.       p_term("t_RI", T_CRI)
  39.       p_term("t_RV", T_CRV)
  40. +     p_term("t_u7", T_U7)
  41.       p_term("t_Sb", T_CSB)
  42.       p_term("t_Sf", T_CSF)
  43.       p_term("t_se", T_SE)
  44. *** ../vim-7.3.858/src/term.c    2013-02-26 14:56:24.000000000 +0100
  45. --- src/term.c    2013-03-13 19:18:22.000000000 +0100
  46. ***************
  47. *** 111,116 ****
  48. --- 111,121 ----
  49.   #  define CRV_SENT    2    /* did send T_CRV, waiting for answer */
  50.   #  define CRV_GOT    3    /* received T_CRV response */
  51.   static int crv_status = CRV_GET;
  52. + /* Request Cursor position report: */
  53. + #  define U7_GET    1    /* send T_U7 when switched to RAW mode */
  54. + #  define U7_SENT    2    /* did send T_U7, waiting for answer */
  55. + #  define U7_GOT    3    /* received T_U7 response */
  56. + static int u7_status = U7_GET;
  57.   # endif
  58.   
  59.   /*
  60. ***************
  61. *** 933,938 ****
  62. --- 938,944 ----
  63.       {(int)KS_CWP,    IF_EB("\033[3;%d;%dt", ESC_STR "[3;%d;%dt")},
  64.   #  endif
  65.       {(int)KS_CRV,    IF_EB("\033[>c", ESC_STR "[>c")},
  66. +     {(int)KS_U7,    IF_EB("\033[6n", ESC_STR "[6n")},
  67.   
  68.       {K_UP,        IF_EB("\033O*A", ESC_STR "O*A")},
  69.       {K_DOWN,        IF_EB("\033O*B", ESC_STR "O*B")},
  70. ***************
  71. *** 1221,1226 ****
  72. --- 1227,1233 ----
  73.       {(int)KS_CWP,    "[%dCWP%d]"},
  74.   #  endif
  75.       {(int)KS_CRV,    "[CRV]"},
  76. +     {(int)KS_U7,    "[U7]"},
  77.       {K_UP,        "[KU]"},
  78.       {K_DOWN,        "[KD]"},
  79.       {K_LEFT,        "[KL]"},
  80. ***************
  81. *** 1596,1601 ****
  82. --- 1603,1609 ----
  83.                   {KS_TS, "ts"}, {KS_FS, "fs"},
  84.                   {KS_CWP, "WP"}, {KS_CWS, "WS"},
  85.                   {KS_CSI, "SI"}, {KS_CEI, "EI"},
  86. +                 {KS_U7, "u7"},
  87.                   {(enum SpecialKey)0, NULL}
  88.                   };
  89.   
  90. ***************
  91. *** 3183,3189 ****
  92.           /* May need to check for T_CRV response and termcodes, it
  93.            * doesn't work in Cooked mode, an external program may get
  94.            * them. */
  95. !         if (tmode != TMODE_RAW && crv_status == CRV_SENT)
  96.               (void)vpeekc_nomap();
  97.           check_for_codes_from_term();
  98.           }
  99. --- 3191,3198 ----
  100.           /* May need to check for T_CRV response and termcodes, it
  101.            * doesn't work in Cooked mode, an external program may get
  102.            * them. */
  103. !         if (tmode != TMODE_RAW && (crv_status == CRV_SENT
  104. !                      || u7_status == U7_SENT))
  105.               (void)vpeekc_nomap();
  106.           check_for_codes_from_term();
  107.           }
  108. ***************
  109. *** 3245,3251 ****
  110.   # endif
  111.       {
  112.           /* May need to check for T_CRV response. */
  113. !         if (crv_status == CRV_SENT)
  114.           (void)vpeekc_nomap();
  115.           /* Check for termcodes first, otherwise an external program may
  116.            * get them. */
  117. --- 3254,3260 ----
  118.   # endif
  119.       {
  120.           /* May need to check for T_CRV response. */
  121. !         if (crv_status == CRV_SENT || u7_status == U7_SENT)
  122.           (void)vpeekc_nomap();
  123.           /* Check for termcodes first, otherwise an external program may
  124.            * get them. */
  125. ***************
  126. *** 3299,3304 ****
  127. --- 3308,3355 ----
  128.       (void)vpeekc_nomap();
  129.       }
  130.   }
  131. + # if defined(FEAT_MBYTE) || defined(PROTO)
  132. + /*
  133. +  * Check how the terminal treats ambiguous character width (UAX #11).
  134. +  * First, we move the cursor to (0, 0) and print a test ambiguous character
  135. +  * \u25bd (WHITE DOWN-POINTING TRIANGLE) and query current cursor position.
  136. +  * If the terminal treats \u25bd as single width, the position is (0, 1),
  137. +  * or if it is treated as double width, that will be (0, 2).
  138. +  * This function has the side effect that changes cursor position, so
  139. +  * it must be called immediately after entering termcap mode.
  140. +  */
  141. +     void
  142. + may_req_ambiguous_character_width()
  143. + {
  144. +     if (u7_status == U7_GET
  145. +         && cur_tmode == TMODE_RAW
  146. +         && termcap_active
  147. +         && p_ek
  148. + #  ifdef UNIX
  149. +         && isatty(1)
  150. +         && isatty(read_cmd_fd)
  151. + #  endif
  152. +         && *T_U7 != NUL
  153. +         && !option_was_set((char_u *)"ambiwidth"))
  154. +     {
  155. +      char_u    buf[16];
  156. +      term_windgoto(0, 0);
  157. +      buf[mb_char2bytes(0x25bd, buf)] = 0;
  158. +      out_str(buf);
  159. +      out_str(T_U7);
  160. +      u7_status = U7_SENT;
  161. +      term_windgoto(0, 0);
  162. +      out_str((char_u *)"  ");
  163. +      term_windgoto(0, 0);
  164. +      /* check for the characters now, otherwise they might be eaten by
  165. +       * get_keystroke() */
  166. +      out_flush();
  167. +      (void)vpeekc_nomap();
  168. +     }
  169. + }
  170. + # endif
  171.   #endif
  172.   
  173.   /*
  174. ***************
  175. *** 4049,4061 ****
  176.           /* URXVT mouse uses <ESC>[#;#;#M, but we are matching <ESC>[ */
  177.           || key_name[0] == KS_URXVT_MOUSE)
  178.       {
  179. !         /* Check for xterm version string: "<Esc>[>{x};{vers};{y}c".  Also
  180. !          * eat other possible responses to t_RV, rxvt returns
  181. !          * "<Esc>[?1;2c".  Also accept CSI instead of <Esc>[.
  182. !          * mrxvt has been reported to have "+" in the version. Assume
  183. !          * the escape sequence ends with a letter or one of "{|}~". */
  184. !         if (*T_CRV != NUL && ((tp[0] == ESC && tp[1] == '[' && len >= 3)
  185. !                            || (tp[0] == CSI && len >= 2)))
  186.           {
  187.           j = 0;
  188.           extra = 0;
  189. --- 4100,4121 ----
  190.           /* URXVT mouse uses <ESC>[#;#;#M, but we are matching <ESC>[ */
  191.           || key_name[0] == KS_URXVT_MOUSE)
  192.       {
  193. !         /* Check for some responses from terminal start with "<Esc>[" or
  194. !          * CSI.
  195. !          *
  196. !          * - xterm version string: <Esc>[>{x};{vers};{y}c
  197. !          *   Also eat other possible responses to t_RV, rxvt returns
  198. !          *   "<Esc>[?1;2c". Also accept CSI instead of <Esc>[.
  199. !          *   mrxvt has been reported to have "+" in the version. Assume
  200. !          *   the escape sequence ends with a letter or one of "{|}~".
  201. !          *
  202. !          * - cursor position report: <Esc>[{row};{col}R
  203. !          *   The final byte is 'R'. now it is only used for checking for
  204. !          *   ambiguous-width character state.
  205. !          */
  206. !         if ((*T_CRV != NUL || *T_U7 != NUL)
  207. !             && ((tp[0] == ESC && tp[1] == '[' && len >= 3)
  208. !                 || (tp[0] == CSI && len >= 2)))
  209.           {
  210.           j = 0;
  211.           extra = 0;
  212. ***************
  213. *** 4067,4074 ****
  214.           if (i == len)
  215.               return -1;        /* not enough characters */
  216.   
  217.           /* eat it when at least one digit and ending in 'c' */
  218. !         if (i > 2 + (tp[0] != CSI) && tp[i] == 'c')
  219.           {
  220.               crv_status = CRV_GOT;
  221.   
  222. --- 4127,4153 ----
  223.           if (i == len)
  224.               return -1;        /* not enough characters */
  225.   
  226. + #ifdef FEAT_MBYTE
  227. +         /* eat it when it has 2 arguments and ends in 'R' */
  228. +         if (u7_status == U7_SENT && j == 1 && tp[i] == 'R')
  229. +         {
  230. +             char *p = NULL;
  231. +             u7_status = U7_GOT;
  232. +             if (extra == 2)
  233. +             p = "single";
  234. +             else if (extra == 3)
  235. +             p = "double";
  236. +             if (p != NULL)
  237. +             set_option_value((char_u *)"ambw", 0L, (char_u *)p, 0);
  238. +             key_name[0] = (int)KS_EXTRA;
  239. +             key_name[1] = (int)KE_IGNORE;
  240. +             slen = i + 1;
  241. +         }
  242. +         else
  243. + #endif
  244.           /* eat it when at least one digit and ending in 'c' */
  245. !         if (*T_CRV != NUL && i > 2 + (tp[0] != CSI) && tp[i] == 'c')
  246.           {
  247.               crv_status = CRV_GOT;
  248.   
  249. *** ../vim-7.3.858/src/term.h    2010-08-15 21:57:25.000000000 +0200
  250. --- src/term.h    2013-03-13 19:09:03.000000000 +0100
  251. ***************
  252. *** 83,92 ****
  253.   #ifdef FEAT_VERTSPLIT
  254.       KS_CSV,    /* scroll region vertical */
  255.   #endif
  256. !     KS_OP    /* original color pair */
  257.   };
  258.   
  259. ! #define KS_LAST        KS_OP
  260.   
  261.   /*
  262.    * the terminal capabilities are stored in this array
  263. --- 83,93 ----
  264.   #ifdef FEAT_VERTSPLIT
  265.       KS_CSV,    /* scroll region vertical */
  266.   #endif
  267. !     KS_OP,    /* original color pair */
  268. !     KS_U7    /* request cursor position */
  269.   };
  270.   
  271. ! #define KS_LAST        KS_U7
  272.   
  273.   /*
  274.    * the terminal capabilities are stored in this array
  275. ***************
  276. *** 158,163 ****
  277. --- 159,165 ----
  278.   #define T_CEI    (term_str(KS_CEI))    /* end insert mode */
  279.   #define T_CRV    (term_str(KS_CRV))    /* request version string */
  280.   #define T_OP    (term_str(KS_OP))    /* original color pair */
  281. + #define T_U7    (term_str(KS_U7))    /* request cursor position */
  282.   
  283.   #define TMODE_COOK  0    /* terminal mode for external cmds and Ex mode */
  284.   #define TMODE_SLEEP 1    /* terminal mode for sleeping (cooked but no echo) */
  285. *** ../vim-7.3.858/src/proto/term.pro    2012-02-05 22:05:44.000000000 +0100
  286. --- src/proto/term.pro    2013-03-13 19:09:54.000000000 +0100
  287. ***************
  288. *** 34,39 ****
  289. --- 34,40 ----
  290.   void starttermcap __ARGS((void));
  291.   void stoptermcap __ARGS((void));
  292.   void may_req_termresponse __ARGS((void));
  293. + void may_req_ambiguous_character_width __ARGS((void));
  294.   int swapping_screen __ARGS((void));
  295.   void setmouse __ARGS((void));
  296.   int mouse_has __ARGS((int c));
  297. *** ../vim-7.3.858/src/version.c    2013-03-13 19:02:37.000000000 +0100
  298. --- src/version.c    2013-03-13 19:27:31.000000000 +0100
  299. ***************
  300. *** 730,731 ****
  301. --- 730,733 ----
  302.   {   /* Add new patch number below this line */
  303. + /**/
  304. +     859,
  305.   /**/
  306.  
  307. -- 
  308. Microsoft is to software what McDonalds is to gourmet cooking
  309.  
  310.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  311. ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  312. \\\  an exciting new programming language -- http://www.Zimbu.org        ///
  313.  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
  314.