Created
November 16, 2017 18:21
-
-
Save Rob--W/2cf28e472aeb6b6de6e478a96e278fc8 to your computer and use it in GitHub Desktop.
Patch to allow vim to use any undo file. Usage: Create a file with many blank lines and use :rundo! path/to/undo/file . Then use u or r to undo/redo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 4775e38f78c7990306fd67fa1145433bb4779722 | |
Author: Rob Wu <[email protected]> | |
Date: Thu Nov 16 12:50:10 2017 +0100 | |
Add :rundo! support | |
Based on https://groups.google.com/d/msg/vim_use/pOia0eB8ZWo/FmIQ4lUOPDIJ | |
Written for https://github.com/vim/vim/archive/v8.0.1272.tar.gz | |
diff --git a/src/ex_cmds.h b/src/ex_cmds.h | |
index 41c7c80..7b4cff0 100644 | |
--- a/src/ex_cmds.h | |
+++ b/src/ex_cmds.h | |
@@ -1208,7 +1208,7 @@ EX(CMD_rubyfile, "rubyfile", ex_rubyfile, | |
RANGE|FILE1|NEEDARG|CMDWIN, | |
ADDR_LINES), | |
EX(CMD_rundo, "rundo", ex_rundo, | |
- NEEDARG|FILE1, | |
+ BANG|NEEDARG|FILE1, | |
ADDR_LINES), | |
EX(CMD_rviminfo, "rviminfo", ex_viminfo, | |
BANG|FILE1|TRLBAR|CMDWIN, | |
diff --git a/src/ex_docmd.c b/src/ex_docmd.c | |
index 547d1ac..b6a2f88 100644 | |
--- a/src/ex_docmd.c | |
+++ b/src/ex_docmd.c | |
@@ -9530,7 +9530,7 @@ ex_rundo(exarg_T *eap) | |
char_u hash[UNDO_HASH_SIZE]; | |
u_compute_hash(hash); | |
- u_read_undo(eap->arg, hash, NULL); | |
+ u_read_undo(eap->arg, hash, NULL, eap->forceit); | |
} | |
#endif | |
diff --git a/src/fileio.c b/src/fileio.c | |
index 34dcdb6..5a40faa 100644 | |
--- a/src/fileio.c | |
+++ b/src/fileio.c | |
@@ -2699,7 +2699,7 @@ failed: | |
char_u hash[UNDO_HASH_SIZE]; | |
sha256_finish(&sha_ctx, hash); | |
- u_read_undo(NULL, hash, fname); | |
+ u_read_undo(NULL, hash, fname, FALSE); | |
} | |
#endif | |
diff --git a/src/option.c b/src/option.c | |
index ceafea3..445ba20 100644 | |
--- a/src/option.c | |
+++ b/src/option.c | |
@@ -8134,7 +8134,7 @@ set_bool_option( | |
&& !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL) | |
{ | |
u_compute_hash(hash); | |
- u_read_undo(NULL, hash, curbuf->b_fname); | |
+ u_read_undo(NULL, hash, curbuf->b_fname, FALSE); | |
} | |
} | |
curbuf = save_curbuf; | |
diff --git a/src/proto/undo.pro b/src/proto/undo.pro | |
index 2b3258d..ba5336b 100644 | |
--- a/src/proto/undo.pro | |
+++ b/src/proto/undo.pro | |
@@ -9,7 +9,7 @@ int u_savecommon(linenr_T top, linenr_T bot, linenr_T newbot, int reload); | |
void u_compute_hash(char_u *hash); | |
char_u *u_get_undo_file_name(char_u *buf_ffname, int reading); | |
void u_write_undo(char_u *name, int forceit, buf_T *buf, char_u *hash); | |
-void u_read_undo(char_u *name, char_u *hash, char_u *orig_name); | |
+void u_read_undo(char_u *name, char_u *hash, char_u *orig_name, int force); | |
void u_undo(int count); | |
void u_redo(int count); | |
void undo_time(long step, int sec, int file, int absolute); | |
diff --git a/src/undo.c b/src/undo.c | |
index 2c5725f..2103bdf 100644 | |
--- a/src/undo.c | |
+++ b/src/undo.c | |
@@ -1786,7 +1786,7 @@ theend: | |
* "hash[UNDO_HASH_SIZE]" must be the hash value of the buffer text. | |
*/ | |
void | |
-u_read_undo(char_u *name, char_u *hash, char_u *orig_name) | |
+u_read_undo(char_u *name, char_u *hash, char_u *orig_name, int force) | |
{ | |
char_u *file_name; | |
FILE *fp; | |
@@ -1917,8 +1917,9 @@ u_read_undo(char_u *name, char_u *hash, char_u *orig_name) | |
goto error; | |
} | |
line_count = (linenr_T)undo_read_4c(&bi); | |
- if (memcmp(hash, read_hash, UNDO_HASH_SIZE) != 0 | |
+ if ((memcmp(hash, read_hash, UNDO_HASH_SIZE) != 0 | |
|| line_count != curbuf->b_ml.ml_line_count) | |
+ && !force) | |
{ | |
if (p_verbose > 0 || name != NULL) | |
{ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment