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.1.237 < prev    next >
Encoding:
Internet Message Format  |  2002-10-29  |  15.2 KB

  1. To: vim-dev@vim.org
  2. Subject: Patch 6.1.237
  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.1.237
  11. Problem:    Putting in Visual block mode does not work correctly when "$" was
  12.         used or when the first line is short.  (Christian Michon)
  13. Solution:   First delete the selected text and then put the new text.  Save
  14.         and restore registers as necessary.
  15. Files:        src/globals.h, src/normal.c, src/ops.c, src/proto/ops.pro,
  16.         src/vim.h
  17.  
  18.  
  19. *** ../vim61.236/src/globals.h    Sun Oct 13 18:48:35 2002
  20. --- src/globals.h    Sun Oct 27 18:31:36 2002
  21. ***************
  22. *** 453,459 ****
  23.   
  24.   EXTERN int    redo_VIsual_busy INIT(= FALSE);
  25.                   /* TRUE when redoing Visual */
  26. - EXTERN int    did_visual_put INIT(= FALSE); /* TRUE after Visual mode "p" */
  27.   #endif
  28.   
  29.   #ifdef FEAT_MOUSE
  30. --- 453,458 ----
  31. *** ../vim61.236/src/normal.c    Thu Oct 17 20:11:44 2002
  32. --- src/normal.c    Sun Oct 27 20:29:45 2002
  33. ***************
  34. *** 1138,1146 ****
  35.   normal_end:
  36.   
  37.       msg_nowait = FALSE;
  38. - #ifdef FEAT_VISUAL
  39. -     did_visual_put = FALSE;
  40. - #endif
  41.   
  42.       /* Reset finish_op, in case it was set */
  43.   #ifdef CURSOR_SHAPE
  44. --- 1138,1143 ----
  45. ***************
  46. *** 7928,7935 ****
  47.       cmdarg_T  *cap;
  48.   {
  49.   #ifdef FEAT_VISUAL
  50. !     pos_T    curpos;
  51. !     colnr_T    left, right;
  52.   #endif
  53.       int        dir;
  54.       int        flags = 0;
  55. --- 7925,7932 ----
  56.       cmdarg_T  *cap;
  57.   {
  58.   #ifdef FEAT_VISUAL
  59. !     int        regname;
  60. !     void    *reg1 = NULL, *reg2 = NULL;
  61.   #endif
  62.       int        dir;
  63.       int        flags = 0;
  64. ***************
  65. *** 7952,8027 ****
  66.       dir = (cap->cmdchar == 'P'
  67.           || (cap->cmdchar == 'g' && cap->nchar == 'P'))
  68.                                ? BACKWARD : FORWARD;
  69. - #ifdef FEAT_VISUAL
  70. -     if (VIsual_active)
  71. -     {
  72. -         /* Putting in Visual mode: The put text replaces the selected
  73. -          * text.  First put the register at the end of the Visual
  74. -          * selection, then delete the selected text.  In some cases the
  75. -          * register is put before the Visual selection. */
  76. -         if (lt(VIsual, curwin->w_cursor))
  77. -         {
  78. -         curbuf->b_visual_start = VIsual;
  79. -         curbuf->b_visual_end = curwin->w_cursor;
  80. -         }
  81. -         else
  82. -         {
  83. -         curbuf->b_visual_start = curwin->w_cursor;
  84. -         curbuf->b_visual_end = VIsual;
  85. -         }
  86. -         curpos = curwin->w_cursor;
  87. -         if (VIsual_mode == Ctrl_V)
  88. -         {
  89. -         getvcols(curwin, &curwin->w_cursor, &VIsual, &left, &right);
  90. -         curwin->w_cursor = curbuf->b_visual_start;
  91. -         coladvance(right);
  92. -         }
  93. -         else
  94. -         curwin->w_cursor = curbuf->b_visual_end;
  95. -         if (VIsual_mode == 'v' && *p_sel == 'e')
  96. -         dir = BACKWARD;
  97. -         else
  98. -         {
  99. -         /* Put linewise text above a characterwise or blockwise
  100. -          * selected Visual area; handled in do_put(). */
  101. -         if (dir == BACKWARD && VIsual_mode != 'V')
  102. -             flags |= PUT_LINE_BACKWARD;
  103. -         dir = FORWARD;
  104. -         }
  105. -         /* When deleting a linewise Visual area, must put the register as
  106. -          * lines to avoid it being deleted. */
  107. -         if (VIsual_mode == 'V')
  108. -         flags |= PUT_LINE;
  109. -     }
  110. - #endif
  111.       prep_redo_cmd(cap);
  112.       if (cap->cmdchar == 'g')
  113.           flags |= PUT_CURSEND;
  114. -     do_put(cap->oap->regname, dir, cap->count1, flags);
  115.   
  116.   #ifdef FEAT_VISUAL
  117.       if (VIsual_active)
  118.       {
  119. !         /* If linewise text was put above the Visual area, need to correct
  120. !          * the line numbers to shift the Visual area down. */
  121. !         if ((flags & PUT_LINE_BACKWARD)
  122. !             && curbuf->b_visual_start.lnum > curbuf->b_op_end.lnum)
  123. !         {
  124. !         linenr_T l;
  125. !         l = curbuf->b_op_end.lnum - curbuf->b_op_start.lnum + 1;
  126. !         curpos.lnum += l;
  127. !         VIsual.lnum += l;
  128.           }
  129.   
  130.           /* Now delete the selected text. */
  131.           cap->cmdchar = 'd';
  132.           cap->nchar = NUL;
  133.           cap->oap->regname = NUL;
  134. -         curwin->w_cursor = curpos;
  135.           nv_operator(cap);
  136. !         did_visual_put = TRUE;  /* tell op_delete() to correct '] mark */
  137.       }
  138.   #endif
  139.       auto_format();
  140.       }
  141. --- 7949,8017 ----
  142.       dir = (cap->cmdchar == 'P'
  143.           || (cap->cmdchar == 'g' && cap->nchar == 'P'))
  144.                                ? BACKWARD : FORWARD;
  145.       prep_redo_cmd(cap);
  146.       if (cap->cmdchar == 'g')
  147.           flags |= PUT_CURSEND;
  148.   
  149.   #ifdef FEAT_VISUAL
  150.       if (VIsual_active)
  151.       {
  152. !         /* Putting in Visual mode: The put text replaces the selected
  153. !          * text.  First delete the selected text, then put the new text.
  154. !          * Need to save and restore the registers that the delete
  155. !          * overwrites if the old contents is being put.
  156. !          */
  157. !         regname = cap->oap->regname;
  158. ! # ifdef FEAT_CLIPBOARD
  159. !         adjust_clip_reg(®name);
  160. ! # endif
  161. !         if (regname == 0 || isdigit(regname))
  162. !         {
  163. !         /* the delete is going to overwrite the register we want to
  164. !          * put, save it first. */
  165. !         reg1 = get_register(regname, TRUE);
  166.           }
  167.   
  168.           /* Now delete the selected text. */
  169.           cap->cmdchar = 'd';
  170.           cap->nchar = NUL;
  171.           cap->oap->regname = NUL;
  172.           nv_operator(cap);
  173. !         do_pending_operator(cap, 0, FALSE);
  174. !         /* delete PUT_LINE_BACKWARD; */
  175. !         cap->oap->regname = regname;
  176. !         if (reg1 != NULL)
  177. !         {
  178. !         /* Delete probably changed the register we want to put, save
  179. !          * it first. Then put back what was there before the delete. */
  180. !         reg2 = get_register(regname, FALSE);
  181. !         put_register(regname, reg1);
  182. !         }
  183. !         /* When deleted a linewise Visual area, put the register as
  184. !          * lines to avoid it joined with the next line.  When deletion was
  185. !          * characterwise, split a line when putting lines. */
  186. !         if (VIsual_mode == 'V')
  187. !         flags |= PUT_LINE;
  188. !         else if (VIsual_mode == 'v')
  189. !         flags |= PUT_LINE_SPLIT;
  190. !         if (VIsual_mode == Ctrl_V && dir == FORWARD)
  191. !         flags |= PUT_LINE_FORWARD;
  192. !         dir = BACKWARD;
  193. !         if (VIsual_mode != 'V'
  194. !                  && curwin->w_cursor.col < curbuf->b_op_start.col)
  195. !         /* cursor is at the end of the line, put forward. */
  196. !         dir = FORWARD;
  197.       }
  198. + #endif
  199. +     do_put(cap->oap->regname, dir, cap->count1, flags);
  200. + #ifdef FEAT_VISUAL
  201. +     /* If a register was saved, put it back now. */
  202. +     if (reg2 != NULL)
  203. +         put_register(regname, reg2);
  204.   #endif
  205.       auto_format();
  206.       }
  207. *** ../vim61.236/src/ops.c    Thu Aug  1 20:47:28 2002
  208. --- src/ops.c    Sun Oct 27 20:29:17 2002
  209. ***************
  210. *** 847,852 ****
  211. --- 847,900 ----
  212.       y_previous = y_current;
  213.   }
  214.   
  215. + #if defined(FEAT_VISUAL) || defined(PROTO)
  216. + /*
  217. +  * Obtain the contents of a "normal" register. The register is made empty.
  218. +  * The returned pointer has allocated memory, use put_register() later.
  219. +  */
  220. +     void *
  221. + get_register(name, copy)
  222. +     int        name;
  223. +     int        copy;    /* make a copy, if FALSE make register empty. */
  224. + {
  225. +     static struct yankreg    *reg;
  226. +     int                i;
  227. +     get_yank_register(name, 0);
  228. +     reg = (struct yankreg *)alloc((unsigned)sizeof(struct yankreg));
  229. +     if (reg != NULL)
  230. +     {
  231. +     *reg = *y_current;
  232. +     if (copy)
  233. +     {
  234. +         /* If we run out of memory some or all of the lines are empty. */
  235. +         reg->y_array = (char_u **)alloc((unsigned)sizeof(char_u *));
  236. +         if (reg->y_array != NULL)
  237. +         {
  238. +         for (i = 0; i < reg->y_size; ++i)
  239. +             reg->y_array[i] = vim_strsave(y_current->y_array[i]);
  240. +         }
  241. +     }
  242. +     else
  243. +         y_current->y_array = NULL;
  244. +     }
  245. +     return (void *)reg;
  246. + }
  247. + /*
  248. +  * Put "reg" into register "name".  Free any previous contents.
  249. +  */
  250. +     void
  251. + put_register(name, reg)
  252. +     int        name;
  253. +     void    *reg;
  254. + {
  255. +     get_yank_register(name, 0);
  256. +     free_yank_all();
  257. +     *y_current = *(struct yankreg *)reg;
  258. + }
  259. + #endif
  260.   #if defined(FEAT_MOUSE) || defined(PROTO)
  261.   /*
  262.    * return TRUE if the current yank register has type MLINE
  263. ***************
  264. *** 1403,1408 ****
  265. --- 1457,1481 ----
  266.       }
  267.   }
  268.   
  269. + #if defined(FEAT_CLIPBOARD) || defined(PROTO)
  270. + /*
  271. +  * Adjust the register name pointed to with "rp" for the clipboard being
  272. +  * used always and the clipboard being available.
  273. +  */
  274. +     void
  275. + adjust_clip_reg(rp)
  276. +     int        *rp;
  277. + {
  278. +     /* If no reg. specified, and "unnamed" is in 'clipboard', use '*' reg. */
  279. +     if (*rp == 0 && clip_unnamed)
  280. +     *rp = '*';
  281. +     if (!clip_star.available && *rp == '*')
  282. +     *rp = 0;
  283. +     if (!clip_plus.available && *rp == '+')
  284. +     *rp = 0;
  285. + }
  286. + #endif
  287.   /*
  288.    * op_delete - handle a delete operation
  289.    *
  290. ***************
  291. *** 1436,1448 ****
  292.       }
  293.   
  294.   #ifdef FEAT_CLIPBOARD
  295. !     /* If no reg. specified, and "unnamed" is in 'clipboard', use '*' reg. */
  296. !     if (oap->regname == 0 && clip_unnamed)
  297. !     oap->regname = '*';
  298. !     if (!clip_star.available && oap->regname == '*')
  299. !     oap->regname = 0;
  300. !     if (!clip_plus.available && oap->regname == '+')
  301. !     oap->regname = 0;
  302.   #endif
  303.   
  304.   #ifdef FEAT_MBYTE
  305. --- 1509,1515 ----
  306.       }
  307.   
  308.   #ifdef FEAT_CLIPBOARD
  309. !     adjust_clip_reg(&oap->regname);
  310.   #endif
  311.   
  312.   #ifdef FEAT_MBYTE
  313. ***************
  314. *** 1754,1799 ****
  315.       msgmore(curbuf->b_ml.ml_line_count - old_lcount);
  316.   
  317.   #ifdef FEAT_VISUAL
  318. !     /*
  319. !      * Set "'[" and "']" marks.
  320. !      */
  321. !     if (did_visual_put)
  322.       {
  323. !     /* "p" in Visual mode: The '] mark is at the end of the inserted text,
  324. !      * correct it for the deleted text. */
  325. !     if (oap->block_mode)
  326. !     {
  327. !         if (curbuf->b_op_end.lnum <= oap->end.lnum)
  328. !         curbuf->b_op_end.col -= bd.textlen
  329. !                           - bd.startspaces - bd.endspaces;
  330. !     }
  331. !     else if (oap->motion_type == MLINE)
  332. !         curbuf->b_op_end.lnum -= oap->line_count;
  333. !     else
  334. !     {
  335. !         if (curbuf->b_op_end.lnum == curbuf->b_op_start.lnum)
  336. !         {
  337. !         if (oap->line_count == 1)
  338. !             curbuf->b_op_end.col -= oap->end.col - oap->start.col + 1;
  339. !         else
  340. !             curbuf->b_op_end.col -= oap->end.col - 1;
  341. !         }
  342. !         curbuf->b_op_end.lnum -= oap->line_count - 1;
  343. !     }
  344.       }
  345.       else
  346.   #endif
  347. !     {
  348. ! #ifdef FEAT_VISUAL
  349. !     if (oap->block_mode)
  350. !     {
  351. !         curbuf->b_op_end.lnum = oap->end.lnum;
  352. !         curbuf->b_op_end.col = oap->start.col;
  353. !     }
  354. !     else
  355. ! #endif
  356. !         curbuf->b_op_end = oap->start;
  357. !     }
  358.       curbuf->b_op_start = oap->start;
  359.   
  360.       return OK;
  361. --- 1821,1834 ----
  362.       msgmore(curbuf->b_ml.ml_line_count - old_lcount);
  363.   
  364.   #ifdef FEAT_VISUAL
  365. !     if (oap->block_mode)
  366.       {
  367. !     curbuf->b_op_end.lnum = oap->end.lnum;
  368. !     curbuf->b_op_end.col = oap->start.col;
  369.       }
  370.       else
  371.   #endif
  372. !     curbuf->b_op_end = oap->start;
  373.       curbuf->b_op_start = oap->start;
  374.   
  375.       return OK;
  376. ***************
  377. *** 2759,2771 ****
  378.       /*
  379.        * Set "'[" and "']" marks.
  380.        */
  381. ! #ifdef FEAT_VISUAL
  382. !     if (!did_visual_put)
  383. ! #endif
  384. !     {
  385. !     curbuf->b_op_start = oap->start;
  386. !     curbuf->b_op_end = oap->end;
  387. !     }
  388.   
  389.   #ifdef FEAT_CLIPBOARD
  390.       /*
  391. --- 2794,2801 ----
  392.       /*
  393.        * Set "'[" and "']" marks.
  394.        */
  395. !     curbuf->b_op_start = oap->start;
  396. !     curbuf->b_op_end = oap->end;
  397.   
  398.   #ifdef FEAT_CLIPBOARD
  399.       /*
  400. ***************
  401. *** 2909,2931 ****
  402.       long    cnt;
  403.   
  404.   #ifdef FEAT_CLIPBOARD
  405. !     /* If no register specified, and "unnamed" in 'clipboard', use + register */
  406. !     if (regname == 0 && clip_unnamed)
  407. !     regname = '*';
  408.       if (regname == '*')
  409. !     {
  410. !     if (!clip_star.available)
  411. !         regname = 0;
  412. !     else
  413. !         clip_get_selection(&clip_star);
  414. !     }
  415.       else if (regname == '+')
  416. !     {
  417. !     if (!clip_plus.available)
  418. !         regname = 0;
  419. !     else
  420. !         clip_get_selection(&clip_plus);
  421. !     }
  422.   #endif
  423.   
  424.       if (flags & PUT_FIXINDENT)
  425. --- 2939,2950 ----
  426.       long    cnt;
  427.   
  428.   #ifdef FEAT_CLIPBOARD
  429. !     /* Adjust register name for "unnamed" in 'clipboard'. */
  430. !     adjust_clip_reg(®name);
  431.       if (regname == '*')
  432. !     clip_get_selection(&clip_star);
  433.       else if (regname == '+')
  434. !     clip_get_selection(&clip_plus);
  435.   #endif
  436.   
  437.       if (flags & PUT_FIXINDENT)
  438. ***************
  439. *** 3021,3046 ****
  440.   #ifdef FEAT_VISUAL
  441.       if (y_type == MLINE)
  442.       {
  443. !     if (flags & PUT_LINE_BACKWARD)
  444.       {
  445. !         /* "P" in Visual mode: Put before the Visual area instead of after
  446. !          * it.  It's OK to change the cursor position here (special
  447. !          * case!). */
  448. !         dir = BACKWARD;
  449. !         curwin->w_cursor = curbuf->b_visual_start;
  450.       }
  451. !     else if (VIsual_active && VIsual_mode == Ctrl_V)
  452.       {
  453. !         /* "p" in Visual block mode with linewise text: put below the
  454. !          * block. */
  455.           curwin->w_cursor = curbuf->b_visual_end;
  456.       }
  457.       curbuf->b_op_start = curwin->w_cursor;    /* default for '[ mark */
  458.       curbuf->b_op_end = curwin->w_cursor;    /* default for '] mark */
  459.       }
  460.   #endif
  461.   
  462. !     if (flags & PUT_LINE)        /* :put command */
  463.       y_type = MLINE;
  464.   
  465.       if (y_size == 0 || y_array == NULL)
  466. --- 3040,3076 ----
  467.   #ifdef FEAT_VISUAL
  468.       if (y_type == MLINE)
  469.       {
  470. !     if (flags & PUT_LINE_SPLIT)
  471.       {
  472. !         /* "p" or "P" in Visual mode: split the lines to put the text in
  473. !          * between. */
  474. !         if (u_save_cursor() == FAIL)
  475. !         goto end;
  476. !         ptr = vim_strsave(ml_get_cursor());
  477. !         if (ptr == NULL)
  478. !         goto end;
  479. !         ml_append(curwin->w_cursor.lnum, ptr, (colnr_T)0, FALSE);
  480. !         vim_free(ptr);
  481. !         ptr = vim_strnsave(ml_get_curline(), curwin->w_cursor.col);
  482. !         if (ptr == NULL)
  483. !         goto end;
  484. !         ml_replace(curwin->w_cursor.lnum, ptr, FALSE);
  485. !         ++nr_lines;
  486. !         dir = FORWARD;
  487.       }
  488. !     if (flags & PUT_LINE_FORWARD)
  489.       {
  490. !         /* Must be "p" for a Visual block, put lines below the block. */
  491.           curwin->w_cursor = curbuf->b_visual_end;
  492. +         dir = FORWARD;
  493.       }
  494.       curbuf->b_op_start = curwin->w_cursor;    /* default for '[ mark */
  495.       curbuf->b_op_end = curwin->w_cursor;    /* default for '] mark */
  496.       }
  497.   #endif
  498.   
  499. !     if (flags & PUT_LINE)    /* :put command or "p" in Visual line mode. */
  500.       y_type = MLINE;
  501.   
  502.       if (y_size == 0 || y_array == NULL)
  503. ***************
  504. *** 3360,3366 ****
  505.       else
  506.       {
  507.           /*
  508. !          * Insert at least one one.  When y_type is MCHAR, break the first
  509.            * line in two.
  510.            */
  511.           for (cnt = 1; cnt <= count; ++cnt)
  512. --- 3390,3396 ----
  513.       else
  514.       {
  515.           /*
  516. !          * Insert at least one line.  When y_type is MCHAR, break the first
  517.            * line in two.
  518.            */
  519.           for (cnt = 1; cnt <= count; ++cnt)
  520. *** ../vim61.236/src/proto/ops.pro    Sun Jul 28 22:02:42 2002
  521. --- src/proto/ops.pro    Sun Oct 27 18:03:58 2002
  522. ***************
  523. *** 9,19 ****
  524. --- 9,22 ----
  525.   int get_expr_register __ARGS((void));
  526.   void set_expr_line __ARGS((char_u *new_line));
  527.   int valid_yank_reg __ARGS((int regname, int writing));
  528. + void *get_register __ARGS((int name, int copy));
  529. + void put_register __ARGS((int name, void *reg));
  530.   int yank_register_mline __ARGS((int regname));
  531.   int do_record __ARGS((int c));
  532.   int do_execreg __ARGS((int regname, int colon, int addcr));
  533.   int insert_reg __ARGS((int regname, int literally));
  534.   int cmdline_paste __ARGS((int regname, int literally));
  535. + void adjust_clip_reg __ARGS((int *rp));
  536.   int op_delete __ARGS((oparg_T *oap));
  537.   int op_replace __ARGS((oparg_T *oap, int c));
  538.   void op_tilde __ARGS((oparg_T *oap));
  539. *** ../vim61.236/src/version.c    Sun Oct 27 19:31:44 2002
  540. --- src/version.c    Sun Oct 27 20:21:01 2002
  541. ***************
  542. *** 608,609 ****
  543. --- 608,611 ----
  544.   {   /* Add new patch number below this line */
  545. + /**/
  546. +     237,
  547.   /**/
  548.  
  549. -- 
  550. ARTHUR:  I did say sorry about the `old woman,' but from the behind you
  551.          looked--
  552. DENNIS:  What I object to is you automatically treat me like an inferior!
  553. ARTHUR:  Well, I AM king...
  554.                                   The Quest for the Holy Grail (Monty Python)
  555.  
  556.  ///  Bram Moolenaar -- Bram@moolenaar.net -- http://www.moolenaar.net  \\\
  557. ///          Creator of Vim - Vi IMproved -- http://www.vim.org          \\\
  558. \\\           Project leader for A-A-P -- http://www.a-a-p.org           ///
  559.  \\\ Lord Of The Rings helps Uganda - http://iccf-holland.org/lotr.html ///
  560.