Mercurial > vim
comparison src/undo.c @ 798:95dac6af3b3a v7.0232
updated for version 7.0232
author | vimboss |
---|---|
date | Thu, 23 Mar 2006 22:59:57 +0000 |
parents | f19994020dad |
children | 9f345c48220b |
comparison
equal
deleted
inserted
replaced
797:a1a08851eac8 | 798:95dac6af3b3a |
---|---|
86 static void u_getbot __ARGS((void)); | 86 static void u_getbot __ARGS((void)); |
87 static int undo_allowed __ARGS((void)); | 87 static int undo_allowed __ARGS((void)); |
88 static int u_savecommon __ARGS((linenr_T, linenr_T, linenr_T)); | 88 static int u_savecommon __ARGS((linenr_T, linenr_T, linenr_T)); |
89 static void u_doit __ARGS((int count)); | 89 static void u_doit __ARGS((int count)); |
90 static void u_undoredo __ARGS((int undo)); | 90 static void u_undoredo __ARGS((int undo)); |
91 static void u_undo_end __ARGS((int did_undo)); | 91 static void u_undo_end __ARGS((int did_undo, int absolute)); |
92 static void u_add_time __ARGS((char_u *buf, size_t buflen, time_t tt)); | 92 static void u_add_time __ARGS((char_u *buf, size_t buflen, time_t tt)); |
93 static void u_freeheader __ARGS((buf_T *buf, u_header_T *uhp, u_header_T **uhpp)); | 93 static void u_freeheader __ARGS((buf_T *buf, u_header_T *uhp, u_header_T **uhpp)); |
94 static void u_freebranch __ARGS((buf_T *buf, u_header_T *uhp, u_header_T **uhpp)); | 94 static void u_freebranch __ARGS((buf_T *buf, u_header_T *uhp, u_header_T **uhpp)); |
95 static void u_freeentries __ARGS((buf_T *buf, u_header_T *uhp, u_header_T **uhpp)); | 95 static void u_freeentries __ARGS((buf_T *buf, u_header_T *uhp, u_header_T **uhpp)); |
96 static void u_freeentry __ARGS((u_entry_T *, long)); | 96 static void u_freeentry __ARGS((u_entry_T *, long)); |
636 if (curbuf->b_u_curhead->uh_prev == NULL) | 636 if (curbuf->b_u_curhead->uh_prev == NULL) |
637 curbuf->b_u_newhead = curbuf->b_u_curhead; | 637 curbuf->b_u_newhead = curbuf->b_u_curhead; |
638 curbuf->b_u_curhead = curbuf->b_u_curhead->uh_prev; | 638 curbuf->b_u_curhead = curbuf->b_u_curhead->uh_prev; |
639 } | 639 } |
640 } | 640 } |
641 u_undo_end(undo_undoes); | 641 u_undo_end(undo_undoes, FALSE); |
642 } | 642 } |
643 | 643 |
644 static int lastmark = 0; | 644 static int lastmark = 0; |
645 | 645 |
646 /* | 646 /* |
702 closest = -1; | 702 closest = -1; |
703 } | 703 } |
704 else | 704 else |
705 { | 705 { |
706 if (sec) | 706 if (sec) |
707 closest = time(NULL) - starttime + 1; | 707 closest = (long)(time(NULL) - starttime + 1); |
708 else | 708 else |
709 closest = curbuf->b_u_seq_last + 2; | 709 closest = curbuf->b_u_seq_last + 2; |
710 if (target >= closest) | 710 if (target >= closest) |
711 target = closest - 1; | 711 target = closest - 1; |
712 } | 712 } |
737 uhp = curbuf->b_u_curhead; | 737 uhp = curbuf->b_u_curhead; |
738 | 738 |
739 while (uhp != NULL) | 739 while (uhp != NULL) |
740 { | 740 { |
741 uhp->uh_walk = mark; | 741 uhp->uh_walk = mark; |
742 val = (dosec ? (uhp->uh_time - starttime) : uhp->uh_seq); | 742 val = (long)(dosec ? (uhp->uh_time - starttime) : uhp->uh_seq); |
743 | 743 |
744 if (round == 1) | 744 if (round == 1) |
745 { | 745 { |
746 /* Remember the header that is closest to the target. | 746 /* Remember the header that is closest to the target. |
747 * It must be at least in the right direction (checked with | 747 * It must be at least in the right direction (checked with |
786 /* go up in the tree if we haven't been there and we are at the | 786 /* go up in the tree if we haven't been there and we are at the |
787 * start of alternate branches */ | 787 * start of alternate branches */ |
788 else if (uhp->uh_next != NULL && uhp->uh_alt_prev == NULL | 788 else if (uhp->uh_next != NULL && uhp->uh_alt_prev == NULL |
789 && uhp->uh_next->uh_walk != nomark | 789 && uhp->uh_next->uh_walk != nomark |
790 && uhp->uh_next->uh_walk != mark) | 790 && uhp->uh_next->uh_walk != mark) |
791 { | |
792 /* If still at the start we don't go through this change. */ | |
793 if (uhp == curbuf->b_u_curhead) | |
794 uhp->uh_walk = nomark; | |
791 uhp = uhp->uh_next; | 795 uhp = uhp->uh_next; |
796 } | |
792 | 797 |
793 else | 798 else |
794 { | 799 { |
795 /* need to backtrack; mark this node as useless */ | 800 /* need to backtrack; mark this node as useless */ |
796 uhp->uh_walk = nomark; | 801 uhp->uh_walk = nomark; |
878 break; /* must have reached the target */ | 883 break; /* must have reached the target */ |
879 | 884 |
880 /* Stop when going backwards in time and didn't find the exact | 885 /* Stop when going backwards in time and didn't find the exact |
881 * header we were looking for. */ | 886 * header we were looking for. */ |
882 if (uhp->uh_seq == target && above) | 887 if (uhp->uh_seq == target && above) |
888 { | |
889 curbuf->b_u_seq_cur = target - 1; | |
883 break; | 890 break; |
891 } | |
884 | 892 |
885 u_undoredo(FALSE); | 893 u_undoredo(FALSE); |
886 | 894 |
887 /* Advance "curhead" to below the header we last used. If it | 895 /* Advance "curhead" to below the header we last used. If it |
888 * becomes NULL then we need to set "newhead" to this leaf. */ | 896 * becomes NULL then we need to set "newhead" to this leaf. */ |
901 EMSG2(_(e_intern2), "undo_time()"); | 909 EMSG2(_(e_intern2), "undo_time()"); |
902 break; | 910 break; |
903 } | 911 } |
904 } | 912 } |
905 } | 913 } |
906 u_undo_end(did_undo); | 914 u_undo_end(did_undo, absolute); |
907 } | 915 } |
908 | 916 |
909 /* | 917 /* |
910 * u_undoredo: common code for undo and redo | 918 * u_undoredo: common code for undo and redo |
911 * | 919 * |
1174 * If we deleted or added lines, report the number of less/more lines. | 1182 * If we deleted or added lines, report the number of less/more lines. |
1175 * Otherwise, report the number of changes (this may be incorrect | 1183 * Otherwise, report the number of changes (this may be incorrect |
1176 * in some cases, but it's better than nothing). | 1184 * in some cases, but it's better than nothing). |
1177 */ | 1185 */ |
1178 static void | 1186 static void |
1179 u_undo_end(did_undo) | 1187 u_undo_end(did_undo, absolute) |
1180 int did_undo; /* just did an undo */ | 1188 int did_undo; /* just did an undo */ |
1189 int absolute; /* used ":undo N" */ | |
1181 { | 1190 { |
1182 char *msg; | 1191 char *msg; |
1183 u_header_T *uhp; | 1192 u_header_T *uhp; |
1184 char_u msgbuf[80]; | 1193 char_u msgbuf[80]; |
1185 | 1194 |
1213 msg = N_("changes"); | 1222 msg = N_("changes"); |
1214 } | 1223 } |
1215 | 1224 |
1216 if (curbuf->b_u_curhead != NULL) | 1225 if (curbuf->b_u_curhead != NULL) |
1217 { | 1226 { |
1218 if (did_undo) | 1227 /* For ":undo N" we prefer a "after #N" message. */ |
1228 if (absolute && curbuf->b_u_curhead->uh_next != NULL) | |
1229 { | |
1230 uhp = curbuf->b_u_curhead->uh_next; | |
1231 did_undo = FALSE; | |
1232 } | |
1233 else if (did_undo) | |
1219 uhp = curbuf->b_u_curhead; | 1234 uhp = curbuf->b_u_curhead; |
1220 else | 1235 else |
1221 uhp = curbuf->b_u_curhead->uh_next; | 1236 uhp = curbuf->b_u_curhead->uh_next; |
1222 } | 1237 } |
1223 else | 1238 else |