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 / 6.3 / 6.3.055 < prev    next >
Encoding:
Internet Message Format  |  2005-01-12  |  8.6 KB

  1. To: vim-dev@vim.org
  2. Subject: Patch 6.3.055
  3. Fcc: outbox
  4. From: Bram Moolenaar <Bram@moolenaar.net>
  5. Mime-Version: 1.0
  6. Content-Type: text/plain; charset=ISO-8859-1
  7. Content-Transfer-Encoding: 8bit
  8. ------------
  9.  
  10. Patch 6.3.055 (after 6.3.013)
  11. Problem:    Can't use getcmdline(), getcmdpos() or setcmdpos() with <C-R>=
  12.         when editing a command line.  Using <C-\>e may crash Vim. (Peter
  13.         Winters)
  14. Solution:   When moving ccline out of the way for recursive use, make it
  15.         available to the functions that need it.  Also save and restore
  16.         ccline when calling get_expr_line().  Make ccline.cmdbuf NULL at
  17.         the end of getcmdline().
  18. Files:        src/ex_getln.c
  19.  
  20.  
  21. *** ../vim-6.3.054/src/ex_getln.c    Fri Oct 22 11:45:17 2004
  22. --- src/ex_getln.c    Thu Jan 13 14:06:56 2005
  23. ***************
  24. *** 80,85 ****
  25. --- 80,87 ----
  26.   static void    alloc_cmdbuff __ARGS((int len));
  27.   static int    realloc_cmdbuff __ARGS((int len));
  28.   static void    draw_cmdline __ARGS((int start, int len));
  29. + static void    save_cmdline __ARGS((struct cmdline_info *ccp));
  30. + static void    restore_cmdline __ARGS((struct cmdline_info *ccp));
  31.   static int    cmdline_paste __ARGS((int regname, int literally));
  32.   #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
  33.   static void    redrawcmd_preedit __ARGS((void));
  34. ***************
  35. *** 589,596 ****
  36.   #ifdef FEAT_EVAL
  37.           else if (c == 'e')
  38.           {
  39. !         struct cmdline_info        save_ccline;
  40. !         char_u            *p;
  41.   
  42.           /*
  43.            * Replace the command line with the result of an expression.
  44. --- 591,598 ----
  45.   #ifdef FEAT_EVAL
  46.           else if (c == 'e')
  47.           {
  48. !         struct cmdline_info save_ccline;
  49. !         char_u            *p = NULL;
  50.   
  51.           /*
  52.            * Replace the command line with the result of an expression.
  53. ***************
  54. *** 601,614 ****
  55.               new_cmdpos = 99999;    /* keep it at the end */
  56.           else
  57.               new_cmdpos = ccline.cmdpos;
  58. !         save_ccline = ccline;
  59. !         ccline.cmdbuff = NULL;
  60. !         ccline.cmdprompt = NULL;
  61.           c = get_expr_register();
  62. !         ccline = save_ccline;
  63.           if (c == '=')
  64.           {
  65.               p = get_expr_line();
  66.               if (p != NULL
  67.                    && realloc_cmdbuff((int)STRLEN(p) + 1) == OK)
  68.               {
  69. --- 603,618 ----
  70.               new_cmdpos = 99999;    /* keep it at the end */
  71.           else
  72.               new_cmdpos = ccline.cmdpos;
  73. !         save_cmdline(&save_ccline);
  74.           c = get_expr_register();
  75. !         restore_cmdline(&save_ccline);
  76.           if (c == '=')
  77.           {
  78. +             save_cmdline(&save_ccline);
  79.               p = get_expr_line();
  80. +             restore_cmdline(&save_ccline);
  81.               if (p != NULL
  82.                    && realloc_cmdbuff((int)STRLEN(p) + 1) == OK)
  83.               {
  84. ***************
  85. *** 1027,1037 ****
  86.               }
  87.               else
  88.               {
  89. !             save_ccline = ccline;
  90. !             ccline.cmdbuff = NULL;
  91. !             ccline.cmdprompt = NULL;
  92.               c = get_expr_register();
  93. !             ccline = save_ccline;
  94.               }
  95.           }
  96.   #endif
  97. --- 1031,1039 ----
  98.               }
  99.               else
  100.               {
  101. !             save_cmdline(&save_ccline);
  102.               c = get_expr_register();
  103. !             restore_cmdline(&save_ccline);
  104.               }
  105.           }
  106.   #endif
  107. ***************
  108. *** 1723,1729 ****
  109.       ui_cursor_shape();        /* may show different cursor shape */
  110.   #endif
  111.   
  112. !     return ccline.cmdbuff;
  113.   }
  114.   
  115.   #if (defined(FEAT_CRYPT) || defined(FEAT_EVAL)) || defined(PROTO)
  116. --- 1725,1737 ----
  117.       ui_cursor_shape();        /* may show different cursor shape */
  118.   #endif
  119.   
  120. !     {
  121. !     char_u *p = ccline.cmdbuff;
  122. !     /* Make ccline empty, getcmdline() may try to use it. */
  123. !     ccline.cmdbuff = NULL;
  124. !     return p;
  125. !     }
  126.   }
  127.   
  128.   #if (defined(FEAT_CRYPT) || defined(FEAT_EVAL)) || defined(PROTO)
  129. ***************
  130. *** 1743,1754 ****
  131.       struct cmdline_info    save_ccline;
  132.       int            msg_col_save = msg_col;
  133.   
  134. !     save_ccline = ccline;
  135. !     ccline.cmdbuff = NULL;
  136.       ccline.cmdprompt = prompt;
  137.       ccline.cmdattr = attr;
  138.       s = getcmdline(firstc, 1L, 0);
  139. !     ccline = save_ccline;
  140.       /* Restore msg_col, the prompt from input() may have changed it. */
  141.       msg_col = msg_col_save;
  142.   
  143. --- 1751,1761 ----
  144.       struct cmdline_info    save_ccline;
  145.       int            msg_col_save = msg_col;
  146.   
  147. !     save_cmdline(&save_ccline);
  148.       ccline.cmdprompt = prompt;
  149.       ccline.cmdattr = attr;
  150.       s = getcmdline(firstc, 1L, 0);
  151. !     restore_cmdline(&save_ccline);
  152.       /* Restore msg_col, the prompt from input() may have changed it. */
  153.       msg_col = msg_col_save;
  154.   
  155. ***************
  156. *** 2537,2542 ****
  157. --- 2544,2583 ----
  158.       return retval;
  159.   }
  160.   
  161. + static struct cmdline_info  prev_ccline;
  162. + static int            prev_ccline_used = FALSE;
  163. + /*
  164. +  * Save ccline, because obtaining the "=" register may execute "normal :cmd"
  165. +  * and overwrite it.  But get_cmdline_str() may need it, thus make it
  166. +  * available globally in prev_ccline.
  167. +  */
  168. +     static void
  169. + save_cmdline(ccp)
  170. +     struct cmdline_info *ccp;
  171. + {
  172. +     if (!prev_ccline_used)
  173. +     {
  174. +     vim_memset(&prev_ccline, 0, sizeof(struct cmdline_info));
  175. +     prev_ccline_used = TRUE;
  176. +     }
  177. +     *ccp = prev_ccline;
  178. +     prev_ccline = ccline;
  179. +     ccline.cmdbuff = NULL;
  180. +     ccline.cmdprompt = NULL;
  181. + }
  182. + /*
  183. +  * Resture ccline after it has been saved with save_cmdline().
  184. +  */
  185. +     static void
  186. + restore_cmdline(ccp)
  187. +     struct cmdline_info *ccp;
  188. + {
  189. +     ccline = prev_ccline;
  190. +     prev_ccline = *ccp;
  191. + }
  192.   /*
  193.    * paste a yank register into the command line.
  194.    * used by CTRL-R command in command-line mode
  195. ***************
  196. *** 2571,2583 ****
  197.       regname = may_get_selection(regname);
  198.   #endif
  199.   
  200. !     /* Need to save and restore ccline, because obtaining the "=" register may
  201. !      * execute "normal :cmd" and overwrite it. */
  202. !     save_ccline = ccline;
  203. !     ccline.cmdbuff = NULL;
  204. !     ccline.cmdprompt = NULL;
  205.       i = get_spec_reg(regname, &arg, &allocated, TRUE);
  206. !     ccline = save_ccline;
  207.   
  208.       if (i)
  209.       {
  210. --- 2612,2621 ----
  211.       regname = may_get_selection(regname);
  212.   #endif
  213.   
  214. !     /* Need to save and restore ccline. */
  215. !     save_cmdline(&save_ccline);
  216.       i = get_spec_reg(regname, &arg, &allocated, TRUE);
  217. !     restore_cmdline(&save_ccline);
  218.   
  219.       if (i)
  220.       {
  221. ***************
  222. *** 4541,4546 ****
  223. --- 4579,4602 ----
  224.       return history[histype][hisidx[histype]].hisnum;
  225.   }
  226.   
  227. + static struct cmdline_info *get_ccline_ptr __ARGS((void));
  228. + /*
  229. +  * Get pointer to the command line info to use. cmdline_paste() may clear
  230. +  * ccline and put the previous value in prev_ccline.
  231. +  */
  232. +     static struct cmdline_info *
  233. + get_ccline_ptr()
  234. + {
  235. +     if ((State & CMDLINE) == 0)
  236. +     return NULL;
  237. +     if (ccline.cmdbuff != NULL)
  238. +     return &ccline;
  239. +     if (prev_ccline_used && prev_ccline.cmdbuff != NULL)
  240. +     return &prev_ccline;
  241. +     return NULL;
  242. + }
  243.   /*
  244.    * Get the current command line in allocated memory.
  245.    * Only works when the command line is being edited.
  246. ***************
  247. *** 4549,4557 ****
  248.       char_u *
  249.   get_cmdline_str()
  250.   {
  251. !     if (ccline.cmdbuff == NULL || (State & CMDLINE) == 0)
  252.       return NULL;
  253. !     return vim_strnsave(ccline.cmdbuff, ccline.cmdlen);
  254.   }
  255.   
  256.   /*
  257. --- 4605,4615 ----
  258.       char_u *
  259.   get_cmdline_str()
  260.   {
  261. !     struct cmdline_info *p = get_ccline_ptr();
  262. !     if (p == NULL)
  263.       return NULL;
  264. !     return vim_strnsave(p->cmdbuff, p->cmdlen);
  265.   }
  266.   
  267.   /*
  268. ***************
  269. *** 4563,4571 ****
  270.       int
  271.   get_cmdline_pos()
  272.   {
  273. !     if (ccline.cmdbuff == NULL || (State & CMDLINE) == 0)
  274.       return -1;
  275. !     return ccline.cmdpos;
  276.   }
  277.   
  278.   /*
  279. --- 4621,4631 ----
  280.       int
  281.   get_cmdline_pos()
  282.   {
  283. !     struct cmdline_info *p = get_ccline_ptr();
  284. !     if (p == NULL)
  285.       return -1;
  286. !     return p->cmdpos;
  287.   }
  288.   
  289.   /*
  290. ***************
  291. *** 4577,4583 ****
  292.   set_cmdline_pos(pos)
  293.       int        pos;
  294.   {
  295. !     if (ccline.cmdbuff == NULL || (State & CMDLINE) == 0)
  296.       return 1;
  297.   
  298.       /* The position is not set directly but after CTRL-\ e or CTRL-R = has
  299. --- 4637,4645 ----
  300.   set_cmdline_pos(pos)
  301.       int        pos;
  302.   {
  303. !     struct cmdline_info *p = get_ccline_ptr();
  304. !     if (p == NULL)
  305.       return 1;
  306.   
  307.       /* The position is not set directly but after CTRL-\ e or CTRL-R = has
  308. *** ../vim-6.3.054/src/version.c    Wed Jan  5 11:17:36 2005
  309. --- src/version.c    Thu Jan 13 14:08:12 2005
  310. ***************
  311. *** 643,644 ****
  312. --- 643,646 ----
  313.   {   /* Add new patch number below this line */
  314. + /**/
  315. +     55,
  316.   /**/
  317.  
  318. -- 
  319. ARTHUR:  Well, I AM king...
  320. DENNIS:  Oh king, eh, very nice.  An' how'd you get that, eh?  By exploitin'
  321.          the workers -- by 'angin' on to outdated imperialist dogma which
  322.          perpetuates the economic an' social differences in our society!  If
  323.          there's ever going to be any progress--
  324.                                   The Quest for the Holy Grail (Monty Python)
  325.  
  326.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  327. ///        Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  328. \\\              Project leader for A-A-P -- http://www.A-A-P.org        ///
  329.  \\\     Buy LOTR 3 and help AIDS victims -- http://ICCF.nl/lotr.html   ///
  330.