Skip to content

Commit 5e20df7

Browse files
committed
updated for version 7.4.171
Problem: Redo does not set v:count and v:count1. Solution: Use a separate buffer for redo, so that we can set the counts when performing redo.
1 parent a7d7956 commit 5e20df7

File tree

6 files changed

+122
-77
lines changed

6 files changed

+122
-77
lines changed

src/getchar.c

Lines changed: 100 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@
4040

4141
#define MINIMAL_SIZE 20 /* minimal size for b_str */
4242

43-
static struct buffheader redobuff = {{NULL, {NUL}}, NULL, 0, 0};
44-
static struct buffheader old_redobuff = {{NULL, {NUL}}, NULL, 0, 0};
43+
static buffheader_T redobuff = {{NULL, {NUL}}, NULL, 0, 0};
44+
static buffheader_T old_redobuff = {{NULL, {NUL}}, NULL, 0, 0};
4545
#if defined(FEAT_AUTOCMD) || defined(FEAT_EVAL) || defined(PROTO)
46-
static struct buffheader save_redobuff = {{NULL, {NUL}}, NULL, 0, 0};
47-
static struct buffheader save_old_redobuff = {{NULL, {NUL}}, NULL, 0, 0};
46+
static buffheader_T save_redobuff = {{NULL, {NUL}}, NULL, 0, 0};
47+
static buffheader_T save_old_redobuff = {{NULL, {NUL}}, NULL, 0, 0};
4848
#endif
49-
static struct buffheader recordbuff = {{NULL, {NUL}}, NULL, 0, 0};
49+
static buffheader_T recordbuff = {{NULL, {NUL}}, NULL, 0, 0};
5050

5151
static int typeahead_char = 0; /* typeahead char that's not flushed */
5252

@@ -112,11 +112,12 @@ static char_u noremapbuf_init[TYPELEN_INIT]; /* initial typebuf.tb_noremap */
112112

113113
static int last_recorded_len = 0; /* number of last recorded chars */
114114

115-
static char_u *get_buffcont __ARGS((struct buffheader *, int));
116-
static void add_buff __ARGS((struct buffheader *, char_u *, long n));
117-
static void add_num_buff __ARGS((struct buffheader *, long));
118-
static void add_char_buff __ARGS((struct buffheader *, int));
119-
static int read_stuff __ARGS((int advance));
115+
static char_u *get_buffcont __ARGS((buffheader_T *, int));
116+
static void add_buff __ARGS((buffheader_T *, char_u *, long n));
117+
static void add_num_buff __ARGS((buffheader_T *, long));
118+
static void add_char_buff __ARGS((buffheader_T *, int));
119+
static int read_readbuffers __ARGS((int advance));
120+
static int read_readbuf __ARGS((buffheader_T *buf, int advance));
120121
static void start_stuff __ARGS((void));
121122
static int read_redo __ARGS((int, int));
122123
static void copy_redo __ARGS((int));
@@ -137,9 +138,9 @@ static char_u *eval_map_expr __ARGS((char_u *str, int c));
137138
*/
138139
void
139140
free_buff(buf)
140-
struct buffheader *buf;
141+
buffheader_T *buf;
141142
{
142-
struct buffblock *p, *np;
143+
buffblock_T *p, *np;
143144

144145
for (p = buf->bh_first.b_next; p != NULL; p = np)
145146
{
@@ -155,14 +156,14 @@ free_buff(buf)
155156
*/
156157
static char_u *
157158
get_buffcont(buffer, dozero)
158-
struct buffheader *buffer;
159+
buffheader_T *buffer;
159160
int dozero; /* count == zero is not an error */
160161
{
161162
long_u count = 0;
162163
char_u *p = NULL;
163164
char_u *p2;
164165
char_u *str;
165-
struct buffblock *bp;
166+
buffblock_T *bp;
166167

167168
/* compute the total length of the string */
168169
for (bp = buffer->bh_first.b_next; bp != NULL; bp = bp->b_next)
@@ -230,11 +231,11 @@ get_inserted()
230231
*/
231232
static void
232233
add_buff(buf, s, slen)
233-
struct buffheader *buf;
234+
buffheader_T *buf;
234235
char_u *s;
235236
long slen; /* length of "s" or -1 */
236237
{
237-
struct buffblock *p;
238+
buffblock_T *p;
238239
long_u len;
239240

240241
if (slen < 0)
@@ -270,7 +271,7 @@ add_buff(buf, s, slen)
270271
len = MINIMAL_SIZE;
271272
else
272273
len = slen;
273-
p = (struct buffblock *)lalloc((long_u)(sizeof(struct buffblock) + len),
274+
p = (buffblock_T *)lalloc((long_u)(sizeof(buffblock_T) + len),
274275
TRUE);
275276
if (p == NULL)
276277
return; /* no space, just forget it */
@@ -289,7 +290,7 @@ add_buff(buf, s, slen)
289290
*/
290291
static void
291292
add_num_buff(buf, n)
292-
struct buffheader *buf;
293+
buffheader_T *buf;
293294
long n;
294295
{
295296
char_u number[32];
@@ -304,7 +305,7 @@ add_num_buff(buf, n)
304305
*/
305306
static void
306307
add_char_buff(buf, c)
307-
struct buffheader *buf;
308+
buffheader_T *buf;
308309
int c;
309310
{
310311
#ifdef FEAT_MBYTE
@@ -354,46 +355,71 @@ add_char_buff(buf, c)
354355
#endif
355356
}
356357

358+
/* First read ahead buffer. Used for translated commands. */
359+
static buffheader_T readbuf1 = {{NULL, {NUL}}, NULL, 0, 0};
360+
361+
/* Second read ahead buffer. Used for redo. */
362+
static buffheader_T readbuf2 = {{NULL, {NUL}}, NULL, 0, 0};
363+
357364
/*
358-
* Get one byte from the stuff buffer.
365+
* Get one byte from the read buffers. Use readbuf1 one first, use readbuf2
366+
* if that one is empty.
359367
* If advance == TRUE go to the next char.
360368
* No translation is done K_SPECIAL and CSI are escaped.
361369
*/
362370
static int
363-
read_stuff(advance)
371+
read_readbuffers(advance)
364372
int advance;
365373
{
366-
char_u c;
367-
struct buffblock *curr;
374+
int c;
375+
376+
c = read_readbuf(&readbuf1, advance);
377+
if (c == NUL)
378+
c = read_readbuf(&readbuf2, advance);
379+
return c;
380+
}
381+
382+
static int
383+
read_readbuf(buf, advance)
384+
buffheader_T *buf;
385+
int advance;
386+
{
387+
char_u c;
388+
buffblock_T *curr;
368389

369-
if (stuffbuff.bh_first.b_next == NULL) /* buffer is empty */
390+
if (buf->bh_first.b_next == NULL) /* buffer is empty */
370391
return NUL;
371392

372-
curr = stuffbuff.bh_first.b_next;
373-
c = curr->b_str[stuffbuff.bh_index];
393+
curr = buf->bh_first.b_next;
394+
c = curr->b_str[buf->bh_index];
374395

375396
if (advance)
376397
{
377-
if (curr->b_str[++stuffbuff.bh_index] == NUL)
398+
if (curr->b_str[++buf->bh_index] == NUL)
378399
{
379-
stuffbuff.bh_first.b_next = curr->b_next;
400+
buf->bh_first.b_next = curr->b_next;
380401
vim_free(curr);
381-
stuffbuff.bh_index = 0;
402+
buf->bh_index = 0;
382403
}
383404
}
384405
return c;
385406
}
386407

387408
/*
388-
* Prepare the stuff buffer for reading (if it contains something).
409+
* Prepare the read buffers for reading (if they contains something).
389410
*/
390411
static void
391412
start_stuff()
392413
{
393-
if (stuffbuff.bh_first.b_next != NULL)
414+
if (readbuf1.bh_first.b_next != NULL)
394415
{
395-
stuffbuff.bh_curr = &(stuffbuff.bh_first);
396-
stuffbuff.bh_space = 0;
416+
readbuf1.bh_curr = &(readbuf1.bh_first);
417+
readbuf1.bh_space = 0;
418+
}
419+
if (readbuf2.bh_first.b_next != NULL)
420+
{
421+
readbuf2.bh_curr = &(readbuf2.bh_first);
422+
readbuf2.bh_space = 0;
397423
}
398424
}
399425

@@ -403,7 +429,18 @@ start_stuff()
403429
int
404430
stuff_empty()
405431
{
406-
return (stuffbuff.bh_first.b_next == NULL);
432+
return (readbuf1.bh_first.b_next == NULL
433+
&& readbuf2.bh_first.b_next == NULL);
434+
}
435+
436+
/*
437+
* Return TRUE if readbuf1 is empty. There may still be redo characters in
438+
* redbuf2.
439+
*/
440+
int
441+
readbuf1_empty()
442+
{
443+
return (readbuf1.bh_first.b_next == NULL);
407444
}
408445

409446
/*
@@ -428,7 +465,7 @@ flush_buffers(flush_typeahead)
428465
init_typebuf();
429466

430467
start_stuff();
431-
while (read_stuff(TRUE) != NUL)
468+
while (read_readbuffers(TRUE) != NUL)
432469
;
433470

434471
if (flush_typeahead) /* remove all typeahead */
@@ -483,7 +520,7 @@ CancelRedo()
483520
redobuff = old_redobuff;
484521
old_redobuff.bh_first.b_next = NULL;
485522
start_stuff();
486-
while (read_stuff(TRUE) != NUL)
523+
while (read_readbuffers(TRUE) != NUL)
487524
;
488525
}
489526
}
@@ -638,15 +675,15 @@ AppendNumberToRedobuff(n)
638675
stuffReadbuff(s)
639676
char_u *s;
640677
{
641-
add_buff(&stuffbuff, s, -1L);
678+
add_buff(&readbuf1, s, -1L);
642679
}
643680

644681
void
645682
stuffReadbuffLen(s, len)
646683
char_u *s;
647684
long len;
648685
{
649-
add_buff(&stuffbuff, s, len);
686+
add_buff(&readbuf1, s, len);
650687
}
651688

652689
#if defined(FEAT_EVAL) || defined(PROTO)
@@ -692,7 +729,7 @@ stuffReadbuffSpec(s)
692729
stuffcharReadbuff(c)
693730
int c;
694731
{
695-
add_char_buff(&stuffbuff, c);
732+
add_char_buff(&readbuf1, c);
696733
}
697734

698735
/*
@@ -702,7 +739,7 @@ stuffcharReadbuff(c)
702739
stuffnumReadbuff(n)
703740
long n;
704741
{
705-
add_num_buff(&stuffbuff, n);
742+
add_num_buff(&readbuf1, n);
706743
}
707744

708745
/*
@@ -718,13 +755,13 @@ read_redo(init, old_redo)
718755
int init;
719756
int old_redo;
720757
{
721-
static struct buffblock *bp;
722-
static char_u *p;
723-
int c;
758+
static buffblock_T *bp;
759+
static char_u *p;
760+
int c;
724761
#ifdef FEAT_MBYTE
725-
int n;
726-
char_u buf[MB_MAXBYTES + 1];
727-
int i;
762+
int n;
763+
char_u buf[MB_MAXBYTES + 1];
764+
int i;
728765
#endif
729766

730767
if (init)
@@ -795,11 +832,11 @@ copy_redo(old_redo)
795832
int c;
796833

797834
while ((c = read_redo(FALSE, old_redo)) != NUL)
798-
stuffcharReadbuff(c);
835+
add_char_buff(&readbuf2, c);
799836
}
800837

801838
/*
802-
* Stuff the redo buffer into the stuffbuff.
839+
* Stuff the redo buffer into readbuf2.
803840
* Insert the redo count into the command.
804841
* If "old_redo" is TRUE, the last but one command is repeated
805842
* instead of the last command (inserting text). This is used for
@@ -823,13 +860,13 @@ start_redo(count, old_redo)
823860
/* copy the buffer name, if present */
824861
if (c == '"')
825862
{
826-
add_buff(&stuffbuff, (char_u *)"\"", 1L);
863+
add_buff(&readbuf2, (char_u *)"\"", 1L);
827864
c = read_redo(FALSE, old_redo);
828865

829866
/* if a numbered buffer is used, increment the number */
830867
if (c >= '1' && c < '9')
831868
++c;
832-
add_char_buff(&stuffbuff, c);
869+
add_char_buff(&readbuf2, c);
833870
c = read_redo(FALSE, old_redo);
834871
}
835872

@@ -850,18 +887,18 @@ start_redo(count, old_redo)
850887
{
851888
while (VIM_ISDIGIT(c)) /* skip "old" count */
852889
c = read_redo(FALSE, old_redo);
853-
add_num_buff(&stuffbuff, count);
890+
add_num_buff(&readbuf2, count);
854891
}
855892

856893
/* copy from the redo buffer into the stuff buffer */
857-
add_char_buff(&stuffbuff, c);
894+
add_char_buff(&readbuf2, c);
858895
copy_redo(old_redo);
859896
return OK;
860897
}
861898

862899
/*
863900
* Repeat the last insert (R, o, O, a, A, i or I command) by stuffing
864-
* the redo buffer into the stuffbuff.
901+
* the redo buffer into readbuf2.
865902
* return FAIL for failure, OK otherwise
866903
*/
867904
int
@@ -879,7 +916,7 @@ start_redo_ins()
879916
if (vim_strchr((char_u *)"AaIiRrOo", c) != NULL)
880917
{
881918
if (c == 'O' || c == 'o')
882-
stuffReadbuff(NL_STR);
919+
add_buff(&readbuf2, NL_STR, -1L);
883920
break;
884921
}
885922
}
@@ -1360,8 +1397,10 @@ save_typeahead(tp)
13601397
tp->old_mod_mask = old_mod_mask;
13611398
old_char = -1;
13621399

1363-
tp->save_stuffbuff = stuffbuff;
1364-
stuffbuff.bh_first.b_next = NULL;
1400+
tp->save_readbuf1 = readbuf1;
1401+
readbuf1.bh_first.b_next = NULL;
1402+
tp->save_readbuf2 = readbuf2;
1403+
readbuf2.bh_first.b_next = NULL;
13651404
# ifdef USE_INPUT_BUF
13661405
tp->save_inputbuf = get_input_buf();
13671406
# endif
@@ -1384,8 +1423,10 @@ restore_typeahead(tp)
13841423
old_char = tp->old_char;
13851424
old_mod_mask = tp->old_mod_mask;
13861425

1387-
free_buff(&stuffbuff);
1388-
stuffbuff = tp->save_stuffbuff;
1426+
free_buff(&readbuf1);
1427+
readbuf1 = tp->save_readbuf1;
1428+
free_buff(&readbuf2);
1429+
readbuf2 = tp->save_readbuf2;
13891430
# ifdef USE_INPUT_BUF
13901431
set_input_buf(tp->save_inputbuf);
13911432
# endif
@@ -1992,7 +2033,7 @@ vgetorpeek(advance)
19922033
typeahead_char = 0;
19932034
}
19942035
else
1995-
c = read_stuff(advance);
2036+
c = read_readbuffers(advance);
19962037
if (c != NUL && !got_int)
19972038
{
19982039
if (advance)

src/globals.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -979,11 +979,6 @@ EXTERN int RedrawingDisabled INIT(= 0);
979979
EXTERN int readonlymode INIT(= FALSE); /* Set to TRUE for "view" */
980980
EXTERN int recoverymode INIT(= FALSE); /* Set to TRUE for "-r" option */
981981

982-
EXTERN struct buffheader stuffbuff /* stuff buffer */
983-
#ifdef DO_INIT
984-
= {{NULL, {NUL}}, NULL, 0, 0}
985-
#endif
986-
;
987982
EXTERN typebuf_T typebuf /* typeahead buffer */
988983
#ifdef DO_INIT
989984
= {NULL, NULL, 0, 0, 0, 0, 0, 0, 0}

0 commit comments

Comments
 (0)