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.2.193 < prev    next >
Encoding:
Internet Message Format  |  2004-01-17  |  12.1 KB

  1. To: vim-dev@vim.org
  2. Subject: Patch 6.2.193
  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.2.193
  11. Problem:    When recalling a search pattern from the history from a ":s,a/c,"
  12.         command the '/' ends the search string. (JC van Winkel)
  13. Solution:   Store the separator character with the history entries.  Escape
  14.         characters when needed, replace the old separator with the new one.
  15.         Also fixes that recalling a "/" search for a "?" command messes up 
  16.         trailing flags.
  17. Files:        src/eval.c, src/ex_getln.c, src/normal.c, src/proto/ex_getln.pro,
  18.         src/search.c, src/tag.c
  19.  
  20.  
  21. *** ../vim-6.2.192/src/eval.c    Sun Jan 18 20:46:13 2004
  22. --- src/eval.c    Sun Jan 18 16:51:58 2004
  23. ***************
  24. *** 5140,5146 ****
  25.       str = get_var_string_buf(&argvars[1], buf);
  26.       if (*str != NUL)
  27.       {
  28. !         add_to_history(histype, str, FALSE);
  29.           retvar->var_val.var_number = TRUE;
  30.           return;
  31.       }
  32. --- 5140,5146 ----
  33.       str = get_var_string_buf(&argvars[1], buf);
  34.       if (*str != NUL)
  35.       {
  36. !         add_to_history(histype, str, FALSE, NUL);
  37.           retvar->var_val.var_number = TRUE;
  38.           return;
  39.       }
  40. *** ../vim-6.2.192/src/ex_getln.c    Sat Sep 27 19:36:46 2003
  41. --- src/ex_getln.c    Sun Jan 18 14:43:53 2004
  42. ***************
  43. *** 42,48 ****
  44.   typedef struct hist_entry
  45.   {
  46.       int        hisnum;        /* identifying number */
  47. !     char_u    *hisstr;    /* actual entry */
  48.   } histentry_T;
  49.   
  50.   static histentry_T *(history[HIST_COUNT]) = {NULL, NULL, NULL, NULL, NULL};
  51. --- 42,48 ----
  52.   typedef struct hist_entry
  53.   {
  54.       int        hisnum;        /* identifying number */
  55. !     char_u    *hisstr;    /* actual entry, separator char after the NUL */
  56.   } histentry_T;
  57.   
  58.   static histentry_T *(history[HIST_COUNT]) = {NULL, NULL, NULL, NULL, NULL};
  59. ***************
  60. *** 1286,1291 ****
  61. --- 1286,1293 ----
  62.           if (hiscnt != i)    /* jumped to other entry */
  63.           {
  64.               char_u    *p;
  65. +             int        len;
  66. +             int        old_firstc;
  67.   
  68.               vim_free(ccline.cmdbuff);
  69.               if (hiscnt == hislen)
  70. ***************
  71. *** 1293,1302 ****
  72.               else
  73.               p = history[histype][hiscnt].hisstr;
  74.   
  75. !             alloc_cmdbuff((int)STRLEN(p));
  76. !             if (ccline.cmdbuff == NULL)
  77. !             goto returncmd;
  78. !             STRCPY(ccline.cmdbuff, p);
  79.   
  80.               ccline.cmdpos = ccline.cmdlen = (int)STRLEN(ccline.cmdbuff);
  81.               redrawcmd();
  82. --- 1295,1353 ----
  83.               else
  84.               p = history[histype][hiscnt].hisstr;
  85.   
  86. !             if (histype == HIST_SEARCH
  87. !                 && p != lookfor
  88. !                 && (old_firstc = p[STRLEN(p) + 1]) != firstc)
  89. !             {
  90. !             /* Correct for the separator character used when
  91. !              * adding the history entry vs the one used now.
  92. !              * First loop: count length.
  93. !              * Second loop: copy the characters. */
  94. !             for (i = 0; i <= 1; ++i)
  95. !             {
  96. !                 len = 0;
  97. !                 for (j = 0; p[j] != NUL; ++j)
  98. !                 {
  99. !                 /* Replace old sep with new sep, unless it is
  100. !                  * escaped. */
  101. !                 if (p[j] == old_firstc
  102. !                           && (j == 0 || p[j - 1] != '\\'))
  103. !                 {
  104. !                     if (i > 0)
  105. !                     ccline.cmdbuff[len] = firstc;
  106. !                 }
  107. !                 else
  108. !                 {
  109. !                     /* Escape new sep, unless it is already
  110. !                      * escaped. */
  111. !                     if (p[j] == firstc
  112. !                           && (j == 0 || p[j - 1] != '\\'))
  113. !                     {
  114. !                     if (i > 0)
  115. !                         ccline.cmdbuff[len] = '\\';
  116. !                     ++len;
  117. !                     }
  118. !                     if (i > 0)
  119. !                     ccline.cmdbuff[len] = p[j];
  120. !                 }
  121. !                 ++len;
  122. !                 }
  123. !                 if (i == 0)
  124. !                 {
  125. !                 alloc_cmdbuff(len);
  126. !                 if (ccline.cmdbuff == NULL)
  127. !                     goto returncmd;
  128. !                 }
  129. !             }
  130. !             ccline.cmdbuff[len] = NUL;
  131. !             }
  132. !             else
  133. !             {
  134. !             alloc_cmdbuff((int)STRLEN(p));
  135. !             if (ccline.cmdbuff == NULL)
  136. !                 goto returncmd;
  137. !             STRCPY(ccline.cmdbuff, p);
  138. !             }
  139.   
  140.               ccline.cmdpos = ccline.cmdlen = (int)STRLEN(ccline.cmdbuff);
  141.               redrawcmd();
  142. ***************
  143. *** 1556,1562 ****
  144.       if (ccline.cmdlen && firstc != NUL
  145.           && (some_key_typed || histype == HIST_SEARCH))
  146.       {
  147. !         add_to_history(histype, ccline.cmdbuff, TRUE);
  148.           if (firstc == ':')
  149.           {
  150.           vim_free(new_last_cmdline);
  151. --- 1607,1614 ----
  152.       if (ccline.cmdlen && firstc != NUL
  153.           && (some_key_typed || histype == HIST_SEARCH))
  154.       {
  155. !         add_to_history(histype, ccline.cmdbuff, TRUE,
  156. !                        histype == HIST_SEARCH ? firstc : NUL);
  157.           if (firstc == ':')
  158.           {
  159.           vim_free(new_last_cmdline);
  160. ***************
  161. *** 4185,4196 ****
  162.    * values.
  163.    */
  164.       void
  165. ! add_to_history(histype, new_entry, in_map)
  166.       int        histype;
  167.       char_u    *new_entry;
  168.       int        in_map;        /* consider maptick when inside a mapping */
  169.   {
  170.       histentry_T    *hisptr;
  171.   
  172.       if (hislen == 0)        /* no history */
  173.       return;
  174. --- 4239,4252 ----
  175.    * values.
  176.    */
  177.       void
  178. ! add_to_history(histype, new_entry, in_map, sep)
  179.       int        histype;
  180.       char_u    *new_entry;
  181.       int        in_map;        /* consider maptick when inside a mapping */
  182. +     int        sep;        /* separator character used (search hist) */
  183.   {
  184.       histentry_T    *hisptr;
  185. +     int        len;
  186.   
  187.       if (hislen == 0)        /* no history */
  188.       return;
  189. ***************
  190. *** 4221,4227 ****
  191.           hisidx[histype] = 0;
  192.       hisptr = &history[histype][hisidx[histype]];
  193.       vim_free(hisptr->hisstr);
  194. !     hisptr->hisstr = vim_strsave(new_entry);
  195.       hisptr->hisnum = ++hisnum[histype];
  196.       if (histype == HIST_SEARCH && in_map)
  197.           last_maptick = maptick;
  198. --- 4277,4289 ----
  199.           hisidx[histype] = 0;
  200.       hisptr = &history[histype][hisidx[histype]];
  201.       vim_free(hisptr->hisstr);
  202. !     /* Store the separator after the NUL of the string. */
  203. !     len = STRLEN(new_entry);
  204. !     hisptr->hisstr = vim_strnsave(new_entry, len + 2);
  205. !     if (hisptr->hisstr != NULL)
  206. !         hisptr->hisstr[len + 1] = sep;
  207.       hisptr->hisnum = ++hisnum[histype];
  208.       if (histype == HIST_SEARCH && in_map)
  209.           last_maptick = maptick;
  210. ***************
  211. *** 4586,4592 ****
  212.           if (i == hislen)
  213.               i = 0;
  214.           if (hist[i].hisstr != NULL
  215. !             && hist[i].hisnum >= j && hist[i].hisnum <= k)
  216.           {
  217.               msg_putchar('\n');
  218.               sprintf((char *)IObuff, "%c%6d  %s", i == idx ? '>' : ' ',
  219. --- 4648,4654 ----
  220.           if (i == hislen)
  221.               i = 0;
  222.           if (hist[i].hisstr != NULL
  223. !             && hist[i].hisnum >= j && hist[i].hisnum <= k)
  224.           {
  225.               msg_putchar('\n');
  226.               sprintf((char *)IObuff, "%c%6d  %s", i == idx ? '>' : ' ',
  227. ***************
  228. *** 4682,4697 ****
  229.       vir_T    *virp;
  230.   {
  231.       int        type;
  232.       char_u    *val;
  233.   
  234.       type = hist_char2type(virp->vir_line[0]);
  235.       if (viminfo_hisidx[type] < viminfo_hislen[type])
  236.       {
  237. !     val = viminfo_readstring(virp, 1, TRUE);
  238.       if (val != NULL)
  239.       {
  240.           if (!in_history(type, val, viminfo_add_at_front))
  241.           viminfo_history[type][viminfo_hisidx[type]++] = val;
  242.           else
  243.           vim_free(val);
  244.       }
  245. --- 4744,4782 ----
  246.       vir_T    *virp;
  247.   {
  248.       int        type;
  249. +     int        sep;
  250. +     int        len;
  251.       char_u    *val;
  252.   
  253.       type = hist_char2type(virp->vir_line[0]);
  254.       if (viminfo_hisidx[type] < viminfo_hislen[type])
  255.       {
  256. !     /* Use a zero offset, so that we have some extra space in the
  257. !      * allocated memory for the separator. */
  258. !     val = viminfo_readstring(virp, 0, TRUE);
  259.       if (val != NULL)
  260.       {
  261.           if (!in_history(type, val, viminfo_add_at_front))
  262. +         {
  263. +         len = STRLEN(val);
  264. +         if (type == HIST_SEARCH)
  265. +         {
  266. +             /* Search entry: Move the separator from the second column
  267. +              * to after the NUL. */
  268. +             sep = val[1];
  269. +             --len;
  270. +             mch_memmove(val, val + 2, (size_t)len);
  271. +             val[len + 1] = (sep == ' ' ? NUL : sep);
  272. +         }
  273. +         else
  274. +         {
  275. +             /* Not a search entry: No separator in the viminfo file,
  276. +              * add a NUL separator. */
  277. +             mch_memmove(val, val + 1, (size_t)len);
  278. +             val[len + 1] = NUL;
  279. +         }
  280.           viminfo_history[type][viminfo_hisidx[type]++] = val;
  281. +         }
  282.           else
  283.           vim_free(val);
  284.       }
  285. ***************
  286. *** 4757,4762 ****
  287. --- 4842,4849 ----
  288.       int        i;
  289.       int        type;
  290.       int        num_saved;
  291. +     char_u  *p;
  292. +     int        c;
  293.   
  294.       init_history();
  295.       if (hislen == 0)
  296. ***************
  297. *** 4779,4788 ****
  298.       if (i >= 0)
  299.           while (num_saved--)
  300.           {
  301. !         if (history[type][i].hisstr != NULL)
  302.           {
  303.               putc(hist_type2char(type, TRUE), fp);
  304. !             viminfo_writestring(fp, history[type][i].hisstr);
  305.           }
  306.           if (--i < 0)
  307.               i = hislen - 1;
  308. --- 4866,4883 ----
  309.       if (i >= 0)
  310.           while (num_saved--)
  311.           {
  312. !         p = history[type][i].hisstr;
  313. !         if (p != NULL)
  314.           {
  315.               putc(hist_type2char(type, TRUE), fp);
  316. !             /* For the search history: put the separator in the second
  317. !              * column; use a space if there isn't one. */
  318. !             if (type == HIST_SEARCH)
  319. !             {
  320. !             c = p[STRLEN(p) + 1];
  321. !             putc(c == NUL ? ' ' : c, fp);
  322. !             }
  323. !             viminfo_writestring(fp, p);
  324.           }
  325.           if (--i < 0)
  326.               i = hislen - 1;
  327. *** ../vim-6.2.192/src/normal.c    Sun Jan 18 20:28:26 2004
  328. --- src/normal.c    Sun Jan 18 18:49:04 2004
  329. ***************
  330. *** 4920,4926 ****
  331.           STRCAT(buf, "\\>");
  332.   #ifdef FEAT_CMDHIST
  333.       /* put pattern in search history */
  334. !     add_to_history(HIST_SEARCH, buf, TRUE);
  335.   #endif
  336.       normal_search(cap, cmdchar == '*' ? '/' : '?', buf, 0);
  337.       }
  338. --- 4932,4938 ----
  339.           STRCAT(buf, "\\>");
  340.   #ifdef FEAT_CMDHIST
  341.       /* put pattern in search history */
  342. !     add_to_history(HIST_SEARCH, buf, TRUE, NUL);
  343.   #endif
  344.       normal_search(cap, cmdchar == '*' ? '/' : '?', buf, 0);
  345.       }
  346. *** ../vim-6.2.192/src/proto/ex_getln.pro    Sun Aug 10 22:24:37 2003
  347. --- src/proto/ex_getln.pro    Sun Jan 18 13:36:26 2004
  348. ***************
  349. *** 25,31 ****
  350.   int ExpandGeneric __ARGS((expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file, char_u *((*func)(expand_T *, int))));
  351.   char_u *globpath __ARGS((char_u *path, char_u *file));
  352.   int get_histtype __ARGS((char_u *name));
  353. ! void add_to_history __ARGS((int histype, char_u *new_entry, int in_map));
  354.   int get_history_idx __ARGS((int histype));
  355.   char_u *get_history_entry __ARGS((int histype, int idx));
  356.   int clr_history __ARGS((int histype));
  357. --- 25,31 ----
  358.   int ExpandGeneric __ARGS((expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file, char_u *((*func)(expand_T *, int))));
  359.   char_u *globpath __ARGS((char_u *path, char_u *file));
  360.   int get_histtype __ARGS((char_u *name));
  361. ! void add_to_history __ARGS((int histype, char_u *new_entry, int in_map, int sep));
  362.   int get_history_idx __ARGS((int histype));
  363.   char_u *get_history_entry __ARGS((int histype, int idx));
  364.   int clr_history __ARGS((int histype));
  365. *** ../vim-6.2.192/src/search.c    Sat Sep 27 19:36:47 2003
  366. --- src/search.c    Sun Jan 18 13:05:15 2004
  367. ***************
  368. *** 172,178 ****
  369.       }
  370.   #ifdef FEAT_CMDHIST
  371.       else if (options & SEARCH_HIS)    /* put new pattern in history */
  372. !     add_to_history(HIST_SEARCH, pat, TRUE);
  373.   #endif
  374.   
  375.   #ifdef FEAT_RIGHTLEFT
  376. --- 172,178 ----
  377.       }
  378.   #ifdef FEAT_CMDHIST
  379.       else if (options & SEARCH_HIS)    /* put new pattern in history */
  380. !     add_to_history(HIST_SEARCH, pat, TRUE, NUL);
  381.   #endif
  382.   
  383.   #ifdef FEAT_RIGHTLEFT
  384. *** ../vim-6.2.192/src/tag.c    Sun Jan 18 20:58:01 2004
  385. --- src/tag.c    Sun Jan 18 13:05:42 2004
  386. ***************
  387. *** 2699,2705 ****
  388.   #if 0    /* disabled for now */
  389.   #ifdef FEAT_CMDHIST
  390.           /* put pattern in search history */
  391. !         add_to_history(HIST_SEARCH, pbuf + 1, TRUE);
  392.   #endif
  393.   #endif
  394.           save_lnum = curwin->w_cursor.lnum;
  395. --- 2699,2705 ----
  396.   #if 0    /* disabled for now */
  397.   #ifdef FEAT_CMDHIST
  398.           /* put pattern in search history */
  399. !         add_to_history(HIST_SEARCH, pbuf + 1, TRUE, pbuf[0]);
  400.   #endif
  401.   #endif
  402.           save_lnum = curwin->w_cursor.lnum;
  403. *** ../vim-6.2.192/src/version.c    Sun Jan 18 21:22:26 2004
  404. --- src/version.c    Sun Jan 18 21:24:10 2004
  405. ***************
  406. *** 639,640 ****
  407. --- 639,642 ----
  408.   {   /* Add new patch number below this line */
  409. + /**/
  410. +     193,
  411.   /**/
  412.  
  413. -- 
  414. WOMAN:   Dennis, there's some lovely filth down here.  Oh -- how d'you do?
  415. ARTHUR:  How do you do, good lady.  I am Arthur, King of the Britons.
  416.          Who's castle is that?
  417. WOMAN:   King of the who?
  418.                                   The Quest for the Holy Grail (Monty Python)
  419.  
  420.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  421. ///        Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  422. \\\              Project leader for A-A-P -- http://www.A-A-P.org        ///
  423.  \\\  Help AIDS victims, buy here: http://ICCF-Holland.org/click1.html  ///
  424.